From d1feb41b3ff4dd462f50891e8901bad39466b75c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 12 Mar 2021 00:24:40 +0200 Subject: [PATCH] Fix a test case and add a couple more --- tests/glsl/chained_member_access.glsl | 41 ++++++++++++++ tests/glsl/expression_inline_iteration.glsl | 4 +- tests/glsl/function_overloading.glsl | 60 +++++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 tests/glsl/chained_member_access.glsl create mode 100644 tests/glsl/function_overloading.glsl diff --git a/tests/glsl/chained_member_access.glsl b/tests/glsl/chained_member_access.glsl new file mode 100644 index 00000000..c34cf7d5 --- /dev/null +++ b/tests/glsl/chained_member_access.glsl @@ -0,0 +1,41 @@ +struct TransformComponents +{ + vec3 position; + vec3 scale; +}; +struct Transform +{ + TransformComponents components; +}; +uniform ModelData +{ + Transform transform; +} model; + +#pragma MSP stage(vertex) +layout(location=0) in vec4 position; +void main() +{ + gl_Position = vec4(model.transform.components.position+position.xyz*model.transform.components.scale, 1.0); +} + +/* Expected output: vertex +struct TransformComponents +{ + vec3 position; + vec3 scale; +}; +struct Transform +{ + TransformComponents components; +}; +uniform ModelData +{ + Transform transform; +} model; +layout(location=0) in vec4 position; +void main() +{ + gl_Position = vec4(model.transform.components.position+position.xyz*model.transform.components.scale, 1.0); +} +*/ diff --git a/tests/glsl/expression_inline_iteration.glsl b/tests/glsl/expression_inline_iteration.glsl index 3ad81bc8..4a125099 100644 --- a/tests/glsl/expression_inline_iteration.glsl +++ b/tests/glsl/expression_inline_iteration.glsl @@ -9,7 +9,7 @@ void main() { float scale = 2.0; p += direction*scale; - if(p.z<0) + if(p.z<0.0) break; step = i; } @@ -26,7 +26,7 @@ void main() for(int i=0; i<10; ++i) { p += direction*2.0; - if(p.z<0) + if(p.z<0.0) break; step = i; } diff --git a/tests/glsl/function_overloading.glsl b/tests/glsl/function_overloading.glsl new file mode 100644 index 00000000..636db511 --- /dev/null +++ b/tests/glsl/function_overloading.glsl @@ -0,0 +1,60 @@ +uniform mat4 mvp; +uniform sampler2D tex; +uniform vec3 ambient; + +vec3 srgb_to_linear(vec3 color) +{ + bvec3 near_zero = lessThan(color, vec3(0.04045)); + vec3 gamma = pow((color.rgb+0.055)/1.055, vec3(2.4)); + return mix(color.rgb/12.92, gamma, near_zero); +} +vec4 srgb_to_linear(vec4 color) +{ + return vec4(srgb_to_linear(color.rgb), color.a); +} + +#pragma MSP stage(vertex) +layout(location=0) in vec4 position; +layout(location=1) in vec2 texcoord; +void main() +{ + passthrough; + gl_Position = mvp*position; +} + +#pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; +void main() +{ + frag_color = srgb_to_linear(texture(tex, texcoord)); +} + +/* Expected output: vertex +uniform mat4 mvp; +layout(location=0) in vec4 position; +layout(location=1) in vec2 texcoord; +out vec2 _vs_out_texcoord; +void main() +{ + _vs_out_texcoord = texcoord; + gl_Position = mvp*position; +} +*/ + +/* Expected output: fragment +uniform sampler2D tex; +vec3 srgb_to_linear(vec3 color) +{ + return mix(color.rgb/12.92, pow((color.rgb+0.055)/1.055, vec3(2.4)), lessThan(color, vec3(0.04045))); +} +vec4 srgb_to_linear(vec4 color) +{ + return vec4(srgb_to_linear(color.rgb), color.a); +} +layout(location=0) out vec4 frag_color; +in vec2 _vs_out_texcoord; +void main() +{ + frag_color = srgb_to_linear(texture(tex, _vs_out_texcoord)); +} +*/ -- 2.45.2