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

View File

@@ -12,7 +12,7 @@ class GPUShaderProgram;
/// <summary>
/// The runtime version of the shaders cache supported by the all graphics back-ends. The same for all the shader cache formats (easier to sync and validate).
/// </summary>
#define GPU_SHADER_CACHE_VERSION 11
#define GPU_SHADER_CACHE_VERSION 12
/// <summary>
/// The GPU resource with shader programs that can run on the GPU and are able to perform rendering calculation using textures, vertices and other resources.
@@ -135,7 +135,7 @@ public:
protected:
GPUShaderProgram* GetShader(ShaderStage stage, const StringAnsiView& name, int32 permutationIndex) const;
virtual GPUShaderProgram* CreateGPUShaderProgram(ShaderStage type, const GPUShaderProgramInitializer& initializer, Span<byte> bytecode, MemoryReadStream& stream) = 0;
static GPUVertexLayout* ReadVertexLayout(MemoryReadStream& stream);
static void ReadVertexLayout(MemoryReadStream& stream, GPUVertexLayout*& inputLayout, GPUVertexLayout*& vertexLayout);
public:
// [GPUResource]

View File

@@ -136,6 +136,9 @@ public:
// [Deprecated in v1.10]
GPUVertexLayout* Layout = nullptr;
// Vertex shader inputs layout. Used to ensure that binded vertex buffers provide all required elements.
GPUVertexLayout* InputLayout = nullptr;
public:
// [GPUShaderProgram]
ShaderStage GetStage() const override