Hi everybody!
I'm trying to copy one vertex buffer to another vertex buffer in compute shader.
This is a first step to then add more vertex processing once the copy is working properly.
The copy is from a vertex buffer containing skinning data to another vertex buffer without skinning data.
Here the entire compute shader:
struct SourceVertex
{
float3 Position;
float3 Normal;
float2 TexCoord;
float4 Tangent;
float4 Weights;
uint4 Indices;
};
struct OutputVertex
{
float3 Position;
float3 Normal;
float2 TexCoord;
float4 Tangent;
};
RWByteAddressBuffer OutputVertexBuffer : register(u0);
ByteAddressBuffer VertexBuffer : register(t0);
[numthreads(1, 1, 1)]
void main(in uint3 dispatchThreadID : SV_DispatchThreadID)
{
// Load the current vertex.
uint SourceByteOffset = dispatchThreadID.x * sizeof(SourceVertex);
SourceVertex CurrentVertex = VertexBuffer.Load<SourceVertex>(SourceByteOffset);
// Set the output current vertex.
OutputVertex OutputCurrentVertex;
OutputCurrentVertex.Position = CurrentVertex.Position;
OutputCurrentVertex.Normal = CurrentVertex.Normal;
OutputCurrentVertex.TexCoord = CurrentVertex.TexCoord;
OutputCurrentVertex.Tangent = CurrentVertex.Tangent;
// Store the output current vertex.
uint OutputByteOffset = dispatchThreadID.x * sizeof(OutputVertex);
OutputVertexBuffer.Store(OutputByteOffset, OutputCurrentVertex);
}
I create the SRV and UVA using DXGI_FORMAT_R32_TYPELESS with bufferSize / 4 for NumElements.
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Buffer.FirstElement = 0;
srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
srvDesc.Buffer.NumElements = size / 4;
srvDesc.Buffer.StructureByteStride = 0;
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc;
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
uavDesc.Buffer.CounterOffsetInBytes = 0;
uavDesc.Buffer.FirstElement = 0;
uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
uavDesc.Buffer.NumElements = size / 4;
uavDesc.Buffer.StructureByteStride = 0;
Without dispatching the compute shader, using just the initially created copied buffer, it's all fine, but once the compute shader is dispatched to simply copy the whole data from one vertex buffer to another the result is not good anymore.
Thank you for your help!