From bd7105ff8683a680d1270eca8cd74f9002144dbd Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 10 Jul 2017 15:40:42 -0700 Subject: Initial work on handling resources in structs during cross-compilation - The basic idea is that during the "lowering" pass, some types (notably: aggregate types that contain resource variables) will get turned into "tuple" types, which are pseduo-types that aren't meant to survive lowering. - An attempt to declare a variable with a tuple type expands into a tuple of declarations - An attempt to reference such a tuple-ified variable leads to a tuple of expressions - An attempt to extract a member from such a tuple expression will pick the appropriate sub-element - Dereference a tuple by dereferencing the primary expression - Expand a tuple in the argument list to a call into N arguments (by recursively flattening the tuple) - Don't create tuple types when not generating GLSL - Make sure to preserve the specialized type of a call expression through lowering, since emission of unchecked calls relies on that info. - TODO: maybe the infix/prefix/postifx/select information should come in as a side-band? Should we have modifiers on expressions? - Make sure to offset the layout for a nested field based on teh base offset of its parent variable, when generating declarations for nested fields --- tests/rewriter/resources-in-structs.glsl | 62 +++++++++++++++++++++++++++++++ tests/rewriter/resources-in-structs.slang | 13 +++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/rewriter/resources-in-structs.glsl create mode 100644 tests/rewriter/resources-in-structs.slang (limited to 'tests/rewriter') diff --git a/tests/rewriter/resources-in-structs.glsl b/tests/rewriter/resources-in-structs.glsl new file mode 100644 index 000000000..26e21f630 --- /dev/null +++ b/tests/rewriter/resources-in-structs.glsl @@ -0,0 +1,62 @@ +#version 450 core +//TEST:COMPARE_GLSL:-profile glsl_fragment + +#if defined(__SLANG__) + +__import resources_in_structs; + +uniform U +{ + Material m; +}; + +in vec2 uv; + +out vec4 color; + +void main() +{ + color = evaluateMaterial(m, uv); +} + +#else + +struct Material +{ + vec4 color; +}; + +vec4 evaluateMaterial( + Material m, + texture2D m_t, + sampler m_s, + vec2 uv) +{ + return m.color + texture(sampler2D(m_t, m_s), uv); +} + +layout(binding = 0) +uniform U +{ + Material m; +}; + +layout(binding = 1) +uniform texture2D SLANG_parameterBlock_U_m_t; + +layout(binding = 2) +uniform sampler SLANG_parameterBlock_U_m_s; + +in vec2 uv; + +out vec4 color; + +void main() +{ + color = evaluateMaterial( + m, + SLANG_parameterBlock_U_m_t, + SLANG_parameterBlock_U_m_s, uv); +} + +#endif diff --git a/tests/rewriter/resources-in-structs.slang b/tests/rewriter/resources-in-structs.slang new file mode 100644 index 000000000..79eca11ac --- /dev/null +++ b/tests/rewriter/resources-in-structs.slang @@ -0,0 +1,13 @@ +//TEST_IGNORE_FILE: + +struct Material +{ + float4 color; + Texture2D t; + SamplerState s; +}; + +float4 evaluateMaterial(Material m, float2 uv) +{ + return m.color + m.t.Sample(m.s, uv); +} -- cgit v1.2.3