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:
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "ShaderCompilerDX.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
#include "Engine/Engine/Globals.h"
|
||||
#include "Engine/Graphics/Config.h"
|
||||
#include "Engine/GraphicsDevice/DirectX/DX12/Types.h"
|
||||
@@ -22,12 +21,10 @@
|
||||
class IncludeDX : public IDxcIncludeHandler
|
||||
{
|
||||
private:
|
||||
|
||||
ShaderCompilationContext* _context;
|
||||
IDxcLibrary* _library;
|
||||
|
||||
public:
|
||||
|
||||
IncludeDX(ShaderCompilationContext* context, IDxcLibrary* library)
|
||||
{
|
||||
_context = context;
|
||||
@@ -185,6 +182,7 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
|
||||
}
|
||||
|
||||
// Compile all shader function permutations
|
||||
AdditionalDataVS additionalDataVS;
|
||||
for (int32 permutationIndex = 0; permutationIndex < meta.Permutations.Count(); permutationIndex++)
|
||||
{
|
||||
_macros.Clear();
|
||||
@@ -320,6 +318,54 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
|
||||
shaderReflection->GetDesc(&desc);
|
||||
|
||||
// Process shader reflection data
|
||||
void* additionalData = nullptr;
|
||||
if (type == ShaderStage::Vertex)
|
||||
{
|
||||
additionalData = &additionalDataVS;
|
||||
additionalDataVS.Inputs.Clear();
|
||||
for (UINT inputIdx = 0; inputIdx < desc.InputParameters; inputIdx++)
|
||||
{
|
||||
D3D12_SIGNATURE_PARAMETER_DESC inputDesc;
|
||||
shaderReflection->GetInputParameterDesc(inputIdx, &inputDesc);
|
||||
if (inputDesc.ReadWriteMask == 0 || inputDesc.SystemValueType != D3D10_NAME_UNDEFINED)
|
||||
continue;
|
||||
auto format = PixelFormat::Unknown;
|
||||
switch (inputDesc.ComponentType)
|
||||
{
|
||||
case D3D_REGISTER_COMPONENT_UINT32:
|
||||
if (inputDesc.Mask >= 0b1111)
|
||||
format = PixelFormat::R32G32B32A32_UInt;
|
||||
else if (inputDesc.Mask >= 0b111)
|
||||
format = PixelFormat::R32G32B32_UInt;
|
||||
else if (inputDesc.Mask >= 0b11)
|
||||
format = PixelFormat::R32G32_UInt;
|
||||
else
|
||||
format = PixelFormat::R32_UInt;
|
||||
break;
|
||||
case D3D_REGISTER_COMPONENT_SINT32:
|
||||
if (inputDesc.Mask >= 0b1111)
|
||||
format = PixelFormat::R32G32B32A32_SInt;
|
||||
else if (inputDesc.Mask >= 0b111)
|
||||
format = PixelFormat::R32G32B32_SInt;
|
||||
else if (inputDesc.Mask >= 0b11)
|
||||
format = PixelFormat::R32G32_SInt;
|
||||
else
|
||||
format = PixelFormat::R32_SInt;
|
||||
break;
|
||||
case D3D_REGISTER_COMPONENT_FLOAT32:
|
||||
if (inputDesc.Mask >= 0b1111)
|
||||
format = PixelFormat::R32G32B32A32_Float;
|
||||
else if (inputDesc.Mask >= 0b111)
|
||||
format = PixelFormat::R32G32B32_Float;
|
||||
else if (inputDesc.Mask >= 0b11)
|
||||
format = PixelFormat::R32G32_Float;
|
||||
else
|
||||
format = PixelFormat::R32_Float;
|
||||
break;
|
||||
}
|
||||
additionalDataVS.Inputs.Add({ ParseVertexElementType(inputDesc.SemanticName, inputDesc.SemanticIndex), 0, 0, 0, format });
|
||||
}
|
||||
}
|
||||
DxShaderHeader header;
|
||||
Platform::MemoryClear(&header, sizeof(header));
|
||||
ShaderBindings bindings = { desc.InstructionCount, 0, 0, 0 };
|
||||
@@ -370,16 +416,16 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
|
||||
shaderReflection->GetResourceBindingDesc(i, &resDesc);
|
||||
switch (resDesc.Type)
|
||||
{
|
||||
// Sampler
|
||||
// Sampler
|
||||
case D3D_SIT_SAMPLER:
|
||||
break;
|
||||
|
||||
// Constant Buffer
|
||||
// Constant Buffer
|
||||
case D3D_SIT_CBUFFER:
|
||||
case D3D_SIT_TBUFFER:
|
||||
break;
|
||||
|
||||
// Shader Resource
|
||||
// Shader Resource
|
||||
case D3D_SIT_TEXTURE:
|
||||
for (UINT shift = 0; shift < resDesc.BindCount; shift++)
|
||||
{
|
||||
@@ -396,7 +442,7 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
|
||||
}
|
||||
break;
|
||||
|
||||
// Unordered Access
|
||||
// Unordered Access
|
||||
case D3D_SIT_UAV_RWTYPED:
|
||||
case D3D_SIT_UAV_RWSTRUCTURED:
|
||||
case D3D_SIT_UAV_RWBYTEADDRESS:
|
||||
@@ -415,7 +461,7 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
|
||||
if (WriteShaderFunctionPermutation(_context, meta, permutationIndex, bindings, &header, sizeof(header), shaderBuffer->GetBufferPointer(), (int32)shaderBuffer->GetBufferSize()))
|
||||
return true;
|
||||
|
||||
if (customDataWrite && customDataWrite(_context, meta, permutationIndex, _macros))
|
||||
if (customDataWrite && customDataWrite(_context, meta, permutationIndex, _macros, additionalData))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user