mirror of
https://github.com/RPCS3/glslang.git
synced 2024-11-30 06:30:40 +00:00
a2b01a0da8
This PR implements recursive type flattening. For example, an array of structs of other structs can be flattened to individual member variables at the shader interface. This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient for geometry shader arrayed inputs. That will be handled separately with structure splitting, which is not implemented by this PR. In the meantime, that case is detected and triggers an error. The recursive flattening extends the following three aspects of single-level flattening: - Flattening of structures to individual members with names such as "foo[0].samp[1]"; - Turning constant references to the nested composite type into a reference to a particular flattened member. - Shadow copies between arrays of flattened members and the nested composite type. Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR. Internally, shadow copies are, such as if the type is passed to a function. Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct types are flattened. (The latter will change with structure splitting). One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be flattened. Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently issues an error until type splitting is online). The process of arriving at the individual member from chained postfix expressions is more complex than it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
29 lines
649 B
GLSL
29 lines
649 B
GLSL
SamplerState g_samp;
|
|
Texture1D g_tex;
|
|
|
|
struct tex_t {
|
|
SamplerState samp;
|
|
Texture1D tex;
|
|
int nonopaque_thing;
|
|
};
|
|
|
|
struct tex_with_arrays_t {
|
|
SamplerState samp[2];
|
|
Texture1D tex[2];
|
|
int nonopaque_thing;
|
|
};
|
|
|
|
uniform tex_t g_texdata;
|
|
uniform tex_t g_texdata_array[3];
|
|
uniform tex_with_arrays_t g_texdata_array2[3];
|
|
|
|
struct PS_OUTPUT { float4 color : SV_Target0; };
|
|
|
|
void main(out PS_OUTPUT ps_output)
|
|
{
|
|
ps_output.color =
|
|
g_texdata.tex.Sample(g_texdata.samp, 0.5) +
|
|
g_texdata_array[1].tex.Sample(g_texdata_array[1].samp, 0.4) +
|
|
g_texdata_array2[1].tex[0].Sample(g_texdata_array2[1].samp[0], 0.3);
|
|
}
|