Fixes for Vulkan backend after recent changes

This commit is contained in:
Wojtek Figat
2025-01-08 18:09:45 +01:00
parent 7e165d6127
commit 2b2ace0d00
7 changed files with 127 additions and 71 deletions

View File

@@ -206,47 +206,71 @@ GPUVertexLayout* GPUVertexLayout::Get(const Span<GPUVertexLayout*>& layouts)
return result;
}
GPUVertexLayout* GPUVertexLayout::Merge(GPUVertexLayout* base, GPUVertexLayout* reference)
GPUVertexLayout* GPUVertexLayout::Merge(GPUVertexLayout* base, GPUVertexLayout* reference, bool removeUnused, bool addMissing)
{
GPUVertexLayout* result = base ? base : reference;
if (base && reference && base != reference)
{
bool anyMissing = false;
const Elements& baseElements = base->GetElements();
Elements newElements = baseElements;
for (const VertexElement& e : reference->GetElements())
bool elementsModified = false;
Elements newElements = base->GetElements();
if (removeUnused)
{
bool missing = true;
for (const VertexElement& ee : baseElements)
for (int32 i = newElements.Count() - 1; i >= 0; i--)
{
if (ee.Type == e.Type)
bool missing = true;
const VertexElement& e = newElements.Get()[i];
for (const VertexElement& ee : reference->GetElements())
{
missing = false;
break;
}
}
if (missing)
{
// Insert any missing elements
VertexElement ne = { e.Type, 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
for (const VertexElement& ee : newElements)
if (ee.Type == e.Type)
{
if (ee.Type == VertexElement::Types::TexCoord0)
{
ne = ee;
ne.Type = e.Type;
break;
}
missing = false;
break;
}
}
newElements.Add(ne);
anyMissing = true;
if (missing)
{
// Remove unused element
newElements.RemoveAtKeepOrder(i);
elementsModified = true;
}
}
}
if (anyMissing)
if (addMissing)
{
for (const VertexElement& e : reference->GetElements())
{
bool missing = true;
for (const VertexElement& ee : base->GetElements())
{
if (ee.Type == e.Type)
{
missing = false;
break;
}
}
if (missing)
{
// Insert any missing elements
VertexElement ne = { e.Type, 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
for (const VertexElement& ee : newElements)
{
if (ee.Type == VertexElement::Types::TexCoord0)
{
ne = ee;
ne.Type = e.Type;
break;
}
}
}
newElements.Add(ne);
elementsModified = true;
}
}
}
if (elementsModified)
result = Get(newElements, true);
}
return result;

View File

@@ -74,8 +74,10 @@ public:
/// </summary>
/// <param name="base">The list of vertex buffers for the layout.</param>
/// <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>
/// <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);
static GPUVertexLayout* Merge(GPUVertexLayout* base, GPUVertexLayout* reference, bool removeUnused = false, bool addMissing = true);
public:
// [GPUResource]