Skip to content

Commit 5026a64

Browse files
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-Examples-and-Tests into autoexposure_ex
2 parents 7a5ea7c + eff1c85 commit 5026a64

File tree

24 files changed

+2277
-372
lines changed

24 files changed

+2277
-372
lines changed

02_HelloCompute/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class HelloComputeApp final : public nbl::application_templates::MonoSystemMonoL
149149
.binding=0,
150150
.type=nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
151151
.createFlags=IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE, // not is not the time for descriptor indexing
152-
.stageFlags=IGPUShader::ESS_COMPUTE,
152+
.stageFlags=IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
153153
.count=1,
154154
}
155155
};

03_DeviceSelectionAndSharedSources/Testers.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class IntrospectionTesterBase
5353
// The Shader Asset Loaders deduce the stage from the file extension,
5454
// if the extension is generic (.glsl or .hlsl) the stage is unknown.
5555
// But it can still be overriden from within the source with a `#pragma shader_stage`
56-
options.stage = source->getStage() == IShader::ESS_COMPUTE ? source->getStage() : IShader::ESS_VERTEX; // TODO: do smth with it
56+
options.stage = source->getStage() == IShader::E_SHADER_STAGE::ESS_COMPUTE ? source->getStage() : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it
5757
options.targetSpirvVersion = device->getPhysicalDevice()->getLimits().spirvVersion;
5858
// we need to perform an unoptimized compilation with source debug info or we'll lose names of variable sin the introspection
5959
options.spirvOptimizer = nullptr;
@@ -201,7 +201,7 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
201201
.binding = 0,
202202
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
203203
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
204-
.stageFlags = ICPUShader::ESS_COMPUTE,
204+
.stageFlags = ICPUShader::E_SHADER_STAGE::ESS_COMPUTE,
205205
.count = 1,
206206
.immutableSamplers = nullptr
207207
}
@@ -213,15 +213,15 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
213213
.binding = 0,
214214
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
215215
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
216-
.stageFlags = ICPUShader::ESS_COMPUTE,
216+
.stageFlags = ICPUShader::E_SHADER_STAGE::ESS_COMPUTE,
217217
.count = 1,
218218
.immutableSamplers = nullptr
219219
},
220220
{
221221
.binding = 1,
222222
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
223223
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
224-
.stageFlags = ICPUShader::ESS_COMPUTE,
224+
.stageFlags = ICPUShader::E_SHADER_STAGE::ESS_COMPUTE,
225225
.count = 2,
226226
.immutableSamplers = nullptr
227227
}

03_DeviceSelectionAndSharedSources/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
8585
binding.binding = introspectionBinding.binding;
8686
binding.type = introspectionBinding.type;
8787
binding.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE;
88-
binding.stageFlags = IGPUShader::ESS_COMPUTE;
88+
binding.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE;
8989
assert(introspectionBinding.count.countMode == CSPIRVIntrospector::CIntrospectionData::SDescriptorArrayInfo::DESCRIPTOR_COUNT::STATIC);
9090
binding.count = introspectionBinding.count.count;
9191
}
@@ -305,7 +305,7 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
305305
// The Shader Asset Loaders deduce the stage from the file extension,
306306
// if the extension is generic (.glsl or .hlsl) the stage is unknown.
307307
// But it can still be overriden from within the source with a `#pragma shader_stage`
308-
options.stage = source->getStage() == IShader::ESS_COMPUTE ? source->getStage() : IShader::ESS_VERTEX; // TODO: do smth with it
308+
options.stage = source->getStage() == IShader::E_SHADER_STAGE::ESS_COMPUTE ? source->getStage() : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it
309309
options.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion;
310310
// we need to perform an unoptimized compilation with source debug info or we'll lose names of variable sin the introspection
311311
options.spirvOptimizer = nullptr;

07_StagingAndMultipleQueues/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
313313
smart_refctd_ptr<ICPUShader> source;
314314
{
315315
source = loadFistAssetInBundle<ICPUShader>("../app_resources/comp_shader.hlsl");
316-
source->setShaderStage(IShader::ESS_COMPUTE);
316+
source->setShaderStage(IShader::E_SHADER_STAGE::ESS_COMPUTE);
317317
}
318318

319319
if (!source)

10_CountingSort/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CountingSortApp final : public application_templates::MonoDeviceApplicatio
8989
}
9090

9191
// People love Reflection but I prefer Shader Sources instead!
92-
const nbl::asset::SPushConstantRange pcRange = { .stageFlags = IShader::ESS_COMPUTE,.offset = 0,.size = sizeof(CountingPushData) };
92+
const nbl::asset::SPushConstantRange pcRange = { .stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE,.offset = 0,.size = sizeof(CountingPushData) };
9393

9494
// This time we'll have no Descriptor Sets or Layouts because our workload has a widely varying size
9595
// and using traditional SSBO bindings would force us to update the Descriptor Set every frame.
@@ -229,7 +229,7 @@ class CountingSortApp final : public application_templates::MonoDeviceApplicatio
229229
cmdBuf->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
230230
cmdBuf->beginDebugMarker("Prefix Sum Dispatch", core::vectorSIMDf(0, 1, 0, 1));
231231
cmdBuf->bindComputePipeline(prefixSumPipeline.get());
232-
cmdBuf->pushConstants(layout.get(), IShader::ESS_COMPUTE, 0u, sizeof(pc), &pc);
232+
cmdBuf->pushConstants(layout.get(), IShader::E_SHADER_STAGE::ESS_COMPUTE, 0u, sizeof(pc), &pc);
233233
cmdBuf->dispatch(ceil((float)element_count / (elements_per_thread * WorkgroupSize)), 1, 1);
234234
cmdBuf->endDebugMarker();
235235
cmdBuf->end();
@@ -271,7 +271,7 @@ class CountingSortApp final : public application_templates::MonoDeviceApplicatio
271271
cmdBuf->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
272272
cmdBuf->beginDebugMarker("Scatter Dispatch", core::vectorSIMDf(0, 1, 0, 1));
273273
cmdBuf->bindComputePipeline(scatterPipeline.get());
274-
cmdBuf->pushConstants(layout.get(), IShader::ESS_COMPUTE, 0u, sizeof(pc), &pc);
274+
cmdBuf->pushConstants(layout.get(), IShader::E_SHADER_STAGE::ESS_COMPUTE, 0u, sizeof(pc), &pc);
275275
cmdBuf->dispatch(ceil((float)element_count / (elements_per_thread * WorkgroupSize)), 1, 1);
276276
cmdBuf->endDebugMarker();
277277
cmdBuf->end();

21_LRUCacheUnitTest/main.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ class LRUCacheTestApp final : public nbl::application_templates::MonoSystemMonoL
1919
public:
2020
using base_t::base_t;
2121

22+
constexpr static uint32_t InvalidTextureIdx = 41234;
23+
struct TextureReference
24+
{
25+
uint32_t alloc_idx;
26+
uint64_t lastUsedSemaphoreValue;
27+
28+
TextureReference(uint32_t alloc_idx, uint64_t semaphoreVal) : alloc_idx(alloc_idx), lastUsedSemaphoreValue(semaphoreVal) {}
29+
TextureReference(uint64_t semaphoreVal) : TextureReference(InvalidTextureIdx, semaphoreVal) {}
30+
TextureReference() : TextureReference(InvalidTextureIdx, ~0ull) {}
31+
32+
// In LRU Cache `insert` function, in case of cache hit, we need to assign semaphore value to TextureReference without changing `alloc_idx`
33+
inline TextureReference& operator=(uint64_t semamphoreVal) { lastUsedSemaphoreValue = semamphoreVal; return *this; }
34+
};
35+
36+
using TextureLRUCache = core::LRUCache<uint32_t, TextureReference>;
37+
2238
// we stuff all our work here because its a "single shot" app
2339
bool onAppInitialized(smart_refctd_ptr<ISystem>&& system) override
2440
{
@@ -108,6 +124,24 @@ class LRUCacheTestApp final : public nbl::application_templates::MonoSystemMonoL
108124
cache2.print(m_logger);
109125
cache2.insert(++i, "key is 112");
110126

127+
m_textureLRUCache = std::unique_ptr<TextureLRUCache>(new TextureLRUCache(1024u));
128+
{
129+
SIntendedSubmitInfo intendedNextSubmit = {};
130+
auto evictionCallback = [&](const TextureReference& evicted)
131+
{
132+
};
133+
const auto nextSemaSignal = intendedNextSubmit.getFutureScratchSemaphore();
134+
TextureReference* inserted = m_textureLRUCache->insert(69420, nextSemaSignal.value, evictionCallback);
135+
}
136+
{
137+
SIntendedSubmitInfo intendedNextSubmit = {};
138+
auto evictionCallback = [&](const TextureReference& evicted)
139+
{
140+
};
141+
const auto nextSemaSignal = intendedNextSubmit.getFutureScratchSemaphore();
142+
TextureReference* inserted = m_textureLRUCache->insert(69420, nextSemaSignal.value, evictionCallback);
143+
}
144+
111145
#ifdef _NBL_DEBUG
112146
cache2.print(m_logger);
113147
#endif
@@ -153,6 +187,7 @@ class LRUCacheTestApp final : public nbl::application_templates::MonoSystemMonoL
153187

154188
return true;
155189
}
190+
std::unique_ptr<TextureLRUCache> m_textureLRUCache;
156191

157192
void workLoopBody() override {}
158193

22_CppCompat/app_resources/test.comp.hlsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct device_capabilities0
7575
{
7676
NBL_CONSTEXPR_STATIC_INLINE bool shaderFloat64 = true;
7777
NBL_CONSTEXPR_STATIC_INLINE bool shaderDrawParameters = true;
78-
NBL_CONSTEXPR_STATIC_INLINE bool subgroupArithmetic = true;
78+
NBL_CONSTEXPR_STATIC_INLINE bool shaderSubgroupArithmetic = true;
7979
NBL_CONSTEXPR_STATIC_INLINE bool fragmentShaderPixelInterlock = true;
8080
NBL_CONSTEXPR_STATIC_INLINE uint16_t maxOptimallyResidentWorkgroupInvocations = 16;
8181
};
@@ -89,7 +89,7 @@ struct device_capabilities1
8989

9090
struct device_capabilities2
9191
{
92-
NBL_CONSTEXPR_STATIC_INLINE bool subgroupArithmetic = true;
92+
NBL_CONSTEXPR_STATIC_INLINE bool shaderSubgroupArithmetic = true;
9393
NBL_CONSTEXPR_STATIC_INLINE bool fragmentShaderPixelInterlock = true;
9494
NBL_CONSTEXPR_STATIC_INLINE uint16_t maxOptimallyResidentWorkgroupInvocations = 16;
9595
NBL_CONSTEXPR_STATIC_INLINE uint32_t extraRandomField = 42;
@@ -278,15 +278,15 @@ void main(uint3 invocationID : SV_DispatchThreadID)
278278

279279
{
280280
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities0>::shaderFloat64 == device_capabilities0::shaderFloat64);
281-
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities0>::subgroupArithmetic == device_capabilities0::subgroupArithmetic);
281+
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities0>::shaderSubgroupArithmetic == device_capabilities0::shaderSubgroupArithmetic);
282282
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities0>::fragmentShaderPixelInterlock == device_capabilities0::fragmentShaderPixelInterlock);
283283
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities0>::maxOptimallyResidentWorkgroupInvocations == device_capabilities0::maxOptimallyResidentWorkgroupInvocations);
284284
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities1>::shaderFloat64 == device_capabilities1::shaderFloat64);
285-
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities1>::subgroupArithmetic == false);
285+
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities1>::shaderSubgroupArithmetic == false);
286286
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities1>::fragmentShaderPixelInterlock == device_capabilities1::fragmentShaderPixelInterlock);
287287
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities1>::maxOptimallyResidentWorkgroupInvocations == device_capabilities1::maxOptimallyResidentWorkgroupInvocations);
288288
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities2>::shaderFloat64 == false);
289-
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities2>::subgroupArithmetic == device_capabilities2::subgroupArithmetic);
289+
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities2>::shaderSubgroupArithmetic == device_capabilities2::shaderSubgroupArithmetic);
290290
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities2>::fragmentShaderPixelInterlock == device_capabilities2::fragmentShaderPixelInterlock);
291291
STATIC_ASSERT(nbl::hlsl::device_capabilities_traits<device_capabilities2>::maxOptimallyResidentWorkgroupInvocations == device_capabilities2::maxOptimallyResidentWorkgroupInvocations);
292292

22_CppCompat/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CompatibilityTest final : public MonoDeviceApplication, public MonoAssetMa
7676
auto source = IAsset::castDown<ICPUShader>(assets[0]);
7777
// The down-cast should not fail!
7878
assert(source);
79-
assert(source->getStage() == IShader::ESS_COMPUTE);
79+
assert(source->getStage() == IShader::E_SHADER_STAGE::ESS_COMPUTE);
8080

8181
// this time we skip the use of the asset converter since the ICPUShader->IGPUShader path is quick and simple
8282
shader = m_device->createShader(source.get());
@@ -93,14 +93,14 @@ class CompatibilityTest final : public MonoDeviceApplication, public MonoAssetMa
9393

9494
for(int i = 0; i < bindingCount; ++i)
9595
{
96-
bindings[i].stageFlags = IShader::ESS_COMPUTE;
96+
bindings[i].stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE;
9797
bindings[i].count = 1;
9898
bindings[i].binding = i;
9999
}
100100
m_descriptorSetLayout = m_device->createDescriptorSetLayout(bindings);
101101
{
102102
SPushConstantRange pcRange = {};
103-
pcRange.stageFlags = IShader::ESS_COMPUTE;
103+
pcRange.stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE;
104104
pcRange.offset = 0u;
105105
pcRange.size = 2 * sizeof(uint32_t);
106106
auto layout = m_device->createPipelineLayout({ &pcRange,1 }, smart_refctd_ptr(m_descriptorSetLayout));

23_ArithmeticUnitTest/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class ArithmeticUnitTestApp final : public application_templates::BasicMultiQueu
107107
{
108108
IGPUDescriptorSetLayout::SBinding binding[2];
109109
for (uint32_t i = 0u; i < 2; i++)
110-
binding[i] = { i,IDescriptor::E_TYPE::ET_STORAGE_BUFFER, IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE, IShader::ESS_COMPUTE, 1u, nullptr };
110+
binding[i] = { i,IDescriptor::E_TYPE::ET_STORAGE_BUFFER, IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE, IShader::E_SHADER_STAGE::ESS_COMPUTE, 1u, nullptr };
111111
binding[1].count = OutputBufferCount;
112112
dsLayout = m_device->createDescriptorSetLayout(binding);
113113
}

24_ColorSpaceTest/app_resources/present.frag.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ using namespace nbl::hlsl::ext::FullScreenTriangle;
2121
{
2222
const float32_t2 repeatCoord = vxAttr.uv*float32_t2(pc.grid);
2323
const int32_t layer = int32_t(repeatCoord.y)*pc.grid.x+int32_t(repeatCoord.x);
24-
return texture.Sample(samplerState,float32_t3(repeatCoord,layer));
24+
float4 color = texture.Sample(samplerState,float32_t3(repeatCoord,layer));
25+
return color * color.a;
2526
}

0 commit comments

Comments
 (0)