GteHLSLShader.h
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.1 (2016/09/12)
7 
8 #pragma once
9 
19 #include <fstream>
20 
21 namespace gte
22 {
23 
25 {
26 public:
27  struct Description
28  {
30  {
31  unsigned int numInstructions;
32  unsigned int numTemporaryRegisters;
33  unsigned int numTemporaryArrays;
34  unsigned int numDefines;
35  unsigned int numDeclarations;
36  unsigned int numTextureNormal;
37  unsigned int numTextureLoad;
38  unsigned int numTextureComparison;
39  unsigned int numTextureBias;
40  unsigned int numTextureGradient;
41  unsigned int numFloatArithmetic;
42  unsigned int numSIntArithmetic;
43  unsigned int numUIntArithmetic;
44  unsigned int numStaticFlowControl;
45  unsigned int numDynamicFlowControl;
46  unsigned int numMacro;
47  unsigned int numArray;
48  };
49 
50 
51  struct GSParameters
52  {
53  unsigned int numCutInstructions;
54  unsigned int numEmitInstructions;
55  D3D_PRIMITIVE inputPrimitive;
56  D3D_PRIMITIVE_TOPOLOGY outputTopology;
57  unsigned int maxOutputVertices;
58  };
59 
60  struct TSParameters
61  {
62  unsigned int numPatchConstants;
63  unsigned int numGSInstances;
64  unsigned int numControlPoints;
65  D3D_PRIMITIVE inputPrimitive;
66  D3D_TESSELLATOR_OUTPUT_PRIMITIVE outputPrimitive;
67  D3D_TESSELLATOR_PARTITIONING partitioning;
68  D3D_TESSELLATOR_DOMAIN domain;
69  };
70 
71  struct CSParameters
72  {
73  unsigned int numBarrierInstructions;
76  };
77 
80  unsigned int majorVersion;
81  unsigned int minorVersion;
82  unsigned int flags;
83  unsigned int numConstantBuffers;
84  unsigned int numBoundResources;
85  unsigned int numInputParameters;
86  unsigned int numOutputParameters;
91  };
92 
93  // Construction.
94  HLSLShader();
95 
96  // Test whether the shader was constructed properly. The function tests
97  // solely whether the name, entry, and target are nonempty strings and
98  // that the compiled code array is nonempty; this is the common case when
99  // HLSLShaderFactory is used to create the shader.
100  bool IsValid() const;
101 
102  // Deferred construction for shader reflection. These functions are
103  // intended to be write-once.
104  void SetDescription(D3D_SHADER_DESC const& desc);
105  void SetName(std::string const& name);
106  void SetEntry(std::string const& entry);
107  void SetTarget(std::string const& target);
108  void InsertInput(HLSLParameter const& parameter);
109  void InsertOutput(HLSLParameter const& parameter);
110  void Insert(HLSLConstantBuffer const& cbuffer);
111  void Insert(HLSLTextureBuffer const& tbuffer);
112  void Insert(HLSLStructuredBuffer const& sbuffer);
113  void Insert(HLSLByteAddressBuffer const& rbuffer);
114  void Insert(HLSLTexture const& texture);
115  void Insert(HLSLTextureArray const& textureArray);
116  void Insert(HLSLSamplerState const& samplerState);
117  void Insert(HLSLResourceBindInfo const& rbinfo);
118  void SetCompiledCode(size_t numBytes, void const* buffer);
119 
120  // Member access.
121  Description const& GetDescription() const;
122  std::string const& GetName() const;
123  std::string const& GetEntry() const;
124  std::string const& GetTarget() const;
125  int GetShaderTypeIndex() const;
126  std::vector<HLSLParameter> const& GetInputs() const;
127  std::vector<HLSLParameter> const& GetOutputs() const;
128  std::vector<HLSLConstantBuffer> const& GetCBuffers() const;
129  std::vector<HLSLTextureBuffer> const& GetTBuffers() const;
130  std::vector<HLSLStructuredBuffer> const& GetSBuffers() const;
131  std::vector<HLSLByteAddressBuffer> const& GetRBuffers() const;
132  std::vector<HLSLTexture> const& GetTextures() const;
133  std::vector<HLSLTextureArray> const& GetTextureArrays() const;
134  std::vector<HLSLSamplerState> const& GetSamplerStates() const;
135  std::vector<HLSLResourceBindInfo> const& GetResourceBindInfos() const;
136  std::vector<unsigned char> const& GetCompiledCode() const;
137 
138  // Compute shaders only.
139  void SetNumThreads(unsigned int numXThreads, unsigned int numYThreads,
140  unsigned int numZThreads);
141  unsigned int GetNumXThreads() const;
142  unsigned int GetNumYThreads() const;
143  unsigned int GetNumZThreads() const;
144 
145  // Print to a text file for human readability.
146  void Print(std::ofstream& output) const;
147 
148 private:
153  std::vector<HLSLParameter> mInputs;
154  std::vector<HLSLParameter> mOutputs;
155  std::vector<HLSLConstantBuffer> mCBuffers;
156  std::vector<HLSLTextureBuffer> mTBuffers;
157  std::vector<HLSLStructuredBuffer> mSBuffers;
158  std::vector<HLSLByteAddressBuffer> mRBuffers;
159  std::vector<HLSLTexture> mTextures;
160  std::vector<HLSLTextureArray> mTextureArrays;
161  std::vector<HLSLSamplerState> mSamplerStates;
162  std::vector<HLSLResourceBindInfo> mRBInfos;
163  std::vector<unsigned char> mCompiledCode;
164  unsigned int mNumXThreads;
165  unsigned int mNumYThreads;
166  unsigned int mNumZThreads;
167 
168  // Support for Print.
169  static std::string const msShaderType[];
170  static std::string const msCompileFlags[];
171  static std::string const msPrimitive[];
172  static std::string const msPrimitiveTopology[];
173  static std::string const msOutputPrimitive[];
174  static std::string const msPartitioning[];
175  static std::string const msDomain[];
176 };
177 
178 }
std::vector< unsigned char > mCompiledCode
std::vector< HLSLTexture > mTextures
Description mDesc
std::string mTarget
D3D_SHADER_VERSION_TYPE shaderType
Definition: GteHLSLShader.h:79
std::vector< HLSLParameter > mOutputs
std::string mName
std::string mEntry
GLuint const GLchar * name
Definition: glcorearb.h:781
GLenum target
Definition: glcorearb.h:1662
unsigned int mNumYThreads
std::vector< HLSLConstantBuffer > mCBuffers
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GLuint texture
Definition: glcorearb.h:410
std::vector< HLSLByteAddressBuffer > mRBuffers
std::vector< HLSLSamplerState > mSamplerStates
std::vector< HLSLTextureArray > mTextureArrays
D3D_TESSELLATOR_OUTPUT_PRIMITIVE outputPrimitive
Definition: GteHLSLShader.h:66
std::vector< HLSLStructuredBuffer > mSBuffers
D3D_TESSELLATOR_PARTITIONING partitioning
Definition: GteHLSLShader.h:67
unsigned int mNumZThreads
unsigned int mNumXThreads
std::vector< HLSLParameter > mInputs
GLuint buffer
Definition: glcorearb.h:655
InstructionCount instructions
Definition: GteHLSLShader.h:87
#define D3D_SHADER_DESC
#define D3D_SHADER_VERSION_TYPE
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
std::vector< HLSLTextureBuffer > mTBuffers
std::vector< HLSLResourceBindInfo > mRBInfos


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00