Alright as you pointed out it is faster to render the pixels to mark into the stencil masks. But i have one problem doing that, with this technique i have two way the pixels are marked. The frist is the compute shader which writes the data, later needed, to an uav with the same dimensions as the viewport, i am masking on a second way using the stencil buffer. My problem is that they do not 100% match. Here is some code for clearification:
RWTexture2DArray<uint> pointer : register(u1);
AppendStructuredBuffer<float4> pixelMark : register(u3);
...
float4 projected = mul(float4(position, 1.0), mCameraWorldProjectionGS[z]);
projected /= projected.w;
projected = Frustum2TextureSpace(projected);
int2 xy = projected.xy * textureDimensions.xy;
int z = LightDirectionDetermineView(depth, g_fLightDirection_BasePow, g_fLightDirection_Far, g_Camera_vProps.w, NUM_PROJECTION);
pixelMark.Append(positionIndex); // store pixel for later create stencil mask
pointer[int3(xy, z)] = uint4(1, 1, 1, 1);
i am not sure that xy is calculated correctly. Here you can see the result, there is one pixel that does not match, the upper is the data written by the compute shader and the other is the stencil buffer. I render to the stencil buffer using DrawInstancedIndirect.
The frustum coordinates of of the error pixel are from the projection: -0.372919900 -0.142580700 0.305269900 1.0 after division by w
The index the compute shader writes to is therefore: 321.0650112 585.0013184 though int3(321 585 1)
The frustum coordinates are written in markPixel and later rendered by DrawInstancedIndirect, but the pixel 321 585 1 gets never written, is that an rounding error or something in the viewport transfrom i have not encounted?