Add vertex shader input layout reading via shader compiler reflection to handle missing vertex elements binding when explicit layout got deprecated

This commit is contained in:
Wojtek Figat
2025-01-07 23:26:06 +01:00
parent 7f0d852f49
commit 7aa240e5eb
20 changed files with 350 additions and 232 deletions

View File

@@ -177,22 +177,28 @@ GPUShaderProgram* GPUShader::GetShader(ShaderStage stage, const StringAnsiView&
return shader;
}
GPUVertexLayout* GPUShader::ReadVertexLayout(MemoryReadStream& stream)
void GPUShader::ReadVertexLayout(MemoryReadStream& stream, GPUVertexLayout*& inputLayout, GPUVertexLayout*& vertexLayout)
{
inputLayout = vertexLayout = nullptr;
// Read input layout (based on shader reflection)
GPUVertexLayout::Elements elements;
stream.Read(elements);
inputLayout = GPUVertexLayout::Get(elements);
// [Deprecated in v1.10]
byte inputLayoutSize;
stream.ReadByte(&inputLayoutSize);
if (inputLayoutSize == 0)
return nullptr;
return;
void* elementsData = stream.Move(sizeof(VertexElement) * inputLayoutSize);
if (inputLayoutSize > GPU_MAX_VS_ELEMENTS)
{
LOG(Error, "Incorrect input layout size.");
return nullptr;
return;
}
GPUVertexLayout::Elements elements;
elements.Set((VertexElement*)elementsData, inputLayoutSize);
return GPUVertexLayout::Get(elements);
vertexLayout = GPUVertexLayout::Get(elements);
}
GPUResourceType GPUShader::GetResourceType() const