forked from Misaki/GhostEngine
Refactor and enhance codebase for maintainability
Refactored and reorganized the codebase to improve readability, performance, and maintainability. Introduced new interfaces and structs for better resource management, updated project configuration files, and refactored shader and graphics pipeline management. Improved error handling, code formatting, and removed unused code and namespaces. Updated DLL references and method signatures for consistency and maintainability.
This commit is contained in:
@@ -28,38 +28,43 @@ struct PixelInput
|
||||
float4 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
// Bindless vertex shader that fetches vertex data from bindless buffers
|
||||
PixelInput VSMain(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID)
|
||||
[NumThreads(3, 1, 1)] // 3 threads per triangle
|
||||
[OutputTopology("triangle")]
|
||||
void MSMain(
|
||||
uint3 groupThreadID : SV_GroupThreadID,
|
||||
uint groupID : SV_GroupID,
|
||||
out vertices PixelInput outVerts[3],
|
||||
out indices uint3 outTris[1])
|
||||
{
|
||||
// Get bindless buffers
|
||||
// Fetch bindless buffers
|
||||
ByteAddressBuffer vertexBuffer = ResourceDescriptorHeap[_VertexBufferIndex];
|
||||
ByteAddressBuffer indexBuffer = ResourceDescriptorHeap[_IndexBufferIndex];
|
||||
|
||||
// For fully bindless rendering, we use instanced drawing where:
|
||||
// - Each instance represents a triangle (instanceId = triangle index)
|
||||
// - vertexId goes from 0 to 2 (the 3 vertices of the triangle)
|
||||
|
||||
// Calculate the index into the index buffer
|
||||
uint indexOffset = (instanceId * 3 + vertexId) * 4; // 4 bytes per index (uint32)
|
||||
|
||||
// Compute the triangle’s vertex indices
|
||||
uint vertexId = groupThreadID.x;
|
||||
uint indexOffset = (groupID.x * 3 + vertexId) * 4; // uint32 index
|
||||
uint vertexIndex = indexBuffer.Load(indexOffset);
|
||||
|
||||
// Calculate the offset into the vertex buffer
|
||||
uint vertexOffset = vertexIndex * 80; // 80 bytes per vertex (5 * float4)
|
||||
|
||||
// Load vertex data from bindless vertex buffer
|
||||
Vertex vertex;
|
||||
vertex.position = asfloat(vertexBuffer.Load4(vertexOffset + 0));
|
||||
vertex.normal = asfloat(vertexBuffer.Load4(vertexOffset + 16));
|
||||
vertex.tangent = asfloat(vertexBuffer.Load4(vertexOffset + 32));
|
||||
vertex.color = asfloat(vertexBuffer.Load4(vertexOffset + 48));
|
||||
vertex.uv = asfloat(vertexBuffer.Load4(vertexOffset + 64));
|
||||
|
||||
// Output transformed vertex
|
||||
PixelInput output;
|
||||
output.position = vertex.position;
|
||||
output.color = vertex.color;
|
||||
output.uv = vertex.uv;
|
||||
return output;
|
||||
|
||||
// Load vertex attributes
|
||||
uint vertexOffset = vertexIndex * 80; // 80 bytes per vertex
|
||||
Vertex v;
|
||||
v.position = asfloat(vertexBuffer.Load4(vertexOffset + 0));
|
||||
v.normal = asfloat(vertexBuffer.Load4(vertexOffset + 16));
|
||||
v.tangent = asfloat(vertexBuffer.Load4(vertexOffset + 32));
|
||||
v.color = asfloat(vertexBuffer.Load4(vertexOffset + 48));
|
||||
v.uv = asfloat(vertexBuffer.Load4(vertexOffset + 64));
|
||||
|
||||
// Write vertex output
|
||||
outVerts[vertexId].position = v.position;
|
||||
outVerts[vertexId].color = v.color;
|
||||
outVerts[vertexId].uv = v.uv;
|
||||
|
||||
// Thread 0 defines topology
|
||||
if (vertexId == 0)
|
||||
{
|
||||
SetMeshOutputCounts(3, 1);
|
||||
outTris[0] = uint3(0, 1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
float4 PSMain(PixelInput input) : SV_TARGET
|
||||
|
||||
Reference in New Issue
Block a user