@@ -22,9 +22,7 @@ bool ClusteredRenderer::supported()
2222 // compute shader
2323 (caps->supported & BGFX_CAPS_COMPUTE) != 0 &&
2424 // 32-bit index buffers, used for light grid structure
25- // D3D12 doesn't report this but it works fine...
26- // TODO try again with updated bgfx
27- ((caps->supported & BGFX_CAPS_INDEX32) != 0 || caps->rendererType == bgfx::RendererType::Direct3D12) &&
25+ ((caps->supported & BGFX_CAPS_INDEX32) != 0 ) &&
2826 // fragment depth available in fragment shader
2927 (caps->supported & BGFX_CAPS_FRAGMENT_DEPTH) != 0 ;
3028}
@@ -58,7 +56,22 @@ void ClusteredRenderer::onRender(float dt)
5856 vLightCulling,
5957 vLighting
6058 };
59+
60+ bgfx::setViewName (vClusterBuilding, " Cluster building pass (compute)" );
61+ bgfx::setViewClear (vClusterBuilding, BGFX_CLEAR_NONE);
62+ // set u_viewRect for screen2Eye to work correctly
63+ bgfx::setViewRect (vClusterBuilding, 0 , 0 , width, height);
64+ // this could be set by a different renderer, reset it (D3D12 cares and crashes)
65+ bgfx::setViewFrameBuffer (vClusterBuilding, BGFX_INVALID_HANDLE);
66+ // bgfx::touch(vClusterBuilding);
67+
68+ bgfx::setViewName (vLightCulling, " Clustered light culling pass (compute)" );
69+ bgfx::setViewClear (vLightCulling, BGFX_CLEAR_NONE);
70+ bgfx::setViewRect (vLightCulling, 0 , 0 , width, height);
71+ bgfx::setViewFrameBuffer (vLightCulling, BGFX_INVALID_HANDLE);
72+ // bgfx::touch(vLightCulling);
6173
74+ bgfx::setViewName (vLighting, " Clustered lighting pass" );
6275 bgfx::setViewClear (vLighting, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, clearColor, 1 .0f , 0 );
6376 bgfx::setViewRect (vLighting, 0 , 0 , width, height);
6477 bgfx::setViewFrameBuffer (vLighting, frameBuffer);
@@ -67,50 +80,36 @@ void ClusteredRenderer::onRender(float dt)
6780 if (!scene->loaded )
6881 return ;
6982
70- // D3D12 crashes if this is not set, even for compute only views
71- // TODO try again with updated bgfx
72- bgfx::setViewFrameBuffer (vClusterBuilding, BGFX_INVALID_HANDLE);
73- bgfx::setViewFrameBuffer (vLightCulling, BGFX_INVALID_HANDLE);
74-
7583 clusters.setUniforms (scene, width, height);
7684
77- // set u_viewRect for screen2Eye to work correctly
78- bgfx::setViewRect (vClusterBuilding, 0 , 0 , width, height);
79- bgfx::setViewRect (vLightCulling, 0 , 0 , width, height);
80-
8185 // cluster building needs u_invProj to transform screen coordinates to eye space
8286 setViewProjection (vClusterBuilding);
8387 // light culling needs u_view to transform lights to eye space
8488 setViewProjection (vLightCulling);
89+ setViewProjection (vLighting);
8590
86- {
87- bgfx::setViewName (vClusterBuilding, " Cluster building pass (compute)" );
91+ // cluster building
8892
89- clusters.bindBuffers (false ); // write access, all buffers
93+ clusters.bindBuffers (false ); // write access, all buffers
9094
91- bgfx::dispatch (vClusterBuilding,
92- clusterBuildingComputeProgram,
93- ClusterShader::CLUSTERS_X,
94- ClusterShader::CLUSTERS_Y,
95- ClusterShader::CLUSTERS_Z);
96- }
95+ bgfx::dispatch (vClusterBuilding,
96+ clusterBuildingComputeProgram,
97+ ClusterShader::CLUSTERS_X,
98+ ClusterShader::CLUSTERS_Y,
99+ ClusterShader::CLUSTERS_Z);
97100
98- {
99- bgfx::setViewName (vLightCulling, " Clustered light culling pass (compute)" );
101+ // light culling
100102
101- lights.bindLights (scene);
102- clusters.bindBuffers (false ); // write access, all buffers
103+ lights.bindLights (scene);
104+ clusters.bindBuffers (false ); // write access, all buffers
103105
104- bgfx::dispatch (vLightCulling,
105- lightCullingComputeProgram,
106- 1 ,
107- 1 ,
108- ClusterShader::CLUSTERS_Z / ClusterShader::CLUSTERS_Z_THREADS);
109- }
106+ bgfx::dispatch (vLightCulling,
107+ lightCullingComputeProgram,
108+ 1 ,
109+ 1 ,
110+ ClusterShader::CLUSTERS_Z / ClusterShader::CLUSTERS_Z_THREADS);
110111
111- bgfx::setViewName (vLighting, " Clustered lighting pass" );
112-
113- setViewProjection (vLighting);
112+ // lighting
114113
115114 uint64_t state = BGFX_STATE_DEFAULT & ~BGFX_STATE_CULL_MASK;
116115
0 commit comments