@@ -22,6 +22,7 @@ struct PTPushConstant
2222 int sampleCount;
2323 int depth;
2424 const uint32_t rwmcCascadeSize = CascadeSize;
25+ int useRWMC;
2526 uint32_t rwmcCascadeStart;
2627 uint32_t rwmcCascadeBase;
2728};
@@ -74,7 +75,7 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
7475 static inline std::array<std::string, E_LIGHT_GEOMETRY::ELG_COUNT> PTGLSLShaderPaths = { " app_resources/glsl/litBySphere.comp" , " app_resources/glsl/litByTriangle.comp" , " app_resources/glsl/litByRectangle.comp" };
7576 static inline std::string PTHLSLShaderPath = " app_resources/hlsl/render.comp.hlsl" ;
7677 static inline std::array<std::string, E_LIGHT_GEOMETRY::ELG_COUNT> PTHLSLShaderVariants = { " SPHERE_LIGHT" , " TRIANGLE_LIGHT" , " RECTANGLE_LIGHT" };
77- static inline std::string ReweightingShaderPath = " app_resources/hlsl/reweighting .hlsl" ;
78+ static inline std::string ReweightingShaderPath = " app_resources/hlsl/resolve.comp .hlsl" ;
7879 static inline std::string PresentShaderPath = " app_resources/hlsl/present.frag.hlsl" ;
7980
8081 const char * shaderNames[E_LIGHT_GEOMETRY::ELG_COUNT] = {
@@ -1096,6 +1097,12 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
10961097
10971098 ImGui::Text (" X: %f Y: %f" , io.MousePos .x , io.MousePos .y );
10981099
1100+ ImGui::Text (" \n RWMC settings:" );
1101+ ImGui::Checkbox (" Enable RWMC" , &useRWMC);
1102+ ImGui::SliderFloat (" base" , &rwmcPushConstants.base , 1 .0f , 32 .0f );
1103+ ImGui::SliderFloat (" minReliableLuma" , &rwmcPushConstants.minReliableLuma , 0 .1f , 32 .0f );
1104+ ImGui::SliderFloat (" kappa" , &rwmcPushConstants.kappa , 0 .1f , 32 .0f );
1105+
10991106 ImGui::End ();
11001107 }
11011108 );
@@ -1151,9 +1158,6 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
11511158 return m_device->updateDescriptorSets (writes, {});
11521159 }
11531160
1154- // TODO: DON'T DO THAT! tansition layout once at the initialization stage
1155- bool cascadeLayoutTransitioned = false ;
1156-
11571161 inline void workLoopBody () override
11581162 {
11591163 // framesInFlight: ensuring safe execution of command buffers and acquires, `framesInFlight` only affect semaphore waits, don't use this to index your resources because it can change with swapchain recreation.
@@ -1192,6 +1196,7 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
11921196 // disregard surface/swapchain transformation for now
11931197 const auto viewProjectionMatrix = m_camera.getConcatenatedMatrix ();
11941198 viewProjectionMatrix.getInverseTransform (pc.invMVP );
1199+ pc.useRWMC = useRWMC ? 1 : 0 ;
11951200 pc.sampleCount = spp;
11961201 pc.depth = depth;
11971202
@@ -1229,19 +1234,17 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
12291234 cmdbuf->pipelineBarrier (E_DEPENDENCY_FLAGS::EDF_NONE, { .imgBarriers = imgBarriers });
12301235 }
12311236
1232- // TODO: remove! we want to transition cascade layout only once right after its creation
1233- if (!cascadeLayoutTransitioned )
1237+ // transit m_cascadeView layout to GENERAL, block until previous shader is done with reading from cascade
1238+ if (useRWMC )
12341239 {
1235- cascadeLayoutTransitioned = true ;
1236-
12371240 const IGPUCommandBuffer::SImageMemoryBarrier<IGPUCommandBuffer::SOwnershipTransferBarrier> cascadeBarrier[] = {
12381241 {
12391242 .barrier = {
12401243 .dep = {
1241- .srcStageMask = PIPELINE_STAGE_FLAGS::NONE ,
1244+ .srcStageMask = PIPELINE_STAGE_FLAGS::COMPUTE_SHADER_BIT ,
12421245 .srcAccessMask = ACCESS_FLAGS::NONE,
12431246 .dstStageMask = PIPELINE_STAGE_FLAGS::COMPUTE_SHADER_BIT,
1244- .dstAccessMask = ACCESS_FLAGS::SHADER_WRITE_BITS
1247+ .dstAccessMask = ACCESS_FLAGS::NONE
12451248 }
12461249 },
12471250 .image = m_cascadeView->getCreationParameters ().image .get (),
@@ -1250,7 +1253,7 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
12501253 .baseMipLevel = 0u ,
12511254 .levelCount = 1u ,
12521255 .baseArrayLayer = 0u ,
1253- .layerCount = 6u
1256+ .layerCount = CascadeSize
12541257 },
12551258 .oldLayout = IImage::LAYOUT::UNDEFINED,
12561259 .newLayout = IImage::LAYOUT::GENERAL
@@ -1298,16 +1301,15 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
12981301 .baseMipLevel = 0u ,
12991302 .levelCount = 1u ,
13001303 .baseArrayLayer = 0u ,
1301- .layerCount = 6u
1302- },
1303- .oldLayout = IImage::LAYOUT::GENERAL,
1304- .newLayout = IImage::LAYOUT::GENERAL
1304+ .layerCount = CascadeSize
1305+ }
13051306 }
13061307 };
13071308 cmdbuf->pipelineBarrier (E_DEPENDENCY_FLAGS::EDF_NONE, { .imgBarriers = cascadeBarrier });
13081309 }
13091310
13101311 // reweighting
1312+ if (useRWMC)
13111313 {
13121314 IGPUComputePipeline* pipeline;
13131315 if (usePersistentWorkGroups)
@@ -1354,34 +1356,6 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
13541356 cmdbuf->pipelineBarrier (E_DEPENDENCY_FLAGS::EDF_NONE, { .imgBarriers = imgBarriers });
13551357 }
13561358
1357- // m_cascadeView synchronization - wait for previous compute shader to zero-out the cascade
1358- // TODO: create this and every other barrier once outside of the loop?
1359- {
1360- const IGPUCommandBuffer::SImageMemoryBarrier<IGPUCommandBuffer::SOwnershipTransferBarrier> cascadeBarrier[] = {
1361- {
1362- .barrier = {
1363- .dep = {
1364- .srcStageMask = PIPELINE_STAGE_FLAGS::COMPUTE_SHADER_BIT,
1365- .srcAccessMask = ACCESS_FLAGS::SHADER_WRITE_BITS,
1366- .dstStageMask = PIPELINE_STAGE_FLAGS::COMPUTE_SHADER_BIT,
1367- .dstAccessMask = ACCESS_FLAGS::SHADER_WRITE_BITS
1368- }
1369- },
1370- .image = m_cascadeView->getCreationParameters ().image .get (),
1371- .subresourceRange = {
1372- .aspectMask = IImage::EAF_COLOR_BIT,
1373- .baseMipLevel = 0u ,
1374- .levelCount = 1u ,
1375- .baseArrayLayer = 0u ,
1376- .layerCount = 6u
1377- },
1378- .oldLayout = IImage::LAYOUT::GENERAL,
1379- .newLayout = IImage::LAYOUT::GENERAL
1380- }
1381- };
1382- cmdbuf->pipelineBarrier (E_DEPENDENCY_FLAGS::EDF_NONE, { .imgBarriers = cascadeBarrier });
1383- }
1384-
13851359 // TODO: tone mapping and stuff
13861360 }
13871361
@@ -1640,6 +1614,7 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
16401614 int spp = 32 ;
16411615 int depth = 3 ;
16421616 bool usePersistentWorkGroups = false ;
1617+ bool useRWMC = false ;
16431618 RWMCPushConstants rwmcPushConstants;
16441619 PTPushConstant pc;
16451620
0 commit comments