GteDX11ComputeShader.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 using namespace gte;
11 
12 DX11ComputeShader::DX11ComputeShader(ID3D11Device* device, Shader const* shader)
13  :
14  DX11Shader(shader)
15 {
16  std::vector<unsigned char> const& code = shader->GetCompiledCode();
17 
18  ID3D11ClassLinkage* linkage = nullptr;
19  ID3D11ComputeShader* dxShader = nullptr;
20  HRESULT hr = device->CreateComputeShader(&code[0], code.size(), linkage, &dxShader);
21  CHECK_HR_RETURN_NONE("Failed to create compute shader");
22 
23  mDXObject = dxShader;
24 }
25 
26 std::shared_ptr<GEObject> DX11ComputeShader::Create(void* device, GraphicsObject const* object)
27 {
28  if (object->GetType() == GT_COMPUTE_SHADER)
29  {
30  return std::make_shared<DX11ComputeShader>(
31  reinterpret_cast<ID3D11Device*>(device),
32  static_cast<Shader const*>(object));
33  }
34 
35  LogError("Invalid object type.");
36  return nullptr;
37 }
38 
39 void DX11ComputeShader::Enable(ID3D11DeviceContext* context)
40 {
41  if (mDXObject)
42  {
43  ID3D11ClassInstance* instances[1] = { nullptr };
44  UINT numInstances = 0;
45  ID3D11ComputeShader* dxShader = static_cast<ID3D11ComputeShader*>(mDXObject);
46  context->CSSetShader(dxShader, instances, numInstances);
47  }
48 }
49 
50 void DX11ComputeShader::Disable(ID3D11DeviceContext* context)
51 {
52  if (mDXObject)
53  {
54  ID3D11ClassInstance* instances[1] = { nullptr };
55  UINT numInstances = 0;
56  ID3D11ComputeShader* dxShader = nullptr;
57  context->CSSetShader(dxShader, instances, numInstances);
58  }
59 }
60 
61 void DX11ComputeShader::EnableCBuffer(ID3D11DeviceContext* context,
62  unsigned int bindPoint, ID3D11Buffer* buffer)
63 {
64  if (mDXObject)
65  {
66  ID3D11Buffer* buffers[1] = { buffer };
67  context->CSSetConstantBuffers(bindPoint, 1, buffers);
68  }
69 }
70 
71 void DX11ComputeShader::DisableCBuffer(ID3D11DeviceContext* context,
72  unsigned int bindPoint)
73 {
74  if (mDXObject)
75  {
76  ID3D11Buffer* buffers[1] = { nullptr };
77  context->CSSetConstantBuffers(bindPoint, 1, buffers);
78  }
79 }
80 
81 void DX11ComputeShader::EnableSRView(ID3D11DeviceContext* context,
82  unsigned int bindPoint, ID3D11ShaderResourceView* srView)
83 {
84  if (mDXObject)
85  {
86  ID3D11ShaderResourceView* views[1] = { srView };
87  context->CSSetShaderResources(bindPoint, 1, views);
88  }
89 }
90 
91 void DX11ComputeShader::DisableSRView(ID3D11DeviceContext* context,
92  unsigned int bindPoint)
93 {
94  if (mDXObject)
95  {
96  ID3D11ShaderResourceView* views[1] = { nullptr };
97  context->CSSetShaderResources(bindPoint, 1, views);
98  }
99 }
100 
101 void DX11ComputeShader::EnableUAView(ID3D11DeviceContext* context,
102  unsigned int bindPoint, ID3D11UnorderedAccessView* uaView,
103  unsigned int initialCount)
104 {
105  if (mDXObject)
106  {
107  ID3D11UnorderedAccessView* views[1] = { uaView };
108  unsigned int initialCounts[1] = { initialCount };
109  context->CSSetUnorderedAccessViews(bindPoint, 1, views,
110  initialCounts);
111  }
112 }
113 
114 void DX11ComputeShader::DisableUAView(ID3D11DeviceContext* context,
115  unsigned int bindPoint)
116 {
117  if (mDXObject)
118  {
119  ID3D11UnorderedAccessView* views[1] = { nullptr };
120  unsigned int initialCounts[1] = { 0xFFFFFFFFu };
121  context->CSSetUnorderedAccessViews(bindPoint, 1, views,
122  initialCounts);
123  }
124 }
125 
126 void DX11ComputeShader::EnableSampler(ID3D11DeviceContext* context,
127  unsigned int bindPoint, ID3D11SamplerState* state)
128 {
129  if (mDXObject)
130  {
131  ID3D11SamplerState* states[1] = { state };
132  context->CSSetSamplers(bindPoint, 1, states);
133  }
134 }
135 
136 void DX11ComputeShader::DisableSampler(ID3D11DeviceContext* context,
137  unsigned int bindPoint)
138 {
139  if (mDXObject)
140  {
141  ID3D11SamplerState* states[1] = { nullptr };
142  context->CSSetSamplers(bindPoint, 1, states);
143  }
144 }
virtual void EnableSRView(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11ShaderResourceView *srView) override
virtual void DisableSRView(ID3D11DeviceContext *context, unsigned int bindPoint) override
static std::shared_ptr< GEObject > Create(void *device, GraphicsObject const *object)
GT_COMPUTE_SHADER
#define CHECK_HR_RETURN_NONE(msg)
const GLuint * buffers
Definition: glcorearb.h:656
DX11ComputeShader(ID3D11Device *device, Shader const *shader)
GraphicsObjectType GetType() const
virtual void DisableSampler(ID3D11DeviceContext *context, unsigned int bindPoint) override
virtual void EnableSampler(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11SamplerState *state) override
#define LogError(message)
Definition: GteLogger.h:92
ID3D11DeviceChild * mDXObject
virtual void DisableUAView(ID3D11DeviceContext *context, unsigned int bindPoint) override
virtual void Disable(ID3D11DeviceContext *context) override
virtual void EnableUAView(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11UnorderedAccessView *uaView, unsigned int initialCount) override
GLuint shader
Definition: glcorearb.h:780
typedef UINT(WINAPI *PFNWGLGETGPUIDSAMDPROC)(UINT maxCount
virtual void EnableCBuffer(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11Buffer *buffer) override
GLuint buffer
Definition: glcorearb.h:655
virtual void DisableCBuffer(ID3D11DeviceContext *context, unsigned int bindPoint) override
std::vector< unsigned char > const & GetCompiledCode() const
Definition: GteShader.h:388
virtual void Enable(ID3D11DeviceContext *context) override


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59