🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

I have an issue with directx 11 RWStructuredBuffer

Started by
0 comments, last by andrey4 3 days, 11 hours ago

I am figuring out with GPU voxelization. I decided to write a simple hlsl shader but I have already had a problem on the first stage. I use RWStructuredBuffer for storing voxels. The shader code is compiled without erros, I debug the shader and the shader writes a voxel with data in RWStructuredBuffer but after calling a voxelization pipeline still there are no voxels in RWStructuredBuffer. I change my code and I specify first index instead of na arbitrary index in RWStructuredBuffer and after calling the voxelization pipeline I have a note in RWStructuredBuffer by first index. I don't understand why it not works with an arbitrary index.


struct Voxel {
	uint encoded_color;
	uint occlusion;
};
RWStructuredBuffer<Voxel> voxels : register(u1);

float4 ps_main(Vertex_Out vertex_output) : SV_TARGET
{
    float3 color = diffuse_texture.Sample(linear_sampling, vertex_output.uv).rgb;
    int3 voxel_position;
    voxel_position.x = (int)floor((float)voxel_grid_width * (vertex_output.position.x / (float)(voxel_grid_width * voxel_grid_ceil_width)));
    voxel_position.y = (int)floor((float)voxel_grid_height * (vertex_output.position.y / (float)(voxel_grid_height * voxel_grid_ceil_height)));
    voxel_position.z = (int)floor((float)voxel_grid_depth * vertex_output.position.z);
    
    uint voxel_index = voxel_position.x + voxel_grid_width * (voxel_position.y + voxel_grid_depth * voxel_position.z);
    InterlockedMax(voxels[voxel_index].encoded_color, pack_RGB(color));
    InterlockedMax(voxels[voxel_index].occlusion, uint(1));
    //InterlockedMax(0].encoded_color, pack_RGB(color));
    //InterlockedMax(0].occlusion, uint(1));
    
    return float4(color, 1.0f);
}
Advertisement