GteDX11GeometryShader.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 
13  :
14  DX11Shader(shader)
15 {
16  std::vector<unsigned char> const& code = shader->GetCompiledCode();
17 
18  ID3D11ClassLinkage* linkage = nullptr;
19  ID3D11GeometryShader* dxShader = nullptr;
20  HRESULT hr = device->CreateGeometryShader(&code[0], code.size(), linkage, &dxShader);
21  CHECK_HR_RETURN_NONE("Failed to create geometry shader");
22 
23  mDXObject = dxShader;
24 }
25 
26 std::shared_ptr<GEObject> DX11GeometryShader::Create(void* device, GraphicsObject const* object)
27 {
28  if (object->GetType() == GT_GEOMETRY_SHADER)
29  {
30  return std::make_shared<DX11GeometryShader>(
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 DX11GeometryShader::Enable(ID3D11DeviceContext* context)
40 {
41  if (mDXObject)
42  {
43  ID3D11ClassInstance* instances[1] = { nullptr };
44  UINT numInstances = 0;
45  ID3D11GeometryShader* dxShader = static_cast<ID3D11GeometryShader*>(mDXObject);
46  context->GSSetShader(dxShader, instances, numInstances);
47  }
48 }
49 
50 void DX11GeometryShader::Disable(ID3D11DeviceContext* context)
51 {
52  if (mDXObject)
53  {
54  ID3D11ClassInstance* instances[1] = { nullptr };
55  UINT numInstances = 0;
56  ID3D11GeometryShader* dxShader = nullptr;
57  context->GSSetShader(dxShader, instances, numInstances);
58  }
59 }
60 
61 void DX11GeometryShader::EnableCBuffer(ID3D11DeviceContext* context,
62  unsigned int bindPoint, ID3D11Buffer* buffer)
63 {
64  if (mDXObject)
65  {
66  ID3D11Buffer* buffers[1] = { buffer };
67  context->GSSetConstantBuffers(bindPoint, 1, buffers);
68  }
69 }
70 
71 void DX11GeometryShader::DisableCBuffer(ID3D11DeviceContext* context,
72  unsigned int bindPoint)
73 {
74  if (mDXObject)
75  {
76  ID3D11Buffer* buffers[1] = { nullptr };
77  context->GSSetConstantBuffers(bindPoint, 1, buffers);
78  }
79 }
80 
81 void DX11GeometryShader::EnableSRView(ID3D11DeviceContext* context,
82  unsigned int bindPoint, ID3D11ShaderResourceView* srView)
83 {
84  if (mDXObject)
85  {
86  ID3D11ShaderResourceView* views[1] = { srView };
87  context->GSSetShaderResources(bindPoint, 1, views);
88  }
89 }
90 
91 void DX11GeometryShader::DisableSRView(ID3D11DeviceContext* context,
92  unsigned int bindPoint)
93 {
94  if (mDXObject)
95  {
96  ID3D11ShaderResourceView* views[1] = { nullptr };
97  context->GSSetShaderResources(bindPoint, 1, views);
98  }
99 }
100 
101 void DX11GeometryShader::EnableUAView(ID3D11DeviceContext* context,
102  unsigned int bindPoint, ID3D11UnorderedAccessView* uaView,
103  unsigned int initialCount)
104 {
105  if (mDXObject)
106  {
107  ID3D11Device* device = nullptr;
108  context->GetDevice(&device);
109  if (!device)
110  {
111  LogError("Cannot access device of context.");
112  return;
113  }
114 
115  if (device->GetFeatureLevel() == D3D_FEATURE_LEVEL_11_1)
116  {
117  ID3D11UnorderedAccessView* uaViews[1] = { uaView };
118  unsigned int initialCounts[1] = { initialCount };
119  context->OMSetRenderTargetsAndUnorderedAccessViews(
120  D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr,
121  nullptr, bindPoint, 1, uaViews, initialCounts);
122  }
123  else
124  {
125  LogError("D3D11.1 is required for UAVs in geometry shaders.");
126  }
127  device->Release();
128  }
129 }
130 
131 void DX11GeometryShader::DisableUAView(ID3D11DeviceContext* context,
132  unsigned int bindPoint)
133 {
134  if (mDXObject)
135  {
136  ID3D11Device* device = nullptr;
137  context->GetDevice(&device);
138  if (!device)
139  {
140  LogError("Cannot access device of context.");
141  return;
142  }
143 
144  if (device->GetFeatureLevel() == D3D_FEATURE_LEVEL_11_1)
145  {
146  ID3D11UnorderedAccessView* uaViews[1] = { nullptr };
147  unsigned int initialCounts[1] = { 0xFFFFFFFFu };
148  context->OMSetRenderTargetsAndUnorderedAccessViews(
149  D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr,
150  nullptr, bindPoint, 1, uaViews, initialCounts);
151  }
152  else
153  {
154  LogError("D3D11.1 is required for UAVs in geometry shaders.");
155  }
156  device->Release();
157  }
158 }
159 
160 void DX11GeometryShader::EnableSampler(ID3D11DeviceContext* context,
161  unsigned int bindPoint, ID3D11SamplerState* state)
162 {
163  if (mDXObject)
164  {
165  ID3D11SamplerState* states[1] = { state };
166  context->GSSetSamplers(bindPoint, 1, states);
167  }
168 }
169 
170 void DX11GeometryShader::DisableSampler(ID3D11DeviceContext* context,
171  unsigned int bindPoint)
172 {
173  if (mDXObject)
174  {
175  ID3D11SamplerState* states[1] = { nullptr };
176  context->GSSetSamplers(bindPoint, 1, states);
177  }
178 }
virtual void EnableUAView(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11UnorderedAccessView *uaView, unsigned int initialCount) override
virtual void EnableSRView(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11ShaderResourceView *srView) override
virtual void DisableSampler(ID3D11DeviceContext *context, unsigned int bindPoint) override
#define CHECK_HR_RETURN_NONE(msg)
virtual void EnableCBuffer(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11Buffer *buffer) override
const GLuint * buffers
Definition: glcorearb.h:656
GraphicsObjectType GetType() const
DX11GeometryShader(ID3D11Device *device, Shader const *shader)
virtual void EnableSampler(ID3D11DeviceContext *context, unsigned int bindPoint, ID3D11SamplerState *state) override
virtual void Enable(ID3D11DeviceContext *context) override
#define LogError(message)
Definition: GteLogger.h:92
virtual void DisableUAView(ID3D11DeviceContext *context, unsigned int bindPoint) override
ID3D11DeviceChild * mDXObject
GLuint shader
Definition: glcorearb.h:780
static std::shared_ptr< GEObject > Create(void *device, GraphicsObject const *object)
virtual void DisableSRView(ID3D11DeviceContext *context, unsigned int bindPoint) override
typedef UINT(WINAPI *PFNWGLGETGPUIDSAMDPROC)(UINT maxCount
GLuint buffer
Definition: glcorearb.h:655
virtual void DisableCBuffer(ID3D11DeviceContext *context, unsigned int bindPoint) override
virtual void Disable(ID3D11DeviceContext *context) override
std::vector< unsigned char > const & GetCompiledCode() const
Definition: GteShader.h:388
GT_GEOMETRY_SHADER


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