-
Notifications
You must be signed in to change notification settings - Fork 1
/
dxutils.cpp
92 lines (66 loc) · 3.06 KB
/
dxutils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "dxutils.hpp"
#include <vector>
namespace tdx
{
const char * detail::ShaderHelper<ID3D11VertexShader>::target = "vs_5_0";
const char * detail::ShaderHelper<ID3D11PixelShader>::target = "ps_5_0";
const char * detail::ShaderHelper<ID3D11GeometryShader>::target = "gs_5_0";
const char * detail::ShaderHelper<ID3D11ComputeShader>::target = "cs_5_0";
static inline DXGI_FORMAT GetDXGIFormat(D3D_REGISTER_COMPONENT_TYPE componentType, BYTE mask)
{
DXGI_FORMAT format;
if (mask == 1)
{
if (componentType == D3D_REGISTER_COMPONENT_UINT32) format = DXGI_FORMAT_R32_UINT;
else if (componentType == D3D_REGISTER_COMPONENT_SINT32) format = DXGI_FORMAT_R32_SINT;
else if (componentType == D3D_REGISTER_COMPONENT_FLOAT32) format = DXGI_FORMAT_R32_FLOAT;
}
else if (mask <= 3)
{
if (componentType == D3D_REGISTER_COMPONENT_UINT32) format = DXGI_FORMAT_R32G32_UINT;
else if (componentType == D3D_REGISTER_COMPONENT_SINT32) format = DXGI_FORMAT_R32G32_SINT;
else if (componentType == D3D_REGISTER_COMPONENT_FLOAT32) format = DXGI_FORMAT_R32G32_FLOAT;
}
else if (mask <= 7)
{
if (componentType == D3D_REGISTER_COMPONENT_UINT32) format = DXGI_FORMAT_R32G32B32_UINT;
else if (componentType == D3D_REGISTER_COMPONENT_SINT32) format = DXGI_FORMAT_R32G32B32_SINT;
else if (componentType == D3D_REGISTER_COMPONENT_FLOAT32) format = DXGI_FORMAT_R32G32B32_FLOAT;
}
else if (mask <= 15)
{
if (componentType == D3D_REGISTER_COMPONENT_UINT32) format = DXGI_FORMAT_R32G32B32A32_UINT;
else if (componentType == D3D_REGISTER_COMPONENT_SINT32) format = DXGI_FORMAT_R32G32B32A32_SINT;
else if (componentType == D3D_REGISTER_COMPONENT_FLOAT32) format = DXGI_FORMAT_R32G32B32A32_FLOAT;
}
return format;
}
ID3D11InputLayout * CreateVSInputLayout(ID3D11Device * device, ID3D11VertexShader * shader, ID3DBlob * code)
{
ID3D11InputLayout * inputLayout = nullptr;
ID3D11ShaderReflection * reflection;
if (!FAILED(D3DReflect(code->GetBufferPointer(), code->GetBufferSize(), IID_ID3D11ShaderReflection, (void **) &reflection)))
{
D3D11_SHADER_DESC shaderDesc;
reflection->GetDesc(&shaderDesc);
std::vector<D3D11_INPUT_ELEMENT_DESC> elements;
for (int i = 0; i < shaderDesc.InputParameters; i++)
{
D3D11_SIGNATURE_PARAMETER_DESC inputParamDesc;
reflection->GetInputParameterDesc(i, &inputParamDesc);
D3D11_INPUT_ELEMENT_DESC elementDesc;
elementDesc.SemanticName = inputParamDesc.SemanticName;
elementDesc.SemanticIndex = inputParamDesc.SemanticIndex;
elementDesc.InputSlot = 0;
elementDesc.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
elementDesc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
elementDesc.InstanceDataStepRate = 0;
elementDesc.Format = GetDXGIFormat(inputParamDesc.ComponentType, inputParamDesc.Mask);
elements.push_back(elementDesc);
}
HRESULT hr = device->CreateInputLayout(&elements[0], elements.size(), code->GetBufferPointer(), code->GetBufferSize(), &inputLayout);
reflection->Release();
}
return inputLayout;
}
}