Allow easier switching between offline/online reflection for tests

This commit is contained in:
baldurk
2022-03-17 18:10:06 +00:00
parent 345206b2b8
commit 5076ab1b4d
2 changed files with 136 additions and 92 deletions
+130 -91
View File
@@ -268,6 +268,9 @@ void TestGLSLReflection(ShaderType testType, ReflectionMaker compile)
REQUIRE(size >= min); \
CHECK(size == min);
#define MAPPING_VALID(mapping) \
(mapping.inputAttributes.empty() || mapping.inputAttributes[0] != 0x12345678)
if(testType == ShaderType::GLSL || testType == ShaderType::GLSPIRV)
{
// test GL only features
@@ -339,10 +342,13 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
if(MAPPING_VALID(mapping))
{
// $Globals
CHECK(mapping.constantBlocks[0].used);
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
{
// $Globals
CHECK(mapping.constantBlocks[0].used);
}
}
};
@@ -383,13 +389,16 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.readWriteResources.size(), 1);
if(MAPPING_VALID(mapping))
{
// atom
CHECK(mapping.readWriteResources[0].bindset == 0);
CHECK(mapping.readWriteResources[0].bind == 0);
CHECK(mapping.readWriteResources[0].arraySize == 1);
CHECK(mapping.readWriteResources[0].used);
REQUIRE_ARRAY_SIZE(mapping.readWriteResources.size(), 1);
{
// atom
CHECK(mapping.readWriteResources[0].bindset == 0);
CHECK(mapping.readWriteResources[0].bind == 0);
CHECK(mapping.readWriteResources[0].arraySize == 1);
CHECK(mapping.readWriteResources[0].used);
}
}
};
}
@@ -431,13 +440,16 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.samplers.size(), 1);
if(MAPPING_VALID(mapping))
{
// S
CHECK(mapping.samplers[0].bindset == 1);
CHECK(mapping.samplers[0].bind == 2);
CHECK(mapping.samplers[0].arraySize == 1);
CHECK(mapping.samplers[0].used);
REQUIRE_ARRAY_SIZE(mapping.samplers.size(), 1);
{
// S
CHECK(mapping.samplers[0].bindset == 1);
CHECK(mapping.samplers[0].bind == 2);
CHECK(mapping.samplers[0].arraySize == 1);
CHECK(mapping.samplers[0].used);
}
}
REQUIRE_ARRAY_SIZE(refl.readOnlyResources.size(), 2);
@@ -465,19 +477,22 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.readOnlyResources.size(), 2);
if(MAPPING_VALID(mapping))
{
// T
CHECK(mapping.readOnlyResources[0].bindset == 2);
CHECK(mapping.readOnlyResources[0].bind == 4);
CHECK(mapping.readOnlyResources[0].arraySize == 1);
CHECK(mapping.readOnlyResources[0].used);
REQUIRE_ARRAY_SIZE(mapping.readOnlyResources.size(), 2);
{
// T
CHECK(mapping.readOnlyResources[0].bindset == 2);
CHECK(mapping.readOnlyResources[0].bind == 4);
CHECK(mapping.readOnlyResources[0].arraySize == 1);
CHECK(mapping.readOnlyResources[0].used);
// ST
CHECK(mapping.readOnlyResources[1].bindset == 2);
CHECK(mapping.readOnlyResources[1].bind == 5);
CHECK(mapping.readOnlyResources[1].arraySize == 1);
CHECK(mapping.readOnlyResources[1].used);
// ST
CHECK(mapping.readOnlyResources[1].bindset == 2);
CHECK(mapping.readOnlyResources[1].bind == 5);
CHECK(mapping.readOnlyResources[1].arraySize == 1);
CHECK(mapping.readOnlyResources[1].used);
}
}
};
@@ -550,13 +565,16 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
if(MAPPING_VALID(mapping))
{
// spec constants
CHECK(mapping.constantBlocks[0].bindset == SpecializationConstantBindSet);
CHECK(mapping.constantBlocks[0].bind == 0);
CHECK(mapping.constantBlocks[0].arraySize == 1);
CHECK(mapping.constantBlocks[0].used);
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
{
// spec constants
CHECK(mapping.constantBlocks[0].bindset == SpecializationConstantBindSet);
CHECK(mapping.constantBlocks[0].bind == 0);
CHECK(mapping.constantBlocks[0].arraySize == 1);
CHECK(mapping.constantBlocks[0].used);
}
}
};
@@ -638,13 +656,16 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
if(MAPPING_VALID(mapping))
{
// push_data
CHECK(mapping.constantBlocks[0].bindset == PushConstantBindSet);
CHECK(mapping.constantBlocks[0].bind == 0);
CHECK(mapping.constantBlocks[0].arraySize == 1);
CHECK(mapping.constantBlocks[0].used);
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
{
// push_data
CHECK(mapping.constantBlocks[0].bindset == PushConstantBindSet);
CHECK(mapping.constantBlocks[0].bind == 0);
CHECK(mapping.constantBlocks[0].arraySize == 1);
CHECK(mapping.constantBlocks[0].used);
}
}
};
}
@@ -842,15 +863,18 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.inputAttributes.size(), 16);
for(size_t i = 0; i < mapping.inputAttributes.size(); i++)
if(MAPPING_VALID(mapping))
{
if(i == 3)
CHECK((mapping.inputAttributes[i] == -1 || mapping.inputAttributes[i] == 1));
else if(i == 6)
CHECK((mapping.inputAttributes[i] == -1 || mapping.inputAttributes[i] == 2));
else
CHECK(mapping.inputAttributes[i] == -1);
REQUIRE_ARRAY_SIZE(mapping.inputAttributes.size(), 16);
for(size_t i = 0; i < mapping.inputAttributes.size(); i++)
{
if(i == 3)
CHECK((mapping.inputAttributes[i] == -1 || mapping.inputAttributes[i] == 1));
else if(i == 6)
CHECK((mapping.inputAttributes[i] == -1 || mapping.inputAttributes[i] == 2));
else
CHECK(mapping.inputAttributes[i] == -1);
}
}
};
@@ -1048,13 +1072,16 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
if(MAPPING_VALID(mapping))
{
// ubo
CHECK(mapping.constantBlocks[0].bindset == 0);
CHECK(mapping.constantBlocks[0].bind == 8);
CHECK(mapping.constantBlocks[0].arraySize == 1);
CHECK(mapping.constantBlocks[0].used);
REQUIRE_ARRAY_SIZE(mapping.constantBlocks.size(), 1);
{
// ubo
CHECK(mapping.constantBlocks[0].bindset == 0);
CHECK(mapping.constantBlocks[0].bind == 8);
CHECK(mapping.constantBlocks[0].arraySize == 1);
CHECK(mapping.constantBlocks[0].used);
}
}
};
@@ -1118,25 +1145,28 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.readOnlyResources.size(), 3);
if(MAPPING_VALID(mapping))
{
// tex2d
CHECK(mapping.readOnlyResources[0].bindset == 0);
CHECK(mapping.readOnlyResources[0].bind == 3);
CHECK(mapping.readOnlyResources[0].arraySize == 1);
CHECK(mapping.readOnlyResources[0].used);
REQUIRE_ARRAY_SIZE(mapping.readOnlyResources.size(), 3);
{
// tex2d
CHECK(mapping.readOnlyResources[0].bindset == 0);
CHECK(mapping.readOnlyResources[0].bind == 3);
CHECK(mapping.readOnlyResources[0].arraySize == 1);
CHECK(mapping.readOnlyResources[0].used);
// tex3d
CHECK(mapping.readOnlyResources[1].bindset == 0);
CHECK(mapping.readOnlyResources[1].bind == 5);
CHECK(mapping.readOnlyResources[1].arraySize == 1);
CHECK(mapping.readOnlyResources[1].used);
// tex3d
CHECK(mapping.readOnlyResources[1].bindset == 0);
CHECK(mapping.readOnlyResources[1].bind == 5);
CHECK(mapping.readOnlyResources[1].arraySize == 1);
CHECK(mapping.readOnlyResources[1].used);
// texBuf
CHECK(mapping.readOnlyResources[2].bindset == 0);
CHECK(mapping.readOnlyResources[2].bind == 7);
CHECK(mapping.readOnlyResources[2].arraySize == 1);
CHECK(mapping.readOnlyResources[2].used);
// texBuf
CHECK(mapping.readOnlyResources[2].bindset == 0);
CHECK(mapping.readOnlyResources[2].bind == 7);
CHECK(mapping.readOnlyResources[2].arraySize == 1);
CHECK(mapping.readOnlyResources[2].used);
}
}
};
@@ -1415,19 +1445,22 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.readWriteResources.size(), 2);
if(MAPPING_VALID(mapping))
{
// ssbo
CHECK(mapping.readWriteResources[0].bindset == 0);
CHECK(mapping.readWriteResources[0].bind == 2);
CHECK(mapping.readWriteResources[0].arraySize == 1);
CHECK(mapping.readWriteResources[0].used);
REQUIRE_ARRAY_SIZE(mapping.readWriteResources.size(), 2);
{
// ssbo
CHECK(mapping.readWriteResources[0].bindset == 0);
CHECK(mapping.readWriteResources[0].bind == 2);
CHECK(mapping.readWriteResources[0].arraySize == 1);
CHECK(mapping.readWriteResources[0].used);
// ssbo2
CHECK(mapping.readWriteResources[1].bindset == 0);
CHECK(mapping.readWriteResources[1].bind == 5);
CHECK(mapping.readWriteResources[1].arraySize == 1);
CHECK(mapping.readWriteResources[1].used);
// ssbo2
CHECK(mapping.readWriteResources[1].bindset == 0);
CHECK(mapping.readWriteResources[1].bind == 5);
CHECK(mapping.readWriteResources[1].arraySize == 1);
CHECK(mapping.readWriteResources[1].used);
}
}
};
@@ -2142,14 +2175,17 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.readOnlyResources.size(), countRO);
if(MAPPING_VALID(mapping))
{
for(size_t i = 0; i < countRO; i++)
REQUIRE_ARRAY_SIZE(mapping.readOnlyResources.size(), countRO);
{
CHECK(mapping.readOnlyResources[i].bindset == 0);
CHECK(mapping.readOnlyResources[i].bind == 3 + (int32_t)i);
CHECK(mapping.readOnlyResources[i].arraySize == arraySizeRO);
CHECK(mapping.readOnlyResources[i].used);
for(size_t i = 0; i < countRO; i++)
{
CHECK(mapping.readOnlyResources[i].bindset == 0);
CHECK(mapping.readOnlyResources[i].bind == 3 + (int32_t)i);
CHECK(mapping.readOnlyResources[i].arraySize == arraySizeRO);
CHECK(mapping.readOnlyResources[i].used);
}
}
}
@@ -2209,14 +2245,17 @@ void main() {
}
}
REQUIRE_ARRAY_SIZE(mapping.readWriteResources.size(), countRW);
if(MAPPING_VALID(mapping))
{
for(size_t i = 0; i < countRW; i++)
REQUIRE_ARRAY_SIZE(mapping.readWriteResources.size(), countRW);
{
CHECK(mapping.readWriteResources[i].bindset == 0);
CHECK(mapping.readWriteResources[i].bind == 2 + (int32_t)i);
CHECK(mapping.readWriteResources[i].arraySize == arraySizeRW);
CHECK(mapping.readWriteResources[i].used);
for(size_t i = 0; i < countRW; i++)
{
CHECK(mapping.readWriteResources[i].bindset == 0);
CHECK(mapping.readWriteResources[i].bind == 2 + (int32_t)i);
CHECK(mapping.readWriteResources[i].arraySize == arraySizeRW);
CHECK(mapping.readWriteResources[i].used);
}
}
}
};
+6 -1
View File
@@ -4156,7 +4156,7 @@ void MakeOnlineShaderReflection(ShaderStage stage, const rdcstr &source, const r
bytebuf buf;
buf.resize(source.size());
memcpy(buf.data(), source.data(), source.size());
driver->BuildCustomShader(ShaderEncoding::GLSL, buf, "main", ShaderCompileFlags(), stage, id,
driver->BuildTargetShader(ShaderEncoding::GLSL, buf, "main", ShaderCompileFlags(), stage, id,
errors);
if(id == ResourceId())
@@ -4167,6 +4167,11 @@ void MakeOnlineShaderReflection(ShaderStage stage, const rdcstr &source, const r
refl = *driver->GetShader(ResourceId(), id, ShaderEntryPoint("main", ShaderStage::Fragment));
// hack the mapping so that tests can skip checks of mapping when using online compilation (see
// MAPPING_VALID)
mapping.inputAttributes.resize(1);
mapping.inputAttributes[0] = 0x12345678;
// Note that we can't fill out ShaderBindpointMapping easily on the actual driver through the
// replay interface
WARN("Using online reflection - all checks with ShaderBindpointMapping will fail");