BsD3D11HLSLParamParser.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsD3D11Prerequisites.h"
  5. #include "RenderAPI/BsVertexDeclaration.h"
  6. namespace bs { namespace ct
  7. {
  8. /** @addtogroup D3D11
  9. * @{
  10. */
  11. /** Handles parsing of GPU program microcode and extracting constant and input parameter data. */
  12. class D3D11HLSLParamParser
  13. {
  14. public:
  15. /**
  16. * Parses the provided microcode and outputs constant parameter descriptions, and optionally for vertex GPU programs
  17. * a set of input parameters.
  18. *
  19. * @param[in] microcode Compiled GPU program microcode to parse.
  20. * @param[in] type Type of the GPU program.
  21. * @param[out] desc Output object that will contain parameter descriptions.
  22. * @param[out] inputParams Output object that will contain a set of program input parameters. Can be null if not
  23. * required. Only relevant for vertex programs.
  24. */
  25. void parse(ID3DBlob* microcode, GpuProgramType type, GpuParamDesc& desc, List<VertexElement>* inputParams);
  26. private:
  27. /** Types of HLSL parameters. */
  28. enum class ParamType
  29. {
  30. ConstantBuffer,
  31. Texture,
  32. Sampler,
  33. UAV,
  34. Count // Keep at end
  35. };
  36. /**
  37. * Parses the provided constant buffer retrieving information about all of its members and storing them in the
  38. * provided GPU params description object.
  39. */
  40. void parseBuffer(ID3D11ShaderReflectionConstantBuffer* bufferReflection, GpuParamDesc& desc);
  41. /** Parses the resource description structure and stores it in the provided GPU params description object. */
  42. void parseResource(D3D11_SHADER_INPUT_BIND_DESC& resourceDesc, GpuProgramType type, GpuParamDesc& desc);
  43. /**
  44. * Parses a variable with the specified type and variable description. Adds the variable in the provided GPU params
  45. * description object and assigns it to the provided param block.
  46. */
  47. void parseVariable(D3D11_SHADER_TYPE_DESC& varTypeDesc, D3D11_SHADER_VARIABLE_DESC& varDesc, GpuParamDesc& desc,
  48. GpuParamBlockDesc& paramBlock);
  49. /** Maps a parameter in a specific shader stage, of a specific type to a unique set index. */
  50. static UINT32 mapParameterToSet(GpuProgramType progType, ParamType paramType);
  51. };
  52. /** @} */
  53. }}