From: Mikko Rasa Date: Sat, 3 Apr 2021 10:56:16 +0000 (+0300) Subject: Allocate locations to interface variables X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7b03ca83ca6c48b9f8c3f77c13760e7f87e9632d;p=libs%2Fgl.git Allocate locations to interface variables --- diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index e0a67606..1948722a 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -106,6 +106,8 @@ void Compiler::compile(Mode mode) else if(result!=REDO_STAGE) ++i; } + + LocationAllocator().apply(*module); for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) finalize(*i, mode); diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index 0adb2960..0805a29e 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -3,6 +3,7 @@ #include #include "finalize.h" #include "glsl_error.h" +#include "reflect.h" using namespace std; @@ -10,6 +11,113 @@ namespace Msp { namespace GL { namespace SL { +void LocationAllocator::apply(Module &module) +{ + for(list::iterator i=module.stages.begin(); i!=module.stages.end(); ++i) + apply(*i); + allocate_locations("uniform"); +} + +void LocationAllocator::apply(Stage &stage) +{ + swap(used_locations["in"], used_locations["out"]); + used_locations["out"].clear(); + + stage.content.visit(*this); + + allocate_locations("in"); + allocate_locations("out"); +} + +void LocationAllocator::allocate_locations(const string &iface) +{ + vector::iterator write = unplaced_variables.begin(); + unsigned next = 0; + for(vector::const_iterator i=unplaced_variables.begin(); i!=unplaced_variables.end(); ++i) + { + if((*i)->interface!=iface) + { + if(write!=i) + *write = *i; + ++write; + continue; + } + + if((*i)->interface=="uniform") + { + map::const_iterator j = uniform_locations.find((*i)->name); + if(j!=uniform_locations.end()) + { + add_location((*i)->layout, j->second); + continue; + } + } + + set &used = used_locations[(*i)->interface]; + + unsigned size = LocationCounter().apply(**i); + while(1) + { + int blocking = -1; + for(unsigned j=0; jlayout, next); + if((*i)->interface=="uniform") + uniform_locations[(*i)->name] = next; + + for(unsigned j=0; j &layout, unsigned location) +{ + if(!layout) + layout = new Layout; + + Layout::Qualifier qual; + qual.name = "location"; + qual.has_value = true; + qual.value = location; + layout->qualifiers.push_back(qual); +} + +void LocationAllocator::visit(VariableDeclaration &var) +{ + if(!var.interface.empty() && var.name.compare(0, 3, "gl_")) + { + int location = (var.layout ? get_layout_value(*var.layout, "location") : -1); + + if(location<0 && var.linked_declaration && var.linked_declaration->layout) + { + location = get_layout_value(*var.linked_declaration->layout, "location"); + if(location>=0) + add_location(var.layout, location); + } + + if(location>=0) + { + unsigned size = LocationCounter().apply(var); + for(unsigned i=0; i > used_locations; + std::map uniform_locations; + std::vector unplaced_variables; + +public: + void apply(Module &); +private: + void apply(Stage &); + + void allocate_locations(const std::string &); + void add_location(RefPtr &, unsigned); + + virtual void visit(VariableDeclaration &); + virtual void visit(InterfaceBlock &) { } + virtual void visit(FunctionDeclaration &) { } +}; + /** Generates default precision declarations or removes precision declarations according to the requirements of the target API. */ class PrecisionConverter: private TraversingVisitor diff --git a/tests/glsl/alias_types.glsl b/tests/glsl/alias_types.glsl index 8e6e9a91..0fda73e3 100644 --- a/tests/glsl/alias_types.glsl +++ b/tests/glsl/alias_types.glsl @@ -11,7 +11,7 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; void main() { diff --git a/tests/glsl/arithmetic_assignment.glsl b/tests/glsl/arithmetic_assignment.glsl index d6c48ad8..01e03b07 100644 --- a/tests/glsl/arithmetic_assignment.glsl +++ b/tests/glsl/arithmetic_assignment.glsl @@ -26,12 +26,12 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; layout(location=1) in vec3 normal; layout(location=2) in vec2 texcoord; -out float light; -out vec2 _vs_out_texcoord; +layout(location=0) out float light; +layout(location=1) out vec2 _vs_out_texcoord; void main() { light = normal.z; @@ -41,12 +41,12 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; -uniform vec3 tint; -uniform vec3 ambient; -out vec4 frag_color; -in vec2 _vs_out_texcoord; -in float light; +layout(location=4) uniform sampler2D tex; +layout(location=5) uniform vec3 tint; +layout(location=6) uniform vec3 ambient; +layout(location=0) out vec4 frag_color; +layout(location=1) in vec2 _vs_out_texcoord; +layout(location=0) in float light; void main() { vec3 color = texture(tex, _vs_out_texcoord).rgb; diff --git a/tests/glsl/complex_constant_condition_removal.glsl b/tests/glsl/complex_constant_condition_removal.glsl index 5a2c588f..4f7819b9 100644 --- a/tests/glsl/complex_constant_condition_removal.glsl +++ b/tests/glsl/complex_constant_condition_removal.glsl @@ -24,7 +24,7 @@ void main() /* Expected output: vertex layout(location=0) in vec4 position; layout(location=1) in vec4 color; -out vec4 _vs_out_color; +layout(location=0) out vec4 _vs_out_color; void main() { gl_Position = position; @@ -34,7 +34,7 @@ void main() /* Expected output: fragment layout(location=0) out vec4 frag_color; -in vec4 _vs_out_color; +layout(location=0) in vec4 _vs_out_color; void main() { frag_color = _vs_out_color; diff --git a/tests/glsl/conditional_multiple_emitvertex.glsl b/tests/glsl/conditional_multiple_emitvertex.glsl index 375a4366..7a80a72b 100644 --- a/tests/glsl/conditional_multiple_emitvertex.glsl +++ b/tests/glsl/conditional_multiple_emitvertex.glsl @@ -34,7 +34,7 @@ void main() /* Expected output: vertex layout(location=0) in vec4 position; -out vec2 texcoord; +layout(location=0) out vec2 texcoord; void main() { texcoord = position.xy*0.5+0.5; @@ -43,11 +43,11 @@ void main() */ /* Expected output: geometry -uniform bool flag; +layout(location=0) uniform bool flag; layout(triangles) in; layout(triangle_strip, max_vertices=3) out; -in vec2 texcoord[]; -out vec2 _gs_out_texcoord; +layout(location=0) in vec2 texcoord[]; +layout(location=0) out vec2 _gs_out_texcoord; void main() { gl_Position = gl_in[0].gl_Position; @@ -66,9 +66,9 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=1) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _gs_out_texcoord; +layout(location=0) in vec2 _gs_out_texcoord; void main() { frag_color = texture(tex, _gs_out_texcoord); diff --git a/tests/glsl/constant_last_argument.glsl b/tests/glsl/constant_last_argument.glsl index b73f1826..4285b5f0 100644 --- a/tests/glsl/constant_last_argument.glsl +++ b/tests/glsl/constant_last_argument.glsl @@ -18,10 +18,10 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; layout(location=1) in vec2 texcoord; -out vec2 _vs_out_texcoord; +layout(location=0) out vec2 _vs_out_texcoord; void main() { gl_Position = mvp*position; @@ -30,9 +30,9 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=4) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _vs_out_texcoord; +layout(location=0) in vec2 _vs_out_texcoord; void main() { frag_color = textureLod(tex, _vs_out_texcoord, 0.0)*0.8; diff --git a/tests/glsl/constructors.glsl b/tests/glsl/constructors.glsl index fe7ca48a..d10dacf5 100644 --- a/tests/glsl/constructors.glsl +++ b/tests/glsl/constructors.glsl @@ -27,16 +27,16 @@ void main() } /* Expected output: vertex -uniform mat4 model; -uniform mat4 view_projection; -uniform vec3 light_dir; +layout(location=0) uniform mat4 model; +layout(location=4) uniform mat4 view_projection; +layout(location=8) uniform vec3 light_dir; layout(location=0) in vec3 position; layout(location=1) in vec3 normal; layout(location=2) in vec3 tangent; layout(location=3) in vec3 binormal; layout(location=4) in vec2 texcoord; -out vec3 tbn_light_dir; -out vec2 _vs_out_texcoord; +layout(location=0) out vec3 tbn_light_dir; +layout(location=1) out vec2 _vs_out_texcoord; void main() { mat3 normal_matrix = mat3(model[0].xyz, model[1].xyz, model[2].xyz); @@ -47,10 +47,10 @@ void main() */ /* Expected output: fragment -uniform sampler2D normalmap; +layout(location=9) uniform sampler2D normalmap; layout(location=0) out vec4 frag_color; -in vec2 _vs_out_texcoord; -in vec3 tbn_light_dir; +layout(location=1) in vec2 _vs_out_texcoord; +layout(location=0) in vec3 tbn_light_dir; void main() { frag_color = vec4(vec3(dot(vec3(texture(normalmap, _vs_out_texcoord).xyz)*2.0-1.0, normalize(tbn_light_dir))), float(1)); diff --git a/tests/glsl/dead_loop_removal.glsl b/tests/glsl/dead_loop_removal.glsl index 7cfba086..ee5c0360 100644 --- a/tests/glsl/dead_loop_removal.glsl +++ b/tests/glsl/dead_loop_removal.glsl @@ -29,8 +29,8 @@ void main() } /* Expected output: vertex -uniform mat4 model_matrix; -uniform mat4 vp_matrix; +layout(location=0) uniform mat4 model_matrix; +layout(location=4) uniform mat4 vp_matrix; layout(location=0) in vec4 position; void main() { @@ -39,7 +39,7 @@ void main() */ /* Expected output: fragment -uniform vec3 ambient; +layout(location=8) uniform vec3 ambient; layout(location=0) out vec4 frag_color; void main() { diff --git a/tests/glsl/function_arguments_inline.glsl b/tests/glsl/function_arguments_inline.glsl index f9946c9c..84ec1c07 100644 --- a/tests/glsl/function_arguments_inline.glsl +++ b/tests/glsl/function_arguments_inline.glsl @@ -12,7 +12,7 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; void main() { diff --git a/tests/glsl/function_inline_parameter_name_conflict.glsl b/tests/glsl/function_inline_parameter_name_conflict.glsl index fb124f87..831858f0 100644 --- a/tests/glsl/function_inline_parameter_name_conflict.glsl +++ b/tests/glsl/function_inline_parameter_name_conflict.glsl @@ -15,7 +15,7 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; layout(location=1) in vec4 offset; void main() diff --git a/tests/glsl/function_overloading.glsl b/tests/glsl/function_overloading.glsl index 6924a628..02576cad 100644 --- a/tests/glsl/function_overloading.glsl +++ b/tests/glsl/function_overloading.glsl @@ -30,10 +30,10 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; layout(location=1) in vec2 texcoord; -out vec2 _vs_out_texcoord; +layout(location=0) out vec2 _vs_out_texcoord; void main() { _vs_out_texcoord = texcoord; @@ -42,9 +42,9 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=4) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _vs_out_texcoord; +layout(location=0) in vec2 _vs_out_texcoord; void main() { vec4 color = texture(tex, _vs_out_texcoord); diff --git a/tests/glsl/geometry_interface_block.glsl b/tests/glsl/geometry_interface_block.glsl index 9f3fae5b..fb9a2aa0 100644 --- a/tests/glsl/geometry_interface_block.glsl +++ b/tests/glsl/geometry_interface_block.glsl @@ -72,7 +72,7 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=0) uniform sampler2D tex; layout(location=0) out vec4 frag_color; in GeometryOut { diff --git a/tests/glsl/geometry_passthrough.glsl b/tests/glsl/geometry_passthrough.glsl index 9acfe83e..95e5ecbd 100644 --- a/tests/glsl/geometry_passthrough.glsl +++ b/tests/glsl/geometry_passthrough.glsl @@ -29,7 +29,7 @@ void main() /* Expected output: vertex layout(location=0) in vec4 position; -out vec2 texcoord; +layout(location=0) out vec2 texcoord; void main() { texcoord = position.xy*0.5+0.5; @@ -40,8 +40,8 @@ void main() /* Expected output: geometry layout(triangles) in; layout(triangle_strip, max_vertices=3) out; -in vec2 texcoord[]; -out vec2 _gs_out_texcoord; +layout(location=0) in vec2 texcoord[]; +layout(location=0) out vec2 _gs_out_texcoord; void main() { for(int i = 0; i<3; ++i) @@ -54,9 +54,9 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=0) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _gs_out_texcoord; +layout(location=0) in vec2 _gs_out_texcoord; void main() { frag_color = texture(tex, _gs_out_texcoord); diff --git a/tests/glsl/ignore_array_in_geometry_passthrough.glsl b/tests/glsl/ignore_array_in_geometry_passthrough.glsl index 62e4d793..598a177c 100644 --- a/tests/glsl/ignore_array_in_geometry_passthrough.glsl +++ b/tests/glsl/ignore_array_in_geometry_passthrough.glsl @@ -32,11 +32,11 @@ void main() } /* Expected output: vertex -uniform mat4 vp_matrix; +layout(location=0) uniform mat4 vp_matrix; layout(location=0) in vec4 position; layout(location=1) in vec2 texcoord; layout(location=2) in vec4 instance_transform[3]; -out vec2 _vs_out_texcoord; +layout(location=0) out vec2 _vs_out_texcoord; void main() { _vs_out_texcoord = texcoord; @@ -47,8 +47,8 @@ void main() /* Expected output: geometry layout(triangles) in; layout(triangle_strip, max_vertices=3) out; -in vec2 _vs_out_texcoord[]; -out vec2 _gs_out_texcoord; +layout(location=0) in vec2 _vs_out_texcoord[]; +layout(location=0) out vec2 _gs_out_texcoord; void main() { for(int i = 0; i<3; ++i) @@ -61,9 +61,9 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=4) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _gs_out_texcoord; +layout(location=0) in vec2 _gs_out_texcoord; void main() { frag_color = texture(tex, _gs_out_texcoord); diff --git a/tests/glsl/keep_spec_constants_in_module.glsl b/tests/glsl/keep_spec_constants_in_module.glsl index a7feab17..674e55ec 100644 --- a/tests/glsl/keep_spec_constants_in_module.glsl +++ b/tests/glsl/keep_spec_constants_in_module.glsl @@ -27,12 +27,12 @@ void main() // Compile mode: module /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; layout(location=1) in vec4 color; layout(location=2) in vec2 texcoord; -out vec4 _vs_out_color; -out vec2 _vs_out_texcoord; +layout(location=0) out vec4 _vs_out_color; +layout(location=1) out vec2 _vs_out_texcoord; void main() { _vs_out_color = color; @@ -44,10 +44,10 @@ void main() /* Expected output: fragment layout(constant_id=0) const bool use_texture = false; layout(constant_id=1) const bool use_vertex_color = false; -uniform sampler2D tex; +layout(location=4) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _vs_out_texcoord; -in vec4 _vs_out_color; +layout(location=1) in vec2 _vs_out_texcoord; +layout(location=0) in vec4 _vs_out_color; void main() { frag_color = vec4(1.0); diff --git a/tests/glsl/multiple_emitvertex.glsl b/tests/glsl/multiple_emitvertex.glsl index c0ef8699..8d769e8b 100644 --- a/tests/glsl/multiple_emitvertex.glsl +++ b/tests/glsl/multiple_emitvertex.glsl @@ -30,7 +30,7 @@ void main() /* Expected output: vertex layout(location=0) in vec4 position; -out vec2 texcoord; +layout(location=0) out vec2 texcoord; void main() { texcoord = position.xy*0.5+0.5; @@ -41,8 +41,8 @@ void main() /* Expected output: geometry layout(triangles) in; layout(triangle_strip, max_vertices=3) out; -in vec2 texcoord[]; -out vec2 _gs_out_texcoord; +layout(location=0) in vec2 texcoord[]; +layout(location=0) out vec2 _gs_out_texcoord; void main() { gl_Position = gl_in[0].gl_Position; @@ -58,9 +58,9 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=0) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _gs_out_texcoord; +layout(location=0) in vec2 _gs_out_texcoord; void main() { frag_color = texture(tex, _gs_out_texcoord); diff --git a/tests/glsl/nested_function_inline.glsl b/tests/glsl/nested_function_inline.glsl index 7999ee73..a09d3422 100644 --- a/tests/glsl/nested_function_inline.glsl +++ b/tests/glsl/nested_function_inline.glsl @@ -16,7 +16,7 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; void main() { diff --git a/tests/glsl/parentheses.glsl b/tests/glsl/parentheses.glsl index 1dec4296..24635017 100644 --- a/tests/glsl/parentheses.glsl +++ b/tests/glsl/parentheses.glsl @@ -33,13 +33,13 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; -uniform vec3 offset; +layout(location=0) uniform mat4 mvp; +layout(location=4) uniform vec3 offset; layout(location=0) in vec4 position; layout(location=1) in vec3 normal; layout(location=2) in vec2 texcoord; -out vec3 _vs_out_normal; -out vec2 _vs_out_texcoord; +layout(location=0) out vec3 _vs_out_normal; +layout(location=1) out vec2 _vs_out_texcoord; void main() { gl_Position = mvp*(position+vec4(offset, 1.0)); @@ -56,12 +56,12 @@ struct LightParams float intensity; vec3 dir; }; -uniform LightParams light; -uniform vec3 material_color; -uniform sampler2D occlusion_map; +layout(location=5) uniform LightParams light; +layout(location=9) uniform vec3 material_color; +layout(location=10) uniform sampler2D occlusion_map; layout(location=0) out vec4 frag_color; -in vec2 _vs_out_texcoord; -in vec3 _vs_out_normal; +layout(location=1) in vec2 _vs_out_texcoord; +layout(location=0) in vec3 _vs_out_normal; void main() { frag_color = vec4(material_color*(light.ambient+light.color*light.intensity*max(dot(light.dir, normalize(_vs_out_normal)), 0.0))*float(texture(occlusion_map, _vs_out_texcoord).x), 1.0); diff --git a/tests/glsl/passthrough.glsl b/tests/glsl/passthrough.glsl index 4017e490..5b048246 100644 --- a/tests/glsl/passthrough.glsl +++ b/tests/glsl/passthrough.glsl @@ -17,7 +17,7 @@ void main() /* Expected output: vertex layout(location=0) in vec4 position; layout(location=1) in vec4 color; -out vec4 _vs_out_color; +layout(location=0) out vec4 _vs_out_color; void main() { gl_Position = position; @@ -27,7 +27,7 @@ void main() /* Expected output: fragment layout(location=0) out vec4 frag_color; -in vec4 _vs_out_color; +layout(location=0) in vec4 _vs_out_color; void main() { frag_color = _vs_out_color; diff --git a/tests/glsl/passthrough_declaration_order.glsl b/tests/glsl/passthrough_declaration_order.glsl index 52712d85..c5d1856a 100644 --- a/tests/glsl/passthrough_declaration_order.glsl +++ b/tests/glsl/passthrough_declaration_order.glsl @@ -23,7 +23,7 @@ void main() /* Expected output: vertex layout(location=0) in vec4 position; layout(location=1) in vec4 color; -out vec4 _vs_out_color; +layout(location=0) out vec4 _vs_out_color; void main() { gl_Position = position; @@ -33,7 +33,7 @@ void main() /* Expected output: fragment layout(location=0) out vec4 frag_color; -in vec4 _vs_out_color; +layout(location=0) in vec4 _vs_out_color; void main() { frag_color = _vs_out_color; diff --git a/tests/glsl/referenced_but_unassigned_output.glsl b/tests/glsl/referenced_but_unassigned_output.glsl index aabff089..5b0e00d1 100644 --- a/tests/glsl/referenced_but_unassigned_output.glsl +++ b/tests/glsl/referenced_but_unassigned_output.glsl @@ -22,13 +22,13 @@ void main() } /* Expected output: vertex -uniform mat4 projection; -out vec4 eye_vertex; +layout(location=0) uniform mat4 projection; +layout(location=0) out vec4 eye_vertex; out VertexOut { vec4 color; }; -out float alpha; +layout(location=1) out float alpha; void main() { gl_Position = projection*eye_vertex; @@ -42,7 +42,7 @@ in VertexOut { vec4 color; }; -in float alpha; +layout(location=1) in float alpha; void main() { frag_color = vec4(color.rgb, alpha); diff --git a/tests/glsl/specialization_constants.glsl b/tests/glsl/specialization_constants.glsl index b5666f2d..2b9eaad8 100644 --- a/tests/glsl/specialization_constants.glsl +++ b/tests/glsl/specialization_constants.glsl @@ -27,10 +27,10 @@ void main() // Specialize: use_texture true /* Expected output: vertex -uniform mat4 mvp; +layout(location=0) uniform mat4 mvp; layout(location=0) in vec4 position; layout(location=2) in vec2 texcoord; -out vec2 _vs_out_texcoord; +layout(location=0) out vec2 _vs_out_texcoord; void main() { _vs_out_texcoord = texcoord; @@ -39,9 +39,9 @@ void main() */ /* Expected output: fragment -uniform sampler2D tex; +layout(location=4) uniform sampler2D tex; layout(location=0) out vec4 frag_color; -in vec2 _vs_out_texcoord; +layout(location=0) in vec2 _vs_out_texcoord; void main() { frag_color = vec4(1.0); diff --git a/tests/glsl/ternary_operator.glsl b/tests/glsl/ternary_operator.glsl index 1a1a0989..d3844af8 100644 --- a/tests/glsl/ternary_operator.glsl +++ b/tests/glsl/ternary_operator.glsl @@ -32,7 +32,7 @@ uniform Transform } transform; layout(location=0) in vec4 position; layout(location=1) in vec2 texcoord; -out vec2 _vs_out_texcoord; +layout(location=0) out vec2 _vs_out_texcoord; void main() { _vs_out_texcoord = texcoord; @@ -46,9 +46,9 @@ uniform Colors vec4 color1; vec4 color2; }; -uniform sampler2D mask; +layout(location=0) uniform sampler2D mask; layout(location=0) out vec4 frag_color; -in vec2 _vs_out_texcoord; +layout(location=0) in vec2 _vs_out_texcoord; void main() { frag_color = texture(mask, _vs_out_texcoord).r>0.5?color1:color2; diff --git a/tests/glsl/uniform_location_allocation.glsl b/tests/glsl/uniform_location_allocation.glsl new file mode 100644 index 00000000..f82a9b8c --- /dev/null +++ b/tests/glsl/uniform_location_allocation.glsl @@ -0,0 +1,43 @@ +#pragma MSP stage(vertex) +uniform mat4 mvp; +uniform sampler2D heightmap; +layout(location=0) in vec2 position; +layout(location=1) in vec2 texcoord; +void main() +{ + gl_Position = mvp*vec4(position, texture(heightmap, texcoord).r, 1.0); + passthrough; +} + +#pragma MSP stage(fragment) +layout(location=0) uniform sampler2D heightmap; +uniform vec4 color; +out vec4 frag_color; +void main() +{ + frag_color = color*vec4(texture(heightmap, texcoord).rrr, 1.0); +} + +/* Expected output: vertex +layout(location=1) uniform mat4 mvp; +layout(location=0) uniform sampler2D heightmap; +layout(location=0) in vec2 position; +layout(location=1) in vec2 texcoord; +layout(location=0) out vec2 _vs_out_texcoord; +void main() +{ + gl_Position = mvp*vec4(position, texture(heightmap, texcoord).r, 1.0); + _vs_out_texcoord = texcoord; +} +*/ + +/* Expected output: fragment +layout(location=0) uniform sampler2D heightmap; +layout(location=5) uniform vec4 color; +layout(location=0) out vec4 frag_color; +layout(location=0) in vec2 _vs_out_texcoord; +void main() +{ + frag_color = color*vec4(texture(heightmap, _vs_out_texcoord).rrr, 1.0); +} +*/ diff --git a/tests/glsl/variable_assignment_subscript.glsl b/tests/glsl/variable_assignment_subscript.glsl index 801b82b7..335e631b 100644 --- a/tests/glsl/variable_assignment_subscript.glsl +++ b/tests/glsl/variable_assignment_subscript.glsl @@ -27,8 +27,8 @@ void main() } /* Expected output: vertex -uniform mat4 mvp; -uniform int mask_index; +layout(location=0) uniform mat4 mvp; +layout(location=4) uniform int mask_index; layout(location=0) in vec4 position; layout(location=1) in vec4 color; out VertexOut