Skip to content

Commit f1b50c4

Browse files
committed
Created ppln layout merge tests
1 parent f8e74f0 commit f1b50c4

File tree

6 files changed

+119
-3
lines changed

6 files changed

+119
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This is a magical header that provides most HLSL types and intrinsics in C++
2+
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
3+
4+
struct PSInput
5+
{
6+
[[vk::location(2)]] nointerpolation uint4 data1 : COLOR1;
7+
[[vk::location(5)]] float2 data2 : COLOR2;
8+
};
9+
10+
struct SomeType
11+
{
12+
uint32_t a;
13+
uint32_t b[5];
14+
uint32_t c[10];
15+
};
16+
17+
NBL_CONSTEXPR uint32_t WorkgroupSize = 256;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma wave shader_stage(compute)
2+
#include "common.hlsl"
3+
4+
[[vk::binding(0,0)]] RWStructuredBuffer<SomeType> asdf;
5+
[[vk::binding(1,0)]] RWByteAddressBuffer output[3];
6+
[[vk::binding(2,0)]] RWByteAddressBuffer output2[];
7+
8+
struct PushConstants
9+
{
10+
int a;
11+
};
12+
[[vk::push_constant]]
13+
PushConstants pc;
14+
15+
[numthreads(WorkgroupSize, 1, 1)]
16+
void main(uint32_t3 ID : SV_DispatchThreadID)
17+
{
18+
const uint32_t index = ID.x;
19+
const uint32_t byteOffset = sizeof(uint32_t)*index;
20+
21+
output[0].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
22+
output[1].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
23+
output[2].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
24+
output2[1].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] - asdf[index].c[3]);
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma wave shader_stage(compute)
2+
#include "common.hlsl"
3+
4+
[[vk::binding(4,2)]] RWStructuredBuffer<SomeType> asdf;
5+
[[vk::binding(6,3)]] RWByteAddressBuffer outputBuff;
6+
7+
[numthreads(WorkgroupSize, 1, 1)]
8+
void main(uint32_t3 ID : SV_DispatchThreadID)
9+
{
10+
const uint32_t index = ID.x;
11+
const uint32_t byteOffset = sizeof(uint32_t)*index;
12+
13+
outputBuff.Store<uint32_t>(byteOffset, asdf[index].a);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma wave shader_stage(compute)
2+
#include "common.hlsl"
3+
4+
[[vk::binding(0,0)]] RWStructuredBuffer<SomeType> asdf;
5+
[[vk::binding(1,0)]] RWByteAddressBuffer output[3];
6+
7+
[numthreads(WorkgroupSize, 1, 1)]
8+
void main(uint32_t3 ID : SV_DispatchThreadID)
9+
{
10+
const uint32_t index = ID.x;
11+
const uint32_t byteOffset = sizeof(uint32_t)*index;
12+
13+
output[0].Store<uint32_t>(byteOffset, asdf[index].a);
14+
}

03_DeviceSelectionAndSharedSources/app_resources/test.hlsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#pragma wave shader_stage(compute)
22
#include "common.hlsl"
33

4+
[[vk::constant_id(3)]] uint32_t SPEC_CONSTANT_VALUE = 10;
5+
46
struct SomeType
57
{
68
uint32_t a;
79
uint32_t b[5];
810
uint32_t c[10];
911
};
12+
1013
[[vk::binding(0,0)]] RWStructuredBuffer<SomeType> asdf;
1114
[[vk::binding(1,0)]] RWByteAddressBuffer output[3];
1215
[[vk::binding(2,0)]] RWByteAddressBuffer output2[];
@@ -17,7 +20,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID)
1720
const uint32_t index = ID.x;
1821
const uint32_t byteOffset = sizeof(uint32_t)*index;
1922

20-
output[0].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
23+
output[0].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3] * SPEC_CONSTANT_VALUE);
2124
output[1].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
2225
output[2].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
2326
output2[1].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] - asdf[index].c[3]);

03_DeviceSelectionAndSharedSources/main.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,56 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
4242
//if (!introspection->canSpecializationlesslyCreateDescSetFrom())
4343
//return logFail("Someone changed the shader and some descriptor binding depends on a specialization constant!");
4444

45+
#if 0
4546
// flexible test
4647
{
4748
m_logger->log("------- test.hlsl INTROSPECTION -------", ILogger::E_LOG_LEVEL::ELL_WARNING);
4849
CSPIRVIntrospector introspector;
4950
auto sourceIntrospectionPair = this->compileShaderAndTestIntrospection("app_resources/test.hlsl", introspector);
50-
CSPIRVIntrospector::CPipelineIntrospectionData pplnIntroData;
51-
pplnIntroData.merge(sourceIntrospectionPair.second.get());
51+
auto pplnIntroData = core::make_smart_refctd_ptr<CSPIRVIntrospector::CPipelineIntrospectionData>();
52+
pplnIntroData->merge(sourceIntrospectionPair.second.get());
53+
}
54+
#endif
55+
// testing creation of compute pipeline layouts compatible for multiple shaders
56+
{
57+
constexpr uint32_t MERGE_TEST_SHADERS_CNT = 3u;
58+
59+
60+
std::array mergeTestShadersPaths = {
61+
"app_resources/pplnLayoutMergeTest/shader_1.comp.hlsl",
62+
"app_resources/pplnLayoutMergeTest/shader_2.comp.hlsl",
63+
"app_resources/pplnLayoutMergeTest/shader_3.comp.hlsl"
64+
};
65+
66+
auto confirmExpectedOutput = [this](bool value, bool expectedValue)
67+
{
68+
if (value != expectedValue)
69+
{
70+
m_logger->log("\"CSPIRVIntrospector::CPipelineIntrospectionData::merge\" function FAIL, incorrect output.",
71+
ILogger::E_LOG_LEVEL::ELL_ERROR);
72+
}
73+
else
74+
{
75+
m_logger->log("\"CSPIRVIntrospector::CPipelineIntrospectionData::merge\" function SUCCESS, correct output.",
76+
ILogger::E_LOG_LEVEL::ELL_PERFORMANCE);
77+
}
78+
};
79+
80+
CSPIRVIntrospector introspector[MERGE_TEST_SHADERS_CNT];
81+
smart_refctd_ptr<const CSPIRVIntrospector::CStageIntrospectionData> introspections[MERGE_TEST_SHADERS_CNT];
82+
83+
for (uint32_t i = 0u; i < MERGE_TEST_SHADERS_CNT; ++i)
84+
{
85+
m_logger->log("------- %s INTROSPECTION -------", ILogger::E_LOG_LEVEL::ELL_WARNING, mergeTestShadersPaths[i]);
86+
auto sourceIntrospectionPair = this->compileShaderAndTestIntrospection(mergeTestShadersPaths[i], introspector[i]);
87+
introspections[i] = sourceIntrospectionPair.second;
88+
}
89+
90+
core::smart_refctd_ptr<CSPIRVIntrospector::CPipelineIntrospectionData> pplnIntroData;
91+
pplnIntroData = core::make_smart_refctd_ptr<CSPIRVIntrospector::CPipelineIntrospectionData>();
92+
confirmExpectedOutput(pplnIntroData->merge(introspections[0].get()), true);
93+
confirmExpectedOutput(pplnIntroData->merge(introspections[1].get()), true);
94+
confirmExpectedOutput(pplnIntroData->merge(introspections[2].get()), false);
5295
}
5396

5497
m_logger->log("------- shader.comp.hlsl INTROSPECTION -------", ILogger::E_LOG_LEVEL::ELL_WARNING);

0 commit comments

Comments
 (0)