I’ve 4 rendertargets R10G10B10A2 every getting used to retailer shade and regular in a compact double RGB 555 bits format. Once I’m doing the lighting cross I am obliged to have additional rendertargets as a result of if I can learn(extract) the conventional/shade, I am unable to write again straight the lit shade to those surfaces.
So I moved to a compute shader to attain this objective (DX11 CS5). I’ve discovered that I am restricted to R32_UINT for learn/write in DX11 CS5. I’ve thus tailored my encoding/decoding to have issues work effective, though the ultimate colours are a little bit bit hugly with my encoding.
Sadly the ultimate body price is decrease than the common pixel shader even when I’ve to do 4 copyresources from the intermediate rendertargets with my earlier methodology.
I’ve applied the CS ranging from these discovered within the legacy DX11 samples. My code is like this:
CPU calls:
//some CSbufferConstant and CSshaderresourceview settings (e.g. shadowmaps, depth textures
gpDC11->CSSetShader(pCS, 0, 0);
//I' mworking on 4 UAV on the similar time within the CSshader. With just one it's even slower
gpDC11->CSSetUnorderedAccessViews(0, 4, gSRDeffered.ppUAV, (UINT*)(&gSRDeffered.ppUAV));
gpDC11->Dispatch(960, 540, 1);//the dimensions of my display screen
GPU CS shader:
[numthreads(1,1,1)]
void CS_PostDeferred( uint3 nGid : SV_GroupID, uint3 nDTid : SV_DispatchThreadID, uint3 nGTid : SV_GroupThreadID )//solely nDTid is used actually right here
{
uint Output;
float2 Tex = float2(nDTid.x/960.0, nDTid.y/540.0);
float Depth1 = txDepth1.SampleLevel(samPoint, Tex, 0).r;
float Depth2 = txDepth2.SampleLevel(samPoint, Tex, 0).r;
float Depth3 = txDepth3.SampleLevel(samPoint, Tex, 0).r;
float Depth4 = txDepth4.SampleLevel(samPoint, Tex, 0).r;
Output = UAVDiffuse0[nDTid.xy];
if ( Depth1 < 1 ) Output = GetLColorUnPackPack_CS(Depth1, Tex, Output);
UAVDiffuse0[nDTid.xy]=Output;
Output = UAVDiffuse1[nDTid.xy];
if ( Depth2 < 1 ) Output = GetLColorUnPackPack_CS(Depth2, Tex, Output);
UAVDiffuse1[nDTid.xy]=Output;
Output = UAVDiffuse2[nDTid.xy];
if ( Depth3 < 1 ) Output = GetLColorUnPackPack_CS(Depth3, Tex, Output);
UAVDiffuse2[nDTid.xy]=Output;
Output = UAVDiffuse3[nDTid.xy];
if ( Depth4 < 1 ) Output = GetLColorUnPackPack_CS(Depth4, Tex, Output);
UAVDiffuse3[nDTid.xy]=Output;
}
The uint GetLColorUnPackPack_CS (float Depth, float2 UV, uint Knowledge) is the perform extracting the colour and regular as 2 float3 from the R32_UINT Knowledge param, calculating as standard lighting and shadows for the pixel after which recompacting the ultimate shade to the R32_UINT (the conventional just isn’t modified). The Depth and UV params are used to get well the place in view area wanted for the purpose lights I am utilizing.
Any recommendation welcome