-
Notifications
You must be signed in to change notification settings - Fork 4
/
DXShader.cpp
66 lines (49 loc) · 1.4 KB
/
DXShader.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
#include "DXShader.h"
#include <d3dcompiler.h>
HRESULT CompileComputeShader(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint,
_In_ ID3D11Device* device, _Outptr_ ID3DBlob** blob)
{
if (!srcFile || !entryPoint || !device || !blob)
return E_INVALIDARG;
*blob = nullptr;
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
flags |= D3DCOMPILE_DEBUG;
#endif
// We generally prefer to use the higher CS shader profile when possible as CS 5.0 is better performance on 11-class hardware
LPCSTR profile = (device->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0) ? "cs_5_0" : "cs_4_0";
const D3D_SHADER_MACRO defines[] =
{
"EXAMPLE_DEFINE", "1",
NULL, NULL
};
ID3DBlob* shaderBlob = nullptr;
ID3DBlob* errorBlob = nullptr;
HRESULT hr = D3DCompileFromFile(srcFile, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE,
entryPoint, profile,
flags, 0, &shaderBlob, &errorBlob);
if (FAILED(hr))
{
if (errorBlob)
{
OutputDebugStringA((char*) errorBlob->GetBufferPointer());
errorBlob->Release();
}
if (shaderBlob)
shaderBlob->Release();
return hr;
}
*blob = shaderBlob;
return hr;
}
DXShader::DXShader(ID3D11Device* device, const BYTE* bytecode, unsigned int size)
{
HRESULT hr = device->CreateComputeShader(bytecode, size, NULL, &(this->shader));
if (hr != S_OK) throw 1;
}
DXShader::~DXShader()
{
}
ID3D11ComputeShader* DXShader::getShader() {
return this->shader;
}