forked from doitsujin/dxvk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd3d11_shader.h
158 lines (117 loc) · 3.88 KB
/
d3d11_shader.h
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#pragma once
#include <mutex>
#include <unordered_map>
#include "../dxbc/dxbc_module.h"
#include "../dxvk/dxvk_device.h"
#include "../d3d10/d3d10_shader.h"
#include "../util/sha1/sha1_util.h"
#include "../util/util_env.h"
#include "d3d11_device_child.h"
#include "d3d11_interfaces.h"
namespace dxvk {
class D3D11Device;
/**
* \brief Common shader object
*
* Stores the compiled SPIR-V shader and the SHA-1
* hash of the original DXBC shader, which can be
* used to identify the shader.
*/
class D3D11CommonShader {
public:
D3D11CommonShader();
D3D11CommonShader(
D3D11Device* pDevice,
const DxvkShaderKey* pShaderKey,
const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode,
size_t BytecodeLength);
~D3D11CommonShader();
Rc<DxvkShader> GetShader() const {
return m_shader;
}
Rc<DxvkBuffer> GetIcb() const {
return m_buffer;
}
std::string GetName() const {
return m_shader->debugName();
}
private:
Rc<DxvkShader> m_shader;
Rc<DxvkBuffer> m_buffer;
};
/**
* \brief Common shader interface
*
* Implements methods for all D3D11*Shader
* interfaces and stores the actual shader
* module object.
*/
template<typename D3D11Interface, typename D3D10Interface>
class D3D11Shader : public D3D11DeviceChild<D3D11Interface> {
using D3D10ShaderClass = D3D10Shader<D3D10Interface, D3D11Interface>;
public:
D3D11Shader(D3D11Device* device, const D3D11CommonShader& shader)
: D3D11DeviceChild<D3D11Interface>(device),
m_shader(shader), m_d3d10(this) { }
~D3D11Shader() { }
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) final {
*ppvObject = nullptr;
if (riid == __uuidof(IUnknown)
|| riid == __uuidof(ID3D11DeviceChild)
|| riid == __uuidof(D3D11Interface)) {
*ppvObject = ref(this);
return S_OK;
}
if (riid == __uuidof(IUnknown)
|| riid == __uuidof(ID3D10DeviceChild)
|| riid == __uuidof(D3D10Interface)) {
*ppvObject = ref(&m_d3d10);
return S_OK;
}
Logger::warn("D3D11Shader::QueryInterface: Unknown interface query");
return E_NOINTERFACE;
}
const D3D11CommonShader* GetCommonShader() const {
return &m_shader;
}
D3D10ShaderClass* GetD3D10Iface() {
return &m_d3d10;
}
private:
D3D11CommonShader m_shader;
D3D10ShaderClass m_d3d10;
};
using D3D11VertexShader = D3D11Shader<ID3D11VertexShader, ID3D10VertexShader>;
using D3D11HullShader = D3D11Shader<ID3D11HullShader, ID3D10DeviceChild>;
using D3D11DomainShader = D3D11Shader<ID3D11DomainShader, ID3D10DeviceChild>;
using D3D11GeometryShader = D3D11Shader<ID3D11GeometryShader, ID3D10GeometryShader>;
using D3D11PixelShader = D3D11Shader<ID3D11PixelShader, ID3D10PixelShader>;
using D3D11ComputeShader = D3D11Shader<ID3D11ComputeShader, ID3D10DeviceChild>;
/**
* \brief Shader module set
*
* Some applications may compile the same shader multiple
* times, so we should cache the resulting shader modules
* and reuse them rather than creating new ones. This
* class is thread-safe.
*/
class D3D11ShaderModuleSet {
public:
D3D11ShaderModuleSet();
~D3D11ShaderModuleSet();
HRESULT GetShaderModule(
D3D11Device* pDevice,
const DxvkShaderKey* pShaderKey,
const DxbcModuleInfo* pDxbcModuleInfo,
const void* pShaderBytecode,
size_t BytecodeLength,
D3D11CommonShader* pShader);
private:
dxvk::mutex m_mutex;
std::unordered_map<
DxvkShaderKey,
D3D11CommonShader,
DxvkHash, DxvkEq> m_modules;
};
}