MCPcopy Create free account
hub / github.com/GPUOpen-Effects/GeometryFX / CompileShader

Function CompileShader

amd_geometryfx_sample/src/GeometryFX_Sample.cpp:225–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223};
224
225void CompileShader(ID3D11Device *device, ID3D11DeviceChild **ppShader, const char *sourceFile,
226 AMD::ShaderType::Enum shaderType, const char *entryPoint, const int macroCount = 0,
227 const D3D_SHADER_MACRO *pMacros = nullptr, ID3D11InputLayout **inputLayout = nullptr,
228 const int inputElementCount = 0, const D3D11_INPUT_ELEMENT_DESC *inputElements = nullptr)
229{
230 const auto data = AMD::GeometryFX_ReadBlobFromFile(sourceFile);
231
232 const char *target = nullptr;
233 switch (shaderType)
234 {
235 case AMD::ShaderType::Compute:
236 target = "cs_5_0";
237 break;
238 case AMD::ShaderType::Geometry:
239 target = "gs_5_0";
240 break;
241 case AMD::ShaderType::Pixel:
242 target = "ps_5_0";
243 break;
244 case AMD::ShaderType::Hull:
245 target = "hs_5_0";
246 break;
247 case AMD::ShaderType::Domain:
248 target = "ds_5_0";
249 break;
250 case AMD::ShaderType::Vertex:
251 target = "vs_5_0";
252 break;
253 }
254
255 ComPtr<ID3DBlob> output;
256
257 std::vector<D3D_SHADER_MACRO> macros(pMacros, pMacros + macroCount);
258
259 D3D_SHADER_MACRO nullMacro = { nullptr, nullptr };
260 macros.push_back(nullMacro);
261
262 D3DCompile(data.data(), data.size(), nullptr, macros.data(), D3D_COMPILE_STANDARD_FILE_INCLUDE,
263 entryPoint, target, 0, 0, &output, nullptr);
264
265 const size_t shaderSize = output->GetBufferSize();
266 const void *shaderSource = output->GetBufferPointer();
267 if (inputLayout)
268 {
269 device->CreateInputLayout(
270 inputElements, inputElementCount, shaderSource, shaderSize, inputLayout);
271 }
272
273 switch (shaderType)
274 {
275 case AMD::ShaderType::Compute:
276 device->CreateComputeShader(
277 shaderSource, shaderSize, nullptr, (ID3D11ComputeShader **)ppShader);
278 break;
279 case AMD::ShaderType::Pixel:
280 device->CreatePixelShader(
281 shaderSource, shaderSize, nullptr, (ID3D11PixelShader **)ppShader);
282 break;

Callers 2

CompileShadersMethod · 0.85
CreateShadersMethod · 0.85

Calls 2

GetBufferSizeMethod · 0.45

Tested by

no test coverage detected