nitc :: GLSLValidationPhase :: _tool_is_in_path
Is the tool glsllangValidator in path?nitc :: GLSLValidationPhase :: tool_is_in_path
Is the tool glsllangValidator in path?nitc :: GLSLValidationPhase :: tool_is_in_path=
Is the tool glsllangValidator in path?nitc $ GLSLValidationPhase :: SELF
Type of this instance, automatically specialized in every classnitc $ GLSLValidationPhase :: process_annotated_node
Specific actions to execute on annotated nodesnitc :: Phase :: _in_hierarchy
The dependence relation of the phase with the other phasesnitc :: GLSLValidationPhase :: _tool_is_in_path
Is the tool glsllangValidator in path?nitc :: Phase :: _toolcontext
The toolcontext instance attached to the phasecore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
nitc :: Phase :: defaultinit
nitc :: Phase :: in_hierarchy
The dependence relation of the phase with the other phasesnitc :: Phase :: in_hierarchy=
The dependence relation of the phase with the other phasescore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: Phase :: process_annotated_node
Specific actions to execute on annotated nodesnitc :: Phase :: process_mainmodule
Specific action to execute on the whole program.nitc :: Phase :: process_nclassdef
Specific actions to execute on the tree of a class definitionnitc :: Phase :: process_nmodule
Specific actions to execute on the whole tree of a modulenitc :: Phase :: process_nmodule_after
Specific actions to execute on the whole tree of a modulenitc :: Phase :: process_npropdef
Specific actions to execute on the tree of a propertynitc :: GLSLValidationPhase :: tool_is_in_path
Is the tool glsllangValidator in path?nitc :: GLSLValidationPhase :: tool_is_in_path=
Is the tool glsllangValidator in path?nitc :: Phase :: toolcontext
The toolcontext instance attached to the phasenitc :: Phase :: toolcontext=
The toolcontext instance attached to the phase
private class GLSLValidationPhase
super Phase
# Annotation names
fun annot_name_vertex: String do return "glsl_vertex_shader"
fun annot_name_fragment: String do return "glsl_fragment_shader"
# TODO support more shader types as needed
# Is the tool _glsllangValidator_ in path?
var tool_is_in_path: nullable Bool = null
redef fun process_annotated_node(nstring, nat)
do
var annot_name = nat.n_atid.n_id.text
var is_vertex = annot_name == annot_name_vertex
var is_fragment = annot_name == annot_name_fragment
# Skip if we are not interested
if not is_vertex and not is_fragment then return
# Only applicable on strings
if not nstring isa AStringFormExpr then
toolcontext.error(nstring.location,
"Syntax Error: only a string literal can be annotated as `{annot_name}`.")
return
end
# Do not double check if tool is in path
var in_path = tool_is_in_path
if in_path == null then
# Is _glslangValidator_ installed?
var proc_which = new ProcessReader("which", "glslangValidator")
proc_which.wait
proc_which.close
var status = proc_which.status
in_path = status == 0
tool_is_in_path = in_path
end
if not in_path then
toolcontext.advice(nat.location, "glslvalidator",
"Warning: program `glslangValidator` not in PATH, cannot validate this shader.")
return
end
# Get the shader source
var shader = nstring.value
# Copy the shader to a file
# TODO make it more portable
var tmp = "/tmp/"
var ext
if is_vertex then
ext = "vert"
else ext = "frag"
var path = tmp / "nit_shader." + ext
shader.write_to_file path
# Execute the validator
var proc_validator = new ProcessReader("glslangValidator", path)
proc_validator.wait
var lines = proc_validator.read_all.split('\n')
proc_validator.close
# Parse errors
var regex = "[A-Z]+: ([0-9]+):([0-9]+): (.*)".to_re
for line in lines do
var match = line.search(regex)
# Does it match an error?
# If not, then it should be the summary
if match != null then
var shader_line_no = match.subs[1].to_s.to_i
var msg = match.subs[2].to_s
var line_start = nstring.location.line_start + shader_line_no
var char_start = 0
var char_end = 0
var loc = new Location(nat.location.file,
line_start, line_start,
char_start, char_end)
toolcontext.warning(loc, "glslvalidator",
"Shader error on {msg}")
end
end
end
end
src/frontend/glsl_validation.nit:30,1--120,3