DxilResourceProperties.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilResourceProperties.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Representation properties for DXIL handle. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "DxilConstants.h"
  13. namespace llvm {
  14. class Constant;
  15. class Type;
  16. }
  17. namespace hlsl {
  18. struct DxilResourceProperties {
  19. struct TypedProps {
  20. uint8_t CompType; // TypedBuffer/Image component type.
  21. uint8_t CompCount; // Number of components known to shader.
  22. uint8_t Reserved2;
  23. uint8_t Reserved3;
  24. };
  25. struct BasicProps {
  26. // BYTE 0
  27. uint8_t ResourceKind; // DXIL::ResourceKind
  28. // BYTE 1
  29. // Alignment of SRV/UAV base in 2^n. 0 is unknown/worst-case.
  30. uint8_t BaseAlignLog2 : 4;
  31. uint8_t IsUAV : 1;
  32. uint8_t IsROV : 1;
  33. uint8_t IsGloballyCoherent : 1;
  34. // Depending on ResourceKind, this indicates:
  35. // Sampler: SamplerKind::Comparison
  36. // StructuredBuffer: HasCounter
  37. // Other: must be 0
  38. uint8_t SamplerCmpOrHasCounter : 1;
  39. // BYTE 2
  40. uint8_t Reserved2;
  41. // BYTE 3
  42. uint8_t Reserved3;
  43. };
  44. union {
  45. BasicProps Basic;
  46. uint32_t RawDword0;
  47. };
  48. // DWORD
  49. union {
  50. TypedProps Typed;
  51. uint32_t StructStrideInBytes; // in bytes for StructuredBuffer.
  52. DXIL::SamplerFeedbackType SamplerFeedbackType; // FeedbackTexture2D.
  53. uint32_t CBufferSizeInBytes; // Cbuffer used size in bytes.
  54. uint32_t RawDword1;
  55. };
  56. DxilResourceProperties();
  57. DXIL::ResourceClass getResourceClass() const;
  58. DXIL::ResourceKind getResourceKind() const;
  59. DXIL::ComponentType getCompType() const;
  60. unsigned getElementStride() const;
  61. void setResourceKind(DXIL::ResourceKind RK);
  62. bool isUAV() const;
  63. bool operator==(const DxilResourceProperties &) const;
  64. bool operator!=(const DxilResourceProperties &) const;
  65. bool isValid() const;
  66. };
  67. static_assert(sizeof(DxilResourceProperties) == 2 * sizeof(uint32_t),
  68. "update shader model and functions read/write "
  69. "DxilResourceProperties when size is changed");
  70. class ShaderModel;
  71. class DxilResourceBase;
  72. struct DxilInst_AnnotateHandle;
  73. namespace resource_helper {
  74. llvm::Constant *getAsConstant(const DxilResourceProperties &, llvm::Type *Ty,
  75. const ShaderModel &);
  76. DxilResourceProperties loadPropsFromConstant(const llvm::Constant &C);
  77. DxilResourceProperties
  78. loadPropsFromAnnotateHandle(DxilInst_AnnotateHandle &annotateHandle, const ShaderModel &);
  79. DxilResourceProperties loadPropsFromResourceBase(const DxilResourceBase *);
  80. } // namespace resource_helper
  81. } // namespace hlsl