Ok guys I have had some pretty good success on this site but I feel that this is a pretty complex question.
I am trying to do tile based deferred lighting using DirectX 11 and the compute shader. Basically I am splitting up the screen into tiles and figuring out which lights hit the pixels in that tile. Then once I get to the pixel shader I only calculate the lighting for the current pixel based on what lights hit that pixel. (I'm pretty sure that I can find the lights that hit the pixel and the lighting calculations for that pixel solely in the compute shader but for now I am not doing that). So currently I think there is two ways that I can get the information to the compute shader. The tile data needs to come in a RWStructuredBuffer so that I can write to it and then use it during other parts of the GPU pipeline in a ShaderResourceView. The thing that I am not sure how to do is what is the best way to get all of the light data to the compute shader? I think I could do it in a constant buffer or a groupshared buffer. I believe the latter of the two is faster but I am not sure how it works and I cannot find much information on it. And if I was to use a constant buffer I would need to house an array of lights in that buffer and I am not sure how I would do that either because I do not want to hard code an array size in the shader.
Here is some code samples to show you what I am doing.
struct ComputeIn
{
uint3 DTid : SV_DispatchThreadID;
int index : SV_GroupIndex;
};
struct TileData
{
float4 position;
float3 normal;
float2 texCoord;
vector<float, 8> something;
};
struct PointLightData
{
float4 color;
float3 pos;
float radius;
};
//If I use a cbuffer for the light data
cbuffer LightData
{
//How do I make an array of lights in a cbuffer
Array of lights here!
};
RWStructuredBuffer<TileData> tileData : register(u0);
//If I use a groupshared
groupshared PointLightData pointLights : register(u1);
[numthreads(1, 1, 1)]
void CS( ComputeIn input )
{
//How do I iterate through the groupshared buffer?
//groupshared[?];
//
}
One more thing. I may be incorrect in assuming this but I assume that memory on the GPU is similar to memory outside of the GPU. If I have a buffer that is passes to the GPU and I know how my data is lined up inside of this buffer, I should be able to traverse through this memory to get to what data I need. My question is how do you traverse memory on the GPU. If I have a this.
struct PointLightData
{
float4 color;
float3 pos;
float radius;
};
StructuredBuffer<PointLightData> pointLights : register(u0);
[numthreads(1, 1, 1)]
void CS( ComputeIn input )
{
//FIGURE OUT WHAT LIGHTS HIT THIS TILE!
}
I assume that pointLights is a "pointer" to the beginning of this memory. How would I go about traversing all of the memory inside of this buffer? Suppose I know the total size of the memory and will not go out of bounds?
If anyone can shed some light on any of these topics I would greatly appreciate it!
Thanks!