Skip to content

Commit b483aa6

Browse files
committed
better hlsl dispatch
1 parent b5194ef commit b483aa6

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

31_HLSLPathTracer/app_resources/hlsl/render.comp.hlsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343

4444
using namespace nbl::hlsl;
4545

46-
NBL_CONSTEXPR uint32_t WorkgroupSize = 32;
46+
NBL_CONSTEXPR uint32_t WorkgroupSize = 256;
4747
NBL_CONSTEXPR uint32_t MAX_DEPTH_LOG2 = 4;
4848
NBL_CONSTEXPR uint32_t MAX_SAMPLES_LOG2 = 10;
4949

5050
int32_t2 getCoordinates()
5151
{
52-
return int32_t2(glsl::gl_GlobalInvocationID().xy);
52+
uint32_t width, height;
53+
outImage.GetDimensions(width, height);
54+
return int32_t2(glsl::gl_GlobalInvocationID().x % width, glsl::gl_GlobalInvocationID().x / width);
5355
}
5456

5557
float32_t2 getTexCoords()
@@ -141,7 +143,7 @@ static const ext::Scene<light_type, bxdfnode_type> scene = ext::Scene<light_type
141143
lights, LIGHT_COUNT, bxdfs, BXDF_COUNT
142144
);
143145

144-
[numthreads(WorkgroupSize, WorkgroupSize, 1)]
146+
[numthreads(WorkgroupSize, 1, 1)]
145147
void main(uint32_t3 threadID : SV_DispatchThreadID)
146148
{
147149
uint32_t width, height;

31_HLSLPathTracer/main.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,12 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
366366
options.stage = IShader::E_SHADER_STAGE::ESS_COMPUTE; // should be compute
367367
options.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion;
368368
options.spirvOptimizer = nullptr;
369-
//#ifndef _NBL_DEBUG
370-
// ISPIRVOptimizer::E_OPTIMIZER_PASS optPasses = ISPIRVOptimizer::EOP_STRIP_DEBUG_INFO;
371-
// auto opt = make_smart_refctd_ptr<ISPIRVOptimizer>(std::span<ISPIRVOptimizer::E_OPTIMIZER_PASS>(&optPasses, 1));
372-
// options.spirvOptimizer = opt.get();
373-
//#endif
374-
options.debugInfoFlags |= IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT;
369+
#ifndef _NBL_DEBUG
370+
ISPIRVOptimizer::E_OPTIMIZER_PASS optPasses = ISPIRVOptimizer::EOP_STRIP_DEBUG_INFO;
371+
auto opt = make_smart_refctd_ptr<ISPIRVOptimizer>(std::span<ISPIRVOptimizer::E_OPTIMIZER_PASS>(&optPasses, 1));
372+
options.spirvOptimizer = opt.get();
373+
#endif
374+
options.debugInfoFlags = IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_NONE;
375375
options.preprocessorOptions.sourceIdentifier = source->getFilepathHint();
376376
options.preprocessorOptions.logger = m_logger.get();
377377
options.preprocessorOptions.includeFinder = compiler->getDefaultIncludeFinder();
@@ -418,8 +418,8 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
418418
params.shader.shader = ptShader.get();
419419
params.shader.entryPoint = "main";
420420
params.shader.entries = nullptr;
421-
params.shader.requireFullSubgroups = true;
422-
params.shader.requiredSubgroupSize = static_cast<IGPUShader::SSpecInfo::SUBGROUP_SIZE>(5);
421+
params.shader.requireFullSubgroups = true;
422+
params.shader.requiredSubgroupSize = static_cast<IGPUShader::SSpecInfo::SUBGROUP_SIZE>(5);
423423
if (!m_device->createComputePipelines(nullptr, { &params, 1 }, m_PTGLSLPipelines.data() + index))
424424
return logFail("Failed to create GLSL compute pipeline!\n");
425425
}
@@ -1068,7 +1068,10 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
10681068
cmdbuf->bindDescriptorSets(EPBP_COMPUTE, pipeline->getLayout(), 0u, 1u, &m_descriptorSet0.get());
10691069
cmdbuf->bindDescriptorSets(EPBP_COMPUTE, pipeline->getLayout(), 2u, 1u, &m_descriptorSet2.get());
10701070
cmdbuf->pushConstants(pipeline->getLayout(), IShader::E_SHADER_STAGE::ESS_COMPUTE, 0, sizeof(PTPushConstant), &pc);
1071-
cmdbuf->dispatch(1 + (WindowDimensions.x - 1) / DefaultWorkGroupSize, 1 + (WindowDimensions.y - 1) / DefaultWorkGroupSize, 1u);
1071+
if (renderMode == E_RENDER_MODE::ERM_HLSL)
1072+
cmdbuf->dispatch(1 + (WindowDimensions.x * WindowDimensions.y - 1) / 256u, 1u, 1u);
1073+
else
1074+
cmdbuf->dispatch(1 + (WindowDimensions.x - 1) / DefaultWorkGroupSize, 1 + (WindowDimensions.y - 1) / DefaultWorkGroupSize, 1u);
10721075
}
10731076

10741077
// TRANSITION m_outImgView to READ (because of descriptorSets0 -> ComputeShader Writes into the image)

0 commit comments

Comments
 (0)