Unverified Commit d83344fc by John Kessenich Committed by GitHub

Merge pull request #1684 from baldurk/reflection-interface-improve

Opt-in improvements to reflection interface
parents f6e7c4d2 4513df91
...@@ -152,6 +152,7 @@ void ProcessConfigFile() ...@@ -152,6 +152,7 @@ void ProcessConfigFile()
} }
} }
int ReflectOptions = EShReflectionDefault;
int Options = 0; int Options = 0;
const char* ExecutableName = nullptr; const char* ExecutableName = nullptr;
const char* binaryFileName = nullptr; const char* binaryFileName = nullptr;
...@@ -523,6 +524,16 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem ...@@ -523,6 +524,16 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
Options |= EOptionNoStorageFormat; Options |= EOptionNoStorageFormat;
} else if (lowerword == "relaxed-errors") { } else if (lowerword == "relaxed-errors") {
Options |= EOptionRelaxedErrors; Options |= EOptionRelaxedErrors;
} else if (lowerword == "reflect-strict-array-suffix") {
ReflectOptions |= EShReflectionStrictArraySuffix;
} else if (lowerword == "reflect-basic-array-suffix") {
ReflectOptions |= EShReflectionBasicArraySuffix;
} else if (lowerword == "reflect-intermediate-io") {
ReflectOptions |= EShReflectionIntermediateIO;
} else if (lowerword == "reflect-separate-buffers") {
ReflectOptions |= EShReflectionSeparateBuffers;
} else if (lowerword == "reflect-all-block-variables") {
ReflectOptions |= EShReflectionAllBlockVariables;
} else if (lowerword == "resource-set-bindings" || // synonyms } else if (lowerword == "resource-set-bindings" || // synonyms
lowerword == "resource-set-binding" || lowerword == "resource-set-binding" ||
lowerword == "rsb") { lowerword == "rsb") {
...@@ -1051,7 +1062,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits) ...@@ -1051,7 +1062,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
// Reflect // Reflect
if (Options & EOptionDumpReflection) { if (Options & EOptionDumpReflection) {
program.buildReflection(); program.buildReflection(ReflectOptions);
program.dumpReflection(); program.dumpReflection();
} }
...@@ -1518,6 +1529,15 @@ void usage() ...@@ -1518,6 +1529,15 @@ void usage()
" --invert-y | --iy invert position.Y output in vertex shader\n" " --invert-y | --iy invert position.Y output in vertex shader\n"
" --keep-uncalled | --ku don't eliminate uncalled functions\n" " --keep-uncalled | --ku don't eliminate uncalled functions\n"
" --no-storage-format | --nsf use Unknown image format\n" " --no-storage-format | --nsf use Unknown image format\n"
" --reflect-strict-array-suffix use strict array suffix rules when\n"
" reflecting\n"
" --reflect-basic-array-suffix arrays of basic types will have trailing [0]\n"
" --reflect-intermediate-io reflection includes inputs/outputs of linked\n"
" shaders rather than just vertex/fragment\n"
" --reflect-separate-buffers reflect buffer variables and blocks\n"
" separately to uniforms\n"
" --reflect-all-block-variables reflect all variables in blocks, whether\n"
" inactive or active\n"
" --resource-set-binding [stage] name set binding\n" " --resource-set-binding [stage] name set binding\n"
" set descriptor set and binding for\n" " set descriptor set and binding for\n"
" individual resources\n" " individual resources\n"
......
...@@ -3,8 +3,8 @@ Uniform reflection: ...@@ -3,8 +3,8 @@ Uniform reflection:
t1: offset -1, type 8b5d, size 1, index -1, binding 11, stages 16 t1: offset -1, type 8b5d, size 1, index -1, binding 11, stages 16
t2: offset -1, type 8b5e, size 1, index -1, binding 12, stages 16 t2: offset -1, type 8b5e, size 1, index -1, binding 12, stages 16
t3: offset -1, type 8b5f, size 1, index -1, binding 13, stages 16 t3: offset -1, type 8b5f, size 1, index -1, binding 13, stages 16
t4.@data: offset 0, type 8b52, size 1, index 0, binding -1, stages 16 t4.@data: offset 0, type 8b52, size 1, index 0, binding -1, stages 16, arrayStride 16, topLevelArrayStride 16
t5.@data: offset 0, type 1405, size 0, index 1, binding -1, stages 16 t5.@data: offset 0, type 1405, size 0, index 1, binding -1, stages 16, arrayStride 4, topLevelArrayStride 4
t6: offset -1, type 8dc2, size 1, index -1, binding 16, stages 16 t6: offset -1, type 8dc2, size 1, index -1, binding 16, stages 16
s1: offset -1, type 0, size 1, index -1, binding 31, stages 16 s1: offset -1, type 0, size 1, index -1, binding 31, stages 16
s2: offset -1, type 0, size 1, index -1, binding 32, stages 16 s2: offset -1, type 0, size 1, index -1, binding 32, stages 16
...@@ -12,18 +12,25 @@ u1: offset -1, type 904c, size 1, index -1, binding 41, stages 16 ...@@ -12,18 +12,25 @@ u1: offset -1, type 904c, size 1, index -1, binding 41, stages 16
u2: offset -1, type 904d, size 1, index -1, binding 42, stages 16 u2: offset -1, type 904d, size 1, index -1, binding 42, stages 16
u3: offset -1, type 904e, size 1, index -1, binding 43, stages 16 u3: offset -1, type 904e, size 1, index -1, binding 43, stages 16
u4: offset -1, type 9051, size 1, index -1, binding 44, stages 16 u4: offset -1, type 9051, size 1, index -1, binding 44, stages 16
u5.@data: offset 0, type 1405, size 0, index 2, binding -1, stages 16 u5.@data: offset 0, type 1405, size 0, index 2, binding -1, stages 16, arrayStride 4, topLevelArrayStride 4
u6.@data: offset 0, type 1406, size 1, index 3, binding -1, stages 16 u6.@data: offset 0, type 1406, size 1, index 3, binding -1, stages 16, arrayStride 4, topLevelArrayStride 4
cb1: offset 0, type 1404, size 1, index 4, binding -1, stages 16 cb1: offset 0, type 1404, size 1, index 4, binding -1, stages 16
tb1: offset 0, type 1404, size 1, index 5, binding -1, stages 16 tb1: offset 0, type 1404, size 1, index 5, binding -1, stages 16
Uniform block reflection: Uniform block reflection:
t4: offset -1, type ffffffff, size 0, index -1, binding 14, stages 0 t4: offset -1, type ffffffff, size 0, index -1, binding 14, stages 16, numMembers 1
t5: offset -1, type ffffffff, size 0, index -1, binding 15, stages 0 t5: offset -1, type ffffffff, size 0, index -1, binding 15, stages 16, numMembers 1
u5: offset -1, type ffffffff, size 0, index -1, binding 45, stages 0 u5: offset -1, type ffffffff, size 0, index -1, binding 45, stages 16, numMembers 1
u6: offset -1, type ffffffff, size 0, index -1, binding 46, stages 0 u6: offset -1, type ffffffff, size 0, index -1, binding 46, stages 16, numMembers 1
cb: offset -1, type ffffffff, size 4, index -1, binding 51, stages 0 cb: offset -1, type ffffffff, size 4, index -1, binding 51, stages 16, numMembers 1
tb: offset -1, type ffffffff, size 4, index -1, binding 17, stages 0 tb: offset -1, type ffffffff, size 4, index -1, binding 17, stages 16, numMembers 1
Vertex attribute reflection: Buffer variable reflection:
Buffer block reflection:
Pipeline input reflection:
Pipeline output reflection:
@entryPointOutput: offset 0, type 8b52, size 0, index 0, binding -1, stages 16
...@@ -2,8 +2,8 @@ hlsl.reflection.binding.frag ...@@ -2,8 +2,8 @@ hlsl.reflection.binding.frag
Uniform reflection: Uniform reflection:
t1: offset -1, type 8b5d, size 1, index -1, binding 15, stages 16 t1: offset -1, type 8b5d, size 1, index -1, binding 15, stages 16
s1: offset -1, type 0, size 1, index -1, binding 5, stages 16 s1: offset -1, type 0, size 1, index -1, binding 5, stages 16
t1a: offset -1, type 8b5d, size 1, index -1, binding 16, stages 16 t1a: offset -1, type 8b5d, size 1, index -1, binding 16, stages 16, arrayStride 4, topLevelArrayStride 4
s1a: offset -1, type 0, size 1, index -1, binding 6, stages 16 s1a: offset -1, type 0, size 1, index -1, binding 6, stages 16, arrayStride 4, topLevelArrayStride 4
c1_a: offset 0, type 8b52, size 1, index 0, binding -1, stages 16 c1_a: offset 0, type 8b52, size 1, index 0, binding -1, stages 16
c1_b: offset 16, type 1404, size 1, index 0, binding -1, stages 16 c1_b: offset 16, type 1404, size 1, index 0, binding -1, stages 16
c1_c: offset 20, type 1406, size 1, index 0, binding -1, stages 16 c1_c: offset 20, type 1406, size 1, index 0, binding -1, stages 16
...@@ -12,8 +12,15 @@ c2_b: offset 16, type 1404, size 1, index 1, binding -1, stages 16 ...@@ -12,8 +12,15 @@ c2_b: offset 16, type 1404, size 1, index 1, binding -1, stages 16
c2_c: offset 20, type 1406, size 1, index 1, binding -1, stages 16 c2_c: offset 20, type 1406, size 1, index 1, binding -1, stages 16
Uniform block reflection: Uniform block reflection:
cbuff1: offset -1, type ffffffff, size 24, index -1, binding 2, stages 0 cbuff1: offset -1, type ffffffff, size 24, index -1, binding 2, stages 16, numMembers 3
cbuff2: offset -1, type ffffffff, size 24, index -1, binding 3, stages 0 cbuff2: offset -1, type ffffffff, size 24, index -1, binding 3, stages 16, numMembers 3
Vertex attribute reflection: Buffer variable reflection:
Buffer block reflection:
Pipeline input reflection:
Pipeline output reflection:
psout.Color: offset 0, type 8b52, size 0, index 0, binding -1, stages 16
...@@ -203,8 +203,8 @@ Uniform reflection: ...@@ -203,8 +203,8 @@ Uniform reflection:
t1: offset -1, type 8b5d, size 1, index -1, binding 21, stages 16 t1: offset -1, type 8b5d, size 1, index -1, binding 21, stages 16
t2: offset -1, type 8b5e, size 1, index -1, binding 22, stages 16 t2: offset -1, type 8b5e, size 1, index -1, binding 22, stages 16
t3: offset -1, type 8b5f, size 1, index -1, binding 26, stages 16 t3: offset -1, type 8b5f, size 1, index -1, binding 26, stages 16
t4.@data: offset 0, type 8b52, size 1, index 0, binding -1, stages 16 t4.@data: offset 0, type 8b52, size 1, index 0, binding -1, stages 16, arrayStride 16, topLevelArrayStride 16
t5.@data: offset 0, type 1405, size 0, index 1, binding -1, stages 16 t5.@data: offset 0, type 1405, size 0, index 1, binding -1, stages 16, arrayStride 4, topLevelArrayStride 4
t6: offset -1, type 8dc2, size 1, index -1, binding 23, stages 16 t6: offset -1, type 8dc2, size 1, index -1, binding 23, stages 16
s1: offset -1, type 0, size 1, index -1, binding 11, stages 16 s1: offset -1, type 0, size 1, index -1, binding 11, stages 16
s2: offset -1, type 0, size 1, index -1, binding 17, stages 16 s2: offset -1, type 0, size 1, index -1, binding 17, stages 16
...@@ -212,19 +212,26 @@ u1: offset -1, type 904c, size 1, index -1, binding 31, stages 16 ...@@ -212,19 +212,26 @@ u1: offset -1, type 904c, size 1, index -1, binding 31, stages 16
u2: offset -1, type 904d, size 1, index -1, binding 42, stages 16 u2: offset -1, type 904d, size 1, index -1, binding 42, stages 16
u3: offset -1, type 904e, size 1, index -1, binding 43, stages 16 u3: offset -1, type 904e, size 1, index -1, binding 43, stages 16
u4: offset -1, type 9051, size 1, index -1, binding 34, stages 16 u4: offset -1, type 9051, size 1, index -1, binding 34, stages 16
u5.@data: offset 0, type 1405, size 0, index 2, binding -1, stages 16 u5.@data: offset 0, type 1405, size 0, index 2, binding -1, stages 16, arrayStride 4, topLevelArrayStride 4
u6.@data: offset 0, type 1406, size 1, index 3, binding -1, stages 16 u6.@data: offset 0, type 1406, size 1, index 3, binding -1, stages 16, arrayStride 4, topLevelArrayStride 4
cb1: offset 0, type 1404, size 1, index 4, binding -1, stages 16 cb1: offset 0, type 1404, size 1, index 4, binding -1, stages 16
tb1: offset 0, type 1404, size 1, index 5, binding -1, stages 16 tb1: offset 0, type 1404, size 1, index 5, binding -1, stages 16
ts6: offset -1, type 8b5f, size 1, index -1, binding 71, stages 16 ts6: offset -1, type 8b5f, size 1, index -1, binding 71, stages 16
Uniform block reflection: Uniform block reflection:
t4: offset -1, type ffffffff, size 0, index -1, binding 21, stages 0 t4: offset -1, type ffffffff, size 0, index -1, binding 21, stages 16, numMembers 1
t5: offset -1, type ffffffff, size 0, index -1, binding 22, stages 0 t5: offset -1, type ffffffff, size 0, index -1, binding 22, stages 16, numMembers 1
u5: offset -1, type ffffffff, size 0, index -1, binding 44, stages 0 u5: offset -1, type ffffffff, size 0, index -1, binding 44, stages 16, numMembers 1
u6: offset -1, type ffffffff, size 0, index -1, binding 34, stages 0 u6: offset -1, type ffffffff, size 0, index -1, binding 34, stages 16, numMembers 1
cb: offset -1, type ffffffff, size 4, index -1, binding 51, stages 0 cb: offset -1, type ffffffff, size 4, index -1, binding 51, stages 16, numMembers 1
tb: offset -1, type ffffffff, size 4, index -1, binding 27, stages 0 tb: offset -1, type ffffffff, size 4, index -1, binding 27, stages 16, numMembers 1
Vertex attribute reflection: Buffer variable reflection:
Buffer block reflection:
Pipeline input reflection:
Pipeline output reflection:
@entryPointOutput: offset 0, type 8b52, size 0, index 0, binding -1, stages 16
reflection.frag
Uniform reflection:
Uniform block reflection:
Buffer variable reflection:
Buffer block reflection:
Pipeline input reflection:
Pipeline output reflection:
reflection.linked.vert
reflection.linked.frag
Uniform reflection:
ubo_block.unused_uniform: offset 0, type 1406, size 1, index 0, binding -1, stages 0
ubo_block.shared_uniform: offset 4, type 1406, size 1, index 0, binding -1, stages 17
ubo_block.vsonly_uniform: offset 8, type 1406, size 1, index 0, binding -1, stages 1
ubo_block.fsonly_uniform: offset 12, type 1406, size 1, index 0, binding -1, stages 16
Uniform block reflection:
ubo_block: offset -1, type ffffffff, size 16, index -1, binding 0, stages 17, numMembers 4
Buffer variable reflection:
Buffer block reflection:
Pipeline input reflection:
vertin: offset 0, type 1406, size 0, index 0, binding -1, stages 1
Pipeline output reflection:
fragout: offset 0, type 1406, size 0, index 0, binding -1, stages 16
reflection.linked.vert
reflection.linked.frag
Uniform reflection:
ubo_block.shared_uniform: offset 4, type 1406, size 1, index 0, binding -1, stages 17
ubo_block.vsonly_uniform: offset 8, type 1406, size 1, index 0, binding -1, stages 17
ubo_block.fsonly_uniform: offset 12, type 1406, size 1, index 0, binding -1, stages 16
Uniform block reflection:
ubo_block: offset -1, type ffffffff, size 16, index -1, binding 0, stages 17, numMembers 4
Buffer variable reflection:
Buffer block reflection:
Pipeline input reflection:
vertin: offset 0, type 1406, size 0, index 0, binding -1, stages 1
Pipeline output reflection:
fragout: offset 0, type 1406, size 0, index 0, binding -1, stages 16
reflection.frag
Uniform reflection:
Uniform block reflection:
Buffer variable reflection:
Buffer block reflection:
Pipeline input reflection:
inval: offset 0, type 1406, size 0, index 0, binding -1, stages 16
Pipeline output reflection:
reflection.options.vert
Uniform reflection:
UBO.verts[0].position[0]: offset 0, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 24
UBO.verts[0].normal[0]: offset 12, type 1406, size 3, index 0, binding -1, stages 0, arrayStride 4, topLevelArrayStride 24
UBO.verts[1].position[0]: offset 24, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 24
UBO.verts[1].normal[0]: offset 36, type 1406, size 3, index 0, binding -1, stages 0, arrayStride 4, topLevelArrayStride 24
UBO.flt[0]: offset 48, type 1406, size 8, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 4
UBO.unused: offset 80, type 8dc8, size 1, index 0, binding -1, stages 0
Uniform block reflection:
UBO: offset -1, type ffffffff, size 96, index -1, binding -1, stages 1, numMembers 6
Buffer variable reflection:
t[0].v[0].position[0]: offset 0, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 72
t[0].v[0].normal[0]: offset 12, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 72
t[0].v[1].position[0]: offset 24, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 72
t[0].v[1].normal[0]: offset 36, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 72
t[0].v[2].position[0]: offset 48, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 72
t[0].v[2].normal[0]: offset 60, type 1406, size 3, index 0, binding -1, stages 1, arrayStride 4, topLevelArrayStride 72
padding[0]: offset 360, type 1405, size 10, index 0, binding -1, stages 0, arrayStride 4, topLevelArrayStride 4
MultipleArrays.tri[0].v[0].position[0]: offset 0, type 1406, size 3, index 1, binding -1, stages 1, arrayStride 4, topLevelArrayStride 72
MultipleArrays.tri[0].v[0].normal[0]: offset 12, type 1406, size 3, index 1, binding -1, stages 0, arrayStride 4, topLevelArrayStride 72
MultipleArrays.tri[0].v[1].position[0]: offset 24, type 1406, size 3, index 1, binding -1, stages 0, arrayStride 4, topLevelArrayStride 72
MultipleArrays.tri[0].v[1].normal[0]: offset 36, type 1406, size 3, index 1, binding -1, stages 0, arrayStride 4, topLevelArrayStride 72
MultipleArrays.tri[0].v[2].position[0]: offset 48, type 1406, size 3, index 1, binding -1, stages 0, arrayStride 4, topLevelArrayStride 72
MultipleArrays.tri[0].v[2].normal[0]: offset 60, type 1406, size 3, index 1, binding -1, stages 0, arrayStride 4, topLevelArrayStride 72
MultipleArrays.vert[0].position[0]: offset 360, type 1406, size 3, index 1, binding -1, stages 1, arrayStride 4, topLevelArrayStride 24
MultipleArrays.vert[0].normal[0]: offset 372, type 1406, size 3, index 1, binding -1, stages 0, arrayStride 4, topLevelArrayStride 24
MultipleArrays.f[0]: offset 480, type 1406, size 5, index 1, binding -1, stages 1, arrayStride 4, topLevelArrayStride 4
Buffer block reflection:
VertexCollection: offset -1, type ffffffff, size 400, index -1, binding -1, stages 1, numMembers 7
MultipleArrays: offset -1, type ffffffff, size 500, index -1, binding -1, stages 1, numMembers 9
Pipeline input reflection:
gl_InstanceID: offset 0, type 1404, size 0, index 0, binding -1, stages 1
Pipeline output reflection:
outval: offset 0, type 1406, size 0, index 0, binding -1, stages 1
#version 440 core
in float inval;
void main()
{
float f = inval;
}
#version 440 core
layout(binding = 0, std140) uniform ubo_block {
float unused_uniform;
float shared_uniform;
float vsonly_uniform;
float fsonly_uniform;
} ubo;
in float vertout;
out float fragout;
void main()
{
fragout = vertout;
fragout += ubo.shared_uniform;
fragout += ubo.fsonly_uniform;
}
#version 440 core
layout(binding = 0, std140) uniform ubo_block {
float unused_uniform;
float shared_uniform;
float vsonly_uniform;
float fsonly_uniform;
} ubo;
in float vertin;
out float vertout;
void main()
{
vertout = vertin;
vertout += ubo.shared_uniform;
vertout += ubo.vsonly_uniform;
}
#version 440 core
struct VertexInfo {
float position[3];
float normal[3];
};
struct TriangleInfo {
VertexInfo v[3];
};
buffer VertexCollection {
TriangleInfo t[5];
uint padding[10];
};
buffer MultipleArrays {
TriangleInfo tri[5];
VertexInfo vert[5];
float f[5];
} multiarray;
uniform UBO {
VertexInfo verts[2];
float flt[8];
uvec4 unused;
} ubo;
out float outval;
void main()
{
float f;
f += t[0].v[0].position[0];
f += t[gl_InstanceID].v[gl_InstanceID].position[gl_InstanceID];
f += t[gl_InstanceID].v[gl_InstanceID].normal[gl_InstanceID];
f += multiarray.tri[gl_InstanceID].v[0].position[0];
f += multiarray.vert[gl_InstanceID].position[0];
f += multiarray.f[gl_InstanceID];
f += ubo.verts[gl_InstanceID].position[0];
f += ubo.flt[gl_InstanceID];
TriangleInfo tlocal[5] = t;
outval = f;
}
...@@ -161,6 +161,22 @@ buffer buf4 { ...@@ -161,6 +161,22 @@ buffer buf4 {
N2 runtimeArray[]; N2 runtimeArray[];
} buf4i; } buf4i;
struct VertexInfo {
float position[3];
float normal[3];
};
struct TriangleInfo {
VertexInfo v[3];
};
buffer VertexCollection {
TriangleInfo t[5];
uint padding[10];
};
out float outval;
void main() void main()
{ {
liveFunction1(image_ui2D, sampler_2D, sampler_2DMSArray); liveFunction1(image_ui2D, sampler_2D, sampler_2DMSArray);
...@@ -216,4 +232,11 @@ void main() ...@@ -216,4 +232,11 @@ void main()
N1 b[4] = nest2.b; N1 b[4] = nest2.b;
f += nest2.c[1].a; f += nest2.c[1].a;
f += nest2.d[gl_InstanceID].a; f += nest2.d[gl_InstanceID].a;
f += t[0].v[0].position[0];
f += t[gl_InstanceID].v[gl_InstanceID].position[gl_InstanceID];
f += t[gl_InstanceID].v[gl_InstanceID].normal[gl_InstanceID];
TriangleInfo tlocal[5] = t;
outval = f;
} }
...@@ -32,6 +32,16 @@ diff -b $BASEDIR/badMacroArgs.frag.out $TARGETDIR/badMacroArgs.frag.out || HASER ...@@ -32,6 +32,16 @@ diff -b $BASEDIR/badMacroArgs.frag.out $TARGETDIR/badMacroArgs.frag.out || HASER
echo Running reflection... echo Running reflection...
$EXE -l -q -C reflection.vert > $TARGETDIR/reflection.vert.out $EXE -l -q -C reflection.vert > $TARGETDIR/reflection.vert.out
diff -b $BASEDIR/reflection.vert.out $TARGETDIR/reflection.vert.out || HASERROR=1 diff -b $BASEDIR/reflection.vert.out $TARGETDIR/reflection.vert.out || HASERROR=1
$EXE -l -q -C --reflect-strict-array-suffix --reflect-basic-array-suffix --reflect-intermediate-io --reflect-separate-buffers --reflect-all-block-variables reflection.options.vert > $TARGETDIR/reflection.options.vert.out
diff -b $BASEDIR/reflection.options.vert.out $TARGETDIR/reflection.options.vert.out || HASERROR=1
$EXE -l -q -C reflection.frag > $TARGETDIR/reflection.frag.out
diff -b $BASEDIR/reflection.frag.out $TARGETDIR/reflection.frag.out || HASERROR=1
$EXE -l -q -C --reflect-strict-array-suffix --reflect-basic-array-suffix --reflect-intermediate-io --reflect-separate-buffers --reflect-all-block-variables reflection.frag > $TARGETDIR/reflection.options.frag.out
diff -b $BASEDIR/reflection.options.frag.out $TARGETDIR/reflection.options.frag.out || HASERROR=1
$EXE -l -q -C reflection.linked.vert reflection.linked.frag > $TARGETDIR/reflection.linked.out
diff -b $BASEDIR/reflection.linked.out $TARGETDIR/reflection.linked.out || HASERROR=1
$EXE -l -q -C --reflect-strict-array-suffix --reflect-basic-array-suffix --reflect-intermediate-io --reflect-separate-buffers --reflect-all-block-variables reflection.linked.vert reflection.linked.frag > $TARGETDIR/reflection.linked.options.out
diff -b $BASEDIR/reflection.linked.options.out $TARGETDIR/reflection.linked.options.out || HASERROR=1
$EXE -D -Od -e flizv -l -q -C -V -Od hlsl.reflection.vert > $TARGETDIR/hlsl.reflection.vert.out $EXE -D -Od -e flizv -l -q -C -V -Od hlsl.reflection.vert > $TARGETDIR/hlsl.reflection.vert.out
diff -b $BASEDIR/hlsl.reflection.vert.out $TARGETDIR/hlsl.reflection.vert.out || HASERROR=1 diff -b $BASEDIR/hlsl.reflection.vert.out $TARGETDIR/hlsl.reflection.vert.out || HASERROR=1
$EXE -D -Od -e main -l -q -C -V -Od hlsl.reflection.binding.frag > $TARGETDIR/hlsl.reflection.binding.frag.out $EXE -D -Od -e main -l -q -C -V -Od hlsl.reflection.binding.frag > $TARGETDIR/hlsl.reflection.binding.frag.out
......
...@@ -1966,12 +1966,27 @@ const char* TProgram::getInfoDebugLog() ...@@ -1966,12 +1966,27 @@ const char* TProgram::getInfoDebugLog()
// Reflection implementation. // Reflection implementation.
// //
bool TProgram::buildReflection() bool TProgram::buildReflection(int opts)
{ {
if (! linked || reflection) if (! linked || reflection)
return false; return false;
reflection = new TReflection; int firstStage = EShLangVertex, lastStage = EShLangFragment;
if (opts & EShReflectionIntermediateIO) {
// if we're reflecting intermediate I/O, determine the first and last stage linked and use those as the
// boundaries for which stages generate pipeline inputs/outputs
firstStage = EShLangCount;
lastStage = 0;
for (int s = 0; s < EShLangCount; ++s) {
if (intermediate[s]) {
firstStage = std::min(firstStage, s);
lastStage = std::max(lastStage, s);
}
}
}
reflection = new TReflection((EShReflectionOptions)opts, (EShLanguage)firstStage, (EShLanguage)lastStage);
for (int s = 0; s < EShLangCount; ++s) { for (int s = 0; s < EShLangCount; ++s) {
if (intermediate[s]) { if (intermediate[s]) {
...@@ -1983,27 +1998,23 @@ bool TProgram::buildReflection() ...@@ -1983,27 +1998,23 @@ bool TProgram::buildReflection()
return true; return true;
} }
int TProgram::getNumLiveUniformVariables() const { return reflection->getNumUniforms(); } unsigned TProgram::getLocalSize(int dim) const { return reflection->getLocalSize(dim); }
int TProgram::getNumLiveUniformBlocks() const { return reflection->getNumUniformBlocks(); } int TProgram::getReflectionIndex(const char* name) const { return reflection->getIndex(name); }
const char* TProgram::getUniformName(int index) const { return reflection->getUniform(index).name.c_str(); }
const char* TProgram::getUniformBlockName(int index) const { return reflection->getUniformBlock(index).name.c_str(); } int TProgram::getNumUniformVariables() const { return reflection->getNumUniforms(); }
int TProgram::getUniformBlockSize(int index) const { return reflection->getUniformBlock(index).size; } const TObjectReflection& TProgram::getUniform(int index) const { return reflection->getUniform(index); }
int TProgram::getUniformIndex(const char* name) const { return reflection->getIndex(name); } int TProgram::getNumUniformBlocks() const { return reflection->getNumUniformBlocks(); }
int TProgram::getUniformBinding(int index) const { return reflection->getUniform(index).getBinding(); } const TObjectReflection& TProgram::getUniformBlock(int index) const { return reflection->getUniformBlock(index); }
EShLanguageMask TProgram::getUniformStages(int index) const { return reflection->getUniform(index).stages; } int TProgram::getNumPipeInputs() const { return reflection->getNumPipeInputs(); }
int TProgram::getUniformBlockBinding(int index) const { return reflection->getUniformBlock(index).getBinding(); } const TObjectReflection& TProgram::getPipeInput(int index) const { return reflection->getPipeInput(index); }
int TProgram::getUniformBlockIndex(int index) const { return reflection->getUniform(index).index; } int TProgram::getNumPipeOutputs() const { return reflection->getNumPipeOutputs(); }
int TProgram::getUniformBlockCounterIndex(int index) const { return reflection->getUniformBlock(index).counterIndex; } const TObjectReflection& TProgram::getPipeOutput(int index) const { return reflection->getPipeOutput(index); }
int TProgram::getUniformType(int index) const { return reflection->getUniform(index).glDefineType; } int TProgram::getNumBufferVariables() const { return reflection->getNumBufferVariables(); }
int TProgram::getUniformBufferOffset(int index) const { return reflection->getUniform(index).offset; } const TObjectReflection& TProgram::getBufferVariable(int index) const { return reflection->getBufferVariable(index); }
int TProgram::getUniformArraySize(int index) const { return reflection->getUniform(index).size; } int TProgram::getNumBufferBlocks() const { return reflection->getNumStorageBuffers(); }
int TProgram::getNumLiveAttributes() const { return reflection->getNumAttributes(); } const TObjectReflection& TProgram::getBufferBlock(int index) const { return reflection->getStorageBufferBlock(index); }
const char* TProgram::getAttributeName(int index) const { return reflection->getAttribute(index).name.c_str(); } int TProgram::getNumAtomicCounters() const { return reflection->getNumAtomicCounters(); }
int TProgram::getAttributeType(int index) const { return reflection->getAttribute(index).glDefineType; } const TObjectReflection& TProgram::getAtomicCounter(int index) const { return reflection->getAtomicCounter(index); }
const TType* TProgram::getAttributeTType(int index) const { return reflection->getAttribute(index).getType(); }
const TType* TProgram::getUniformTType(int index) const { return reflection->getUniform(index).getType(); }
const TType* TProgram::getUniformBlockTType(int index) const { return reflection->getUniformBlock(index).getType(); }
unsigned TProgram::getLocalSize(int dim) const { return reflection->getLocalSize(dim); }
void TProgram::dumpReflection() { reflection->dump(); } void TProgram::dumpReflection() { reflection->dump(); }
......
...@@ -52,51 +52,11 @@ class TIntermediate; ...@@ -52,51 +52,11 @@ class TIntermediate;
class TIntermAggregate; class TIntermAggregate;
class TReflectionTraverser; class TReflectionTraverser;
// Data needed for just a single object at the granularity exchanged by the reflection API
class TObjectReflection {
public:
TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex) :
name(pName), offset(pOffset),
glDefineType(pGLDefineType), size(pSize), index(pIndex), counterIndex(-1), stages(EShLanguageMask(0)), type(pType.clone()) { }
const TType* getType() const { return type; }
int getBinding() const
{
if (type == nullptr || !type->getQualifier().hasBinding())
return -1;
return type->getQualifier().layoutBinding;
}
void dump() const
{
printf("%s: offset %d, type %x, size %d, index %d, binding %d, stages %d",
name.c_str(), offset, glDefineType, size, index, getBinding(), stages );
if (counterIndex != -1)
printf(", counter %d", counterIndex);
printf("\n");
}
static TObjectReflection badReflection() { return TObjectReflection(); }
std::string name;
int offset;
int glDefineType;
int size; // data size in bytes for a block, array size for a (non-block) object that's an array
int index;
int counterIndex;
EShLanguageMask stages;
protected:
TObjectReflection() :
offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), stages(EShLanguageMask(0)), type(nullptr) { }
const TType* type;
};
// The full reflection database // The full reflection database
class TReflection { class TReflection {
public: public:
TReflection() : badReflection(TObjectReflection::badReflection()) TReflection(EShReflectionOptions opts, EShLanguage first, EShLanguage last)
: options(opts), firstStage(first), lastStage(last), badReflection(TObjectReflection::badReflection())
{ {
for (int dim=0; dim<3; ++dim) for (int dim=0; dim<3; ++dim)
localSize[dim] = 0; localSize[dim] = 0;
...@@ -127,17 +87,57 @@ public: ...@@ -127,17 +87,57 @@ public:
return badReflection; return badReflection;
} }
// for mapping an attribute index to the attribute's description // for mapping an pipeline input index to the input's description
int getNumAttributes() { return (int)indexToAttribute.size(); } int getNumPipeInputs() { return (int)indexToPipeInput.size(); }
const TObjectReflection& getAttribute(int i) const const TObjectReflection& getPipeInput(int i) const
{
if (i >= 0 && i < (int)indexToPipeInput.size())
return indexToPipeInput[i];
else
return badReflection;
}
// for mapping an pipeline output index to the output's description
int getNumPipeOutputs() { return (int)indexToPipeOutput.size(); }
const TObjectReflection& getPipeOutput(int i) const
{ {
if (i >= 0 && i < (int)indexToAttribute.size()) if (i >= 0 && i < (int)indexToPipeOutput.size())
return indexToAttribute[i]; return indexToPipeOutput[i];
else else
return badReflection; return badReflection;
} }
// for mapping any name to its index (block names, uniform names and attribute names) // for mapping from an atomic counter to the uniform index
int getNumAtomicCounters() const { return (int)atomicCounterUniformIndices.size(); }
const TObjectReflection& getAtomicCounter(int i) const
{
if (i >= 0 && i < (int)atomicCounterUniformIndices.size())
return getUniform(atomicCounterUniformIndices[i]);
else
return badReflection;
}
// for mapping a buffer variable index to a buffer variable object's description
int getNumBufferVariables() { return (int)indexToBufferVariable.size(); }
const TObjectReflection& getBufferVariable(int i) const
{
if (i >= 0 && i < (int)indexToBufferVariable.size())
return indexToBufferVariable[i];
else
return badReflection;
}
// for mapping a storage block index to the storage block's description
int getNumStorageBuffers() const { return (int)indexToBufferBlock.size(); }
const TObjectReflection& getStorageBufferBlock(int i) const
{
if (i >= 0 && i < (int)indexToBufferBlock.size())
return indexToBufferBlock[i];
else
return badReflection;
}
// for mapping any name to its index (block names, uniform names and input/output names)
int getIndex(const char* name) const int getIndex(const char* name) const
{ {
TNameToIndex::const_iterator it = nameToIndex.find(name); TNameToIndex::const_iterator it = nameToIndex.find(name);
...@@ -165,12 +165,35 @@ protected: ...@@ -165,12 +165,35 @@ protected:
// Need a TString hash: typedef std::unordered_map<TString, int> TNameToIndex; // Need a TString hash: typedef std::unordered_map<TString, int> TNameToIndex;
typedef std::map<std::string, int> TNameToIndex; typedef std::map<std::string, int> TNameToIndex;
typedef std::vector<TObjectReflection> TMapIndexToReflection; typedef std::vector<TObjectReflection> TMapIndexToReflection;
typedef std::vector<int> TIndices;
TMapIndexToReflection& GetBlockMapForStorage(TStorageQualifier storage)
{
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
return indexToBufferBlock;
return indexToUniformBlock;
}
TMapIndexToReflection& GetVariableMapForStorage(TStorageQualifier storage)
{
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
return indexToBufferVariable;
return indexToUniform;
}
EShReflectionOptions options;
EShLanguage firstStage;
EShLanguage lastStage;
TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this
TNameToIndex nameToIndex; // maps names to indexes; can hold all types of data: uniform/buffer and which function names have been processed TNameToIndex nameToIndex; // maps names to indexes; can hold all types of data: uniform/buffer and which function names have been processed
TMapIndexToReflection indexToUniform; TMapIndexToReflection indexToUniform;
TMapIndexToReflection indexToUniformBlock; TMapIndexToReflection indexToUniformBlock;
TMapIndexToReflection indexToAttribute; TMapIndexToReflection indexToBufferVariable;
TMapIndexToReflection indexToBufferBlock;
TMapIndexToReflection indexToPipeInput;
TMapIndexToReflection indexToPipeOutput;
TIndices atomicCounterUniformIndices;
unsigned int localSize[3]; unsigned int localSize[3];
}; };
......
...@@ -237,6 +237,18 @@ enum EShMessages { ...@@ -237,6 +237,18 @@ enum EShMessages {
}; };
// //
// Options for building reflection
//
typedef enum {
EShReflectionDefault = 0, // default is original behaviour before options were added
EShReflectionStrictArraySuffix = (1 << 0), // reflection will follow stricter rules for array-of-structs suffixes
EShReflectionBasicArraySuffix = (1 << 1), // arrays of basic types will be appended with [0] as in GL reflection
EShReflectionIntermediateIO = (1 << 2), // reflect inputs and outputs to program, even with no vertex shader
EShReflectionSeparateBuffers = (1 << 3), // buffer variables and buffer blocks are reflected separately
EShReflectionAllBlockVariables = (1 << 4), // reflect all variables in blocks, even if they are inactive
} EShReflectionOptions;
//
// Build a table for bindings. This can be used for locating // Build a table for bindings. This can be used for locating
// attributes, uniforms, globals, etc., as needed. // attributes, uniforms, globals, etc., as needed.
// //
...@@ -596,6 +608,41 @@ private: ...@@ -596,6 +608,41 @@ private:
TShader& operator=(TShader&); TShader& operator=(TShader&);
}; };
//
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
//
// Data needed for just a single object at the granularity exchanged by the reflection API
class TObjectReflection {
public:
TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
const TType* getType() const { return type; }
int getBinding() const;
void dump() const;
static TObjectReflection badReflection() { return TObjectReflection(); }
std::string name;
int offset;
int glDefineType;
int size; // data size in bytes for a block, array size for a (non-block) object that's an array
int index;
int counterIndex;
int numMembers;
int arrayStride; // stride of an array variable
int topLevelArrayStride; // stride of the top-level variable in a storage buffer member
EShLanguageMask stages;
protected:
TObjectReflection()
: offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), numMembers(-1), arrayStride(0),
topLevelArrayStride(0), stages(EShLanguageMask(0)), type(nullptr)
{
}
const TType* type;
};
class TReflection; class TReflection;
class TIoMapper; class TIoMapper;
...@@ -685,28 +732,89 @@ public: ...@@ -685,28 +732,89 @@ public:
TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; } TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; }
// Reflection Interface // Reflection Interface
bool buildReflection(); // call first, to do liveness analysis, index mapping, etc.; returns false on failure
int getNumLiveUniformVariables() const; // can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS) // call first, to do liveness analysis, index mapping, etc.; returns false on failure
int getNumLiveUniformBlocks() const; // can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS) bool buildReflection(int opts = EShReflectionDefault);
const char* getUniformName(int index) const; // can be used for "name" part of glGetActiveUniform()
const char* getUniformBlockName(int blockIndex) const; // can be used for glGetActiveUniformBlockName()
int getUniformBlockSize(int blockIndex) const; // can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
int getUniformIndex(const char* name) const; // can be used for glGetUniformIndices()
int getUniformBinding(int index) const; // returns the binding number
EShLanguageMask getUniformStages(int index) const; // returns Shaders Stages where a Uniform is present
int getUniformBlockBinding(int index) const; // returns the block binding number
int getUniformBlockIndex(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
int getUniformBlockCounterIndex(int index) const; // returns block index of associated counter.
int getUniformType(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
int getUniformBufferOffset(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
int getUniformArraySize(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
int getNumLiveAttributes() const; // can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
unsigned getLocalSize(int dim) const; // return dim'th local size unsigned getLocalSize(int dim) const; // return dim'th local size
const char *getAttributeName(int index) const; // can be used for glGetActiveAttrib() int getReflectionIndex(const char *name) const;
int getAttributeType(int index) const; // can be used for glGetActiveAttrib()
const TType* getUniformTType(int index) const; // returns a TType* int getNumUniformVariables() const;
const TType* getUniformBlockTType(int index) const; // returns a TType* const TObjectReflection& getUniform(int index) const;
const TType* getAttributeTType(int index) const; // returns a TType* int getNumUniformBlocks() const;
const TObjectReflection& getUniformBlock(int index) const;
int getNumPipeInputs() const;
const TObjectReflection& getPipeInput(int index) const;
int getNumPipeOutputs() const;
const TObjectReflection& getPipeOutput(int index) const;
int getNumBufferVariables() const;
const TObjectReflection& getBufferVariable(int index) const;
int getNumBufferBlocks() const;
const TObjectReflection& getBufferBlock(int index) const;
int getNumAtomicCounters() const;
const TObjectReflection& getAtomicCounter(int index) const;
// Legacy Reflection Interface - expressed in terms of above interface
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
int getNumLiveUniformVariables() const { return getNumUniformVariables(); }
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
int getNumLiveUniformBlocks() const { return getNumUniformBlocks(); }
// can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
int getNumLiveAttributes() const { return getNumPipeInputs(); }
// can be used for glGetUniformIndices()
int getUniformIndex(const char *name) const { return getReflectionIndex(name); }
// can be used for "name" part of glGetActiveUniform()
const char *getUniformName(int index) const { return getUniform(index).name.c_str(); }
// returns the binding number
int getUniformBinding(int index) const { return getUniform(index).getBinding(); }
// returns Shaders Stages where a Uniform is present
EShLanguageMask getUniformStages(int index) const { return getUniform(index).stages; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
int getUniformBlockIndex(int index) const { return getUniform(index).index; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
int getUniformType(int index) const { return getUniform(index).glDefineType; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
int getUniformBufferOffset(int index) const { return getUniform(index).offset; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
int getUniformArraySize(int index) const { return getUniform(index).size; }
// returns a TType*
const TType *getUniformTType(int index) const { return getUniform(index).getType(); }
// can be used for glGetActiveUniformBlockName()
const char *getUniformBlockName(int index) const { return getUniformBlock(index).name.c_str(); }
// can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
int getUniformBlockSize(int index) const { return getUniformBlock(index).size; }
// returns the block binding number
int getUniformBlockBinding(int index) const { return getUniformBlock(index).getBinding(); }
// returns block index of associated counter.
int getUniformBlockCounterIndex(int index) const { return getUniformBlock(index).counterIndex; }
// returns a TType*
const TType *getUniformBlockTType(int index) const { return getUniformBlock(index).getType(); }
// can be used for glGetActiveAttrib()
const char *getAttributeName(int index) const { return getPipeInput(index).name.c_str(); }
// can be used for glGetActiveAttrib()
int getAttributeType(int index) const { return getPipeInput(index).glDefineType; }
// returns a TType*
const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); }
void dumpReflection(); void dumpReflection();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment