diff options
author | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2017-07-04 13:30:29 +0200 |
---|---|---|
committer | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2017-07-13 13:27:41 +0200 |
commit | f3254981462e5e2964458475af7f7639e06b7bfd (patch) | |
tree | e16706066a77c073eef694b3d88df3bac3c13fac | |
parent | 9d150731a0f810381f6a2cc882b4d2f127afd09c (diff) |
glsl/linker: find built-in variable assignments by location instead of name
This is faster and more compatible with SPIR-V.
-rw-r--r-- | src/compiler/glsl/linker.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index a051c9d7e3..535a122b3f 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -92,10 +92,12 @@ namespace { struct find_variable { - const char *name; + enum ir_variable_mode mode; + unsigned location; bool found; - find_variable(const char *name) : name(name), found(false) {} + find_variable(enum ir_variable_mode mode, unsigned location) : + mode(mode), location(location), found(false) {} }; /** @@ -115,7 +117,7 @@ public: { ir_variable *const var = ir->lhs->variable_referenced(); - return check_variable_name(var->name); + return check_variable(var); } virtual ir_visitor_status visit_enter(ir_call *ir) @@ -128,7 +130,7 @@ public: if (sig_param->data.mode == ir_var_function_out || sig_param->data.mode == ir_var_function_inout) { ir_variable *var = param_rval->variable_referenced(); - if (var && check_variable_name(var->name) == visit_stop) + if (var && check_variable(var) == visit_stop) return visit_stop; } } @@ -136,7 +138,7 @@ public: if (ir->return_deref != NULL) { ir_variable *const var = ir->return_deref->variable_referenced(); - if (check_variable_name(var->name) == visit_stop) + if (check_variable(var) == visit_stop) return visit_stop; } @@ -144,10 +146,12 @@ public: } private: - ir_visitor_status check_variable_name(const char *name) + ir_visitor_status check_variable(ir_variable *var) { for (unsigned i = 0; i < num_variables; ++i) { - if (strcmp(variables[i]->name, name) == 0) { + if (variables[i]->mode == var->data.mode && + var->data.explicit_location && + variables[i]->location == var->data.location) { if (!variables[i]->found) { variables[i]->found = true; @@ -608,9 +612,9 @@ analyze_clip_cull_usage(struct gl_shader_program *prog, * gl_ClipVertex nor gl_ClipDistance. However with * GL_EXT_clip_cull_distance, this functionality is exposed in ES 3.0. */ - find_variable gl_ClipDistance("gl_ClipDistance"); - find_variable gl_CullDistance("gl_CullDistance"); - find_variable gl_ClipVertex("gl_ClipVertex"); + find_variable gl_ClipDistance(ir_var_shader_out, VARYING_SLOT_CLIP_DIST0); + find_variable gl_CullDistance(ir_var_shader_out, VARYING_SLOT_CULL_DIST0); + find_variable gl_ClipVertex(ir_var_shader_out, VARYING_SLOT_CLIP_VERTEX); find_variable * const variables[] = { &gl_ClipDistance, &gl_CullDistance, @@ -718,7 +722,7 @@ validate_vertex_shader_executable(struct gl_shader_program *prog, * gl_Position is not an error. */ if (prog->data->Version < (prog->IsES ? 300 : 140)) { - find_variable gl_Position("gl_Position"); + find_variable gl_Position(ir_var_shader_out, VARYING_SLOT_POS); find_assignments(shader->ir, &gl_Position); if (!gl_Position.found) { if (prog->IsES) { @@ -764,8 +768,8 @@ validate_fragment_shader_executable(struct gl_shader_program *prog, if (shader == NULL) return; - find_variable gl_FragColor("gl_FragColor"); - find_variable gl_FragData("gl_FragData"); + find_variable gl_FragColor(ir_var_shader_out, FRAG_RESULT_COLOR); + find_variable gl_FragData(ir_var_shader_out, FRAG_RESULT_DATA0); find_variable * const variables[] = { &gl_FragColor, &gl_FragData, NULL }; find_assignments(shader->ir, variables); |