More fixes for Vulkan rendering to be on pair with DirectX when it comes to accessing missing vertex buffer components

This commit is contained in:
Wojtek Figat
2025-01-09 21:46:22 +01:00
parent 3505b8971b
commit 99788e4743
7 changed files with 54 additions and 24 deletions

View File

@@ -96,12 +96,12 @@ GPUVertexLayout::GPUVertexLayout()
void GPUVertexLayout::SetElements(const Elements& elements, bool explicitOffsets)
{
uint32 offsets[GPU_MAX_VB_BINDED] = {};
uint32 offsets[GPU_MAX_VB_BINDED + 1] = {};
_elements = elements;
for (int32 i = 0; i < _elements.Count(); i++)
{
VertexElement& e = _elements[i];
ASSERT(e.Slot < GPU_MAX_VB_BINDED);
ASSERT(e.Slot <= GPU_MAX_VB_BINDED); // One special slot after all VBs for any missing vertex elements binding (on Vulkan)
uint32& offset = offsets[e.Slot];
if (e.Offset != 0 || explicitOffsets)
offset = e.Offset;
@@ -216,7 +216,7 @@ GPUVertexLayout* GPUVertexLayout::Get(const Span<GPUVertexLayout*>& layouts)
return result;
}
GPUVertexLayout* GPUVertexLayout::Merge(GPUVertexLayout* base, GPUVertexLayout* reference, bool removeUnused, bool addMissing)
GPUVertexLayout* GPUVertexLayout::Merge(GPUVertexLayout* base, GPUVertexLayout* reference, bool removeUnused, bool addMissing, int32 missingSlotOverride)
{
GPUVertexLayout* result = base ? base : reference;
if (base && reference && base != reference)
@@ -261,7 +261,7 @@ GPUVertexLayout* GPUVertexLayout::Merge(GPUVertexLayout* base, GPUVertexLayout*
if (missing)
{
// Insert any missing elements
VertexElement ne = { e.Type, e.Slot, 0, e.PerInstance, e.Format };
VertexElement ne = { e.Type, missingSlotOverride != -1 ? (byte)missingSlotOverride : e.Slot, 0, e.PerInstance, e.Format };
if (e.Type == VertexElement::Types::TexCoord1 || e.Type == VertexElement::Types::TexCoord2 || e.Type == VertexElement::Types::TexCoord3)
{
// Alias missing texcoords with existing texcoords

View File

@@ -83,8 +83,9 @@ public:
/// <param name="reference">The list of reference inputs.</param>
/// <param name="removeUnused">True to remove elements from base layout that don't exist in a reference layout.</param>
/// <param name="addMissing">True to add missing elements to base layout that exist in a reference layout.</param>
/// <param name="missingSlotOverride">Allows to override the input slot for missing elements. Use value -1 to inherit slot from the reference layout.</param>
/// <returns>Vertex layout object. Doesn't need to be cleared as it's cached for an application lifetime.</returns>
static GPUVertexLayout* Merge(GPUVertexLayout* base, GPUVertexLayout* reference, bool removeUnused = false, bool addMissing = true);
static GPUVertexLayout* Merge(GPUVertexLayout* base, GPUVertexLayout* reference, bool removeUnused = false, bool addMissing = true, int32 missingSlotOverride = -1);
public:
// [GPUResource]