Skip to content

Commit 5d3b3b2

Browse files
RWMC is broken, Persistent workgroups are broken (light and camera doesn't update)
1 parent 85aae49 commit 5d3b3b2

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

31_HLSLPathTracer/app_resources/hlsl/compute_render_scene_impl.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void tracePixel(int32_t2 coords)
8787
}
8888

8989
scene_type scene;
90-
scene.updateLight(renderPushConstants.generalPurposeLightMatrix);
90+
scene.updateLight(renderPushConstants.lightMatrix());
9191

9292
typename variant_types::raygen_type rayGen;
9393
rayGen.pixOffsetParam = pixOffsetParam;

31_HLSLPathTracer/app_resources/hlsl/render_common.hlsl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,28 @@ NBL_CONSTEXPR uint32_t MaxSamplesLog2 = MAX_SAMPLES_LOG2;
1212

1313
struct RenderPushConstants
1414
{
15-
// TODO: cut down the MVP into a compact raygen matrix to get this whole struct to less than 112 bytes!
16-
float32_t4x4 invMVP;
17-
float32_t3x4 generalPurposeLightMatrix;
15+
float32_t3x4 lightMatrix()
16+
{
17+
float32_t4x3 retval;
18+
retval[0] = lightX;
19+
retval[1] = lightY;
20+
retval[2] = cross(lightX,lightY)*lightZscale;
21+
retval[3] = lightPos;
22+
return hlsl::transpose(retval);
23+
}
24+
1825
uint64_t pSampleSequence;
26+
float32_t4x4 invMVP;
27+
float32_t3 lightX;
28+
float32_t3 lightY;
29+
float32_t lightZscale;
30+
float32_t3 lightPos;
1931
// TODO: compact a bit and refactor
2032
uint32_t sampleCount : MAX_SAMPLES_LOG2;
2133
uint32_t depth : MAX_DEPTH_LOG2;
2234
uint32_t sequenceSampleCountLog2 : 5;
2335
uint32_t unused : 13;
36+
uint32_t unused1;
2437
};
2538
#undef MAX_SAMPLES_LOG2
2639
#undef MAX_DEPTH_LOG2

31_HLSLPathTracer/main.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,12 +1218,21 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
12181218
const float32_t4x4 modelViewProjectionMatrix = nbl::hlsl::math::linalg::promoted_mul(viewProjectionMatrix, modelMatrix);
12191219
const float32_t4x4 invMVP = hlsl::inverse(modelViewProjectionMatrix);
12201220

1221+
pc.pSampleSequence = m_sequenceBuffer->getDeviceAddress();
12211222
pc.invMVP = invMVP;
1222-
pc.generalPurposeLightMatrix = hlsl::float32_t3x4(transpose(m_lightModelMatrix));
1223+
{
1224+
const auto matT = hlsl::float32_t4x3(m_lightModelMatrix);
1225+
pc.lightX = matT[0];
1226+
pc.lightY = matT[1];
1227+
// Z had a length and a direction, can point colinear or opposite cross product
1228+
const auto recon = hlsl::cross(matT[0], matT[1]);
1229+
pc.lightZscale = hlsl::sign(hlsl::dot(recon,matT[2]))*hlsl::length(matT[2])/hlsl::length(recon);
1230+
pc.lightPos = matT[3];
1231+
assert(pc.lightMatrix()==hlsl::transpose(matT));
1232+
}
12231233
pc.sampleCount = guiControlled.spp;
12241234
pc.depth = guiControlled.depth;
12251235
pc.sequenceSampleCountLog2 = m_sequenceSamplesLog2;
1226-
pc.pSampleSequence = m_sequenceBuffer->getDeviceAddress();
12271236
if (guiControlled.useRWMC)
12281237
{
12291238
rwmcPushConstants.renderPushConstants = pc;

0 commit comments

Comments
 (0)