Refactor Vertex Shader input vertex layout to use GPUVertexLayout defined on Vertex Buffer rather than Vertex Shader

#3044 #2667
This commit is contained in:
Wojtek Figat
2024-12-15 22:10:45 +01:00
parent 666efb7675
commit b3f37ca041
66 changed files with 786 additions and 579 deletions

View File

@@ -5,6 +5,7 @@
#if GRAPHICS_API_DIRECTX12
#include "GPUDeviceDX12.h"
#include "Engine/Core/Types/DataContainer.h"
#include "Engine/Graphics/Shaders/GPUShaderProgram.h"
#include "Types.h"
#include "../IncludeDirectXHeaders.h"
@@ -15,30 +16,27 @@
template<typename BaseType>
class GPUShaderProgramDX12 : public BaseType
{
protected:
Array<byte> _data;
public:
GPUShaderProgramDX12(const GPUShaderProgramInitializer& initializer, DxShaderHeader* header, byte* cacheBytes, uint32 cacheSize)
GPUShaderProgramDX12(const GPUShaderProgramInitializer& initializer, const DxShaderHeader* header, Span<byte> bytecode)
: Header(*header)
{
BaseType::Init(initializer);
_data.Set(cacheBytes, cacheSize);
Bytecode.Copy(bytecode);
}
public:
BytesContainer Bytecode;
DxShaderHeader Header;
public:
// [BaseType]
void* GetBufferHandle() const override
{
return (void*)_data.Get();
return (void*)Bytecode.Get();
}
uint32 GetBufferSize() const override
{
return _data.Count();
return Bytecode.Length();
}
};
@@ -47,29 +45,11 @@ public:
/// </summary>
class GPUShaderProgramVSDX12 : public GPUShaderProgramDX12<GPUShaderProgramVS>
{
private:
byte _inputLayoutSize;
D3D12_INPUT_ELEMENT_DESC _inputLayout[VERTEX_SHADER_MAX_INPUT_ELEMENTS];
public:
GPUShaderProgramVSDX12(const GPUShaderProgramInitializer& initializer, DxShaderHeader* header, byte* cacheBytes, uint32 cacheSize, D3D12_INPUT_ELEMENT_DESC* inputLayout, byte inputLayoutSize)
: GPUShaderProgramDX12(initializer, header, cacheBytes, cacheSize)
, _inputLayoutSize(inputLayoutSize)
GPUShaderProgramVSDX12(const GPUShaderProgramInitializer& initializer, const DxShaderHeader* header, Span<byte> bytecode, GPUVertexLayout* vertexLayout)
: GPUShaderProgramDX12(initializer, header, bytecode)
{
for (byte i = 0; i < inputLayoutSize; i++)
_inputLayout[i] = inputLayout[i];
}
public:
// [GPUShaderProgramDX12]
void* GetInputLayout() const override
{
return (void*)_inputLayout;
}
byte GetInputLayoutSize() const override
{
return _inputLayoutSize;
Layout = vertexLayout;
}
};
@@ -80,8 +60,8 @@ public:
class GPUShaderProgramHSDX12 : public GPUShaderProgramDX12<GPUShaderProgramHS>
{
public:
GPUShaderProgramHSDX12(const GPUShaderProgramInitializer& initializer, DxShaderHeader* header, byte* cacheBytes, uint32 cacheSize, int32 controlPointsCount)
: GPUShaderProgramDX12(initializer, header, cacheBytes, cacheSize)
GPUShaderProgramHSDX12(const GPUShaderProgramInitializer& initializer, const DxShaderHeader* header, Span<byte> bytecode, int32 controlPointsCount)
: GPUShaderProgramDX12(initializer, header, bytecode)
{
_controlPointsCount = controlPointsCount;
}
@@ -93,8 +73,8 @@ public:
class GPUShaderProgramDSDX12 : public GPUShaderProgramDX12<GPUShaderProgramDS>
{
public:
GPUShaderProgramDSDX12(const GPUShaderProgramInitializer& initializer, DxShaderHeader* header, byte* cacheBytes, uint32 cacheSize)
: GPUShaderProgramDX12(initializer, header, cacheBytes, cacheSize)
GPUShaderProgramDSDX12(const GPUShaderProgramInitializer& initializer, const DxShaderHeader* header, Span<byte> bytecode)
: GPUShaderProgramDX12(initializer, header, bytecode)
{
}
};
@@ -107,8 +87,8 @@ public:
class GPUShaderProgramGSDX12 : public GPUShaderProgramDX12<GPUShaderProgramGS>
{
public:
GPUShaderProgramGSDX12(const GPUShaderProgramInitializer& initializer, DxShaderHeader* header, byte* cacheBytes, uint32 cacheSize)
: GPUShaderProgramDX12(initializer, header, cacheBytes, cacheSize)
GPUShaderProgramGSDX12(const GPUShaderProgramInitializer& initializer, const DxShaderHeader* header, Span<byte> bytecode)
: GPUShaderProgramDX12(initializer, header, bytecode)
{
}
};
@@ -120,8 +100,8 @@ public:
class GPUShaderProgramPSDX12 : public GPUShaderProgramDX12<GPUShaderProgramPS>
{
public:
GPUShaderProgramPSDX12(const GPUShaderProgramInitializer& initializer, DxShaderHeader* header, byte* cacheBytes, uint32 cacheSize)
: GPUShaderProgramDX12(initializer, header, cacheBytes, cacheSize)
GPUShaderProgramPSDX12(const GPUShaderProgramInitializer& initializer, const DxShaderHeader* header, Span<byte> bytecode)
: GPUShaderProgramDX12(initializer, header, bytecode)
{
}
};
@@ -137,8 +117,8 @@ private:
ID3D12PipelineState* _state;
public:
GPUShaderProgramCSDX12(GPUDeviceDX12* device, const GPUShaderProgramInitializer& initializer, DxShaderHeader* header, byte* cacheBytes, uint32 cacheSize)
: GPUShaderProgramDX12(initializer, header, cacheBytes, cacheSize)
GPUShaderProgramCSDX12(GPUDeviceDX12* device, const GPUShaderProgramInitializer& initializer, const DxShaderHeader* header, Span<byte> bytecode)
: GPUShaderProgramDX12(initializer, header, bytecode)
, _device(device)
, _state(nullptr)
{