d3dx12_property_format_table.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //*********************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation.
  4. // Licensed under the MIT License (MIT).
  5. //
  6. //*********************************************************
  7. #ifndef __D3D12_PROPERTY_LAYOUT_FORMAT_TABLE_H__
  8. #define __D3D12_PROPERTY_LAYOUT_FORMAT_TABLE_H__
  9. #include "d3d12.h"
  10. #define MAP_ALIGN_REQUIREMENT 16 // Map is required to return 16-byte aligned addresses
  11. struct D3D12_PROPERTY_LAYOUT_FORMAT_TABLE
  12. {
  13. public:
  14. // ----------------------------------------------------------------------------
  15. // Information describing everything about a D3D Resource Format
  16. // ----------------------------------------------------------------------------
  17. typedef struct FORMAT_DETAIL
  18. {
  19. DXGI_FORMAT DXGIFormat;
  20. DXGI_FORMAT ParentFormat;
  21. const DXGI_FORMAT* pDefaultFormatCastSet; // This is dependent on FL/driver version, but is here to save a lot of space
  22. UINT8 BitsPerComponent[4]; // only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
  23. UINT8 BitsPerUnit;
  24. BYTE SRGBFormat : 1;
  25. UINT WidthAlignment : 4; // number of texels to align to in a mip level.
  26. UINT HeightAlignment : 4; // Top level dimensions must be a multiple of these
  27. UINT DepthAlignment : 1; // values.
  28. D3D_FORMAT_LAYOUT Layout : 1;
  29. D3D_FORMAT_TYPE_LEVEL TypeLevel : 2;
  30. D3D_FORMAT_COMPONENT_NAME ComponentName0 : 3; // RED ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
  31. D3D_FORMAT_COMPONENT_NAME ComponentName1 : 3; // GREEN ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
  32. D3D_FORMAT_COMPONENT_NAME ComponentName2 : 3; // BLUE ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
  33. D3D_FORMAT_COMPONENT_NAME ComponentName3 : 3; // ALPHA ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
  34. D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation0 : 3; // only used for D3DFTL_FULL_TYPE
  35. D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation1 : 3; // only used for D3DFTL_FULL_TYPE
  36. D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation2 : 3; // only used for D3DFTL_FULL_TYPE
  37. D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation3 : 3; // only used for D3DFTL_FULL_TYPE
  38. bool bDX9VertexOrIndexFormat : 1;
  39. bool bDX9TextureFormat : 1;
  40. bool bFloatNormFormat : 1;
  41. bool bPlanar : 1;
  42. bool bYUV : 1;
  43. bool bDependantFormatCastSet : 1; // This indicates that the format cast set is dependent on FL/driver version
  44. bool bInternal : 1;
  45. } FORMAT_DETAIL;
  46. private:
  47. static const FORMAT_DETAIL s_FormatDetail[];
  48. static const UINT s_NumFormats;
  49. static const LPCSTR s_FormatNames[]; // separate from above structure so it can be compiled out of runtime.
  50. public:
  51. static UINT GetNumFormats();
  52. static const FORMAT_DETAIL* GetFormatTable();
  53. static D3D_FEATURE_LEVEL GetHighestDefinedFeatureLevel();
  54. static DXGI_FORMAT GetFormat (SIZE_T Index);
  55. static bool FormatExists (DXGI_FORMAT Format);
  56. static bool FormatExistsInHeader (DXGI_FORMAT Format, bool bExternalHeader = true);
  57. static UINT GetByteAlignment (DXGI_FORMAT Format);
  58. static bool IsBlockCompressFormat (DXGI_FORMAT Format);
  59. static LPCSTR GetName (DXGI_FORMAT Format, bool bHideInternalFormats = true);
  60. static bool IsSRGBFormat (DXGI_FORMAT Format);
  61. static UINT GetBitsPerStencil (DXGI_FORMAT Format);
  62. static void GetFormatReturnTypes (DXGI_FORMAT Format, D3D_FORMAT_COMPONENT_INTERPRETATION* pInterpretations); // return array of 4 components
  63. static UINT GetNumComponentsInFormat(DXGI_FORMAT Format);
  64. // Converts the sequential component index (range from 0 to GetNumComponentsInFormat()) to
  65. // the absolute component index (range 0 to 3).
  66. static UINT Sequential2AbsoluteComponentIndex (DXGI_FORMAT Format, UINT SequentialComponentIndex);
  67. static bool CanBeCastEvenFullyTyped (DXGI_FORMAT Format, D3D_FEATURE_LEVEL fl);
  68. static UINT8 GetAddressingBitsPerAlignedSize (DXGI_FORMAT Format);
  69. static DXGI_FORMAT GetParentFormat (DXGI_FORMAT Format);
  70. static const DXGI_FORMAT* GetFormatCastSet (DXGI_FORMAT Format);
  71. static D3D_FORMAT_LAYOUT GetLayout (DXGI_FORMAT Format);
  72. static D3D_FORMAT_TYPE_LEVEL GetTypeLevel (DXGI_FORMAT Format);
  73. static UINT GetBitsPerUnit (DXGI_FORMAT Format);
  74. static UINT GetBitsPerUnitThrow (DXGI_FORMAT Format);
  75. static UINT GetBitsPerElement (DXGI_FORMAT Format); // Legacy function used to support D3D10on9 only. Do not use.
  76. static UINT GetWidthAlignment (DXGI_FORMAT Format);
  77. static UINT GetHeightAlignment (DXGI_FORMAT Format);
  78. static UINT GetDepthAlignment (DXGI_FORMAT Format);
  79. static BOOL Planar (DXGI_FORMAT Format);
  80. static BOOL NonOpaquePlanar (DXGI_FORMAT Format);
  81. static BOOL YUV (DXGI_FORMAT Format);
  82. static BOOL Opaque (DXGI_FORMAT Format);
  83. static bool FamilySupportsStencil (DXGI_FORMAT Format);
  84. static UINT NonOpaquePlaneCount (DXGI_FORMAT Format);
  85. static BOOL DX9VertexOrIndexFormat (DXGI_FORMAT Format);
  86. static BOOL DX9TextureFormat (DXGI_FORMAT Format);
  87. static BOOL FloatNormTextureFormat (DXGI_FORMAT Format);
  88. static bool DepthOnlyFormat (DXGI_FORMAT format);
  89. static UINT8 GetPlaneCount (DXGI_FORMAT Format);
  90. static bool MotionEstimatorAllowedInputFormat (DXGI_FORMAT Format);
  91. static bool SupportsSamplerFeedback (DXGI_FORMAT Format);
  92. static bool DecodeHistogramAllowedForOutputFormatSupport(DXGI_FORMAT Format);
  93. static UINT8 GetPlaneSliceFromViewFormat (DXGI_FORMAT ResourceFormat, DXGI_FORMAT ViewFormat);
  94. static bool FloatAndNotFloatFormats (DXGI_FORMAT FormatA, DXGI_FORMAT FormatB);
  95. static bool SNORMAndUNORMFormats (DXGI_FORMAT FormatA, DXGI_FORMAT FormatB);
  96. static bool ValidCastToR32UAV (DXGI_FORMAT from, DXGI_FORMAT to);
  97. static bool IsSupportedTextureDisplayableFormat (DXGI_FORMAT, bool bMediaFormatOnly);
  98. static D3D_FORMAT_COMPONENT_INTERPRETATION GetFormatComponentInterpretation (DXGI_FORMAT Format, UINT AbsoluteComponentIndex);
  99. static UINT GetBitsPerComponent (DXGI_FORMAT Format, UINT AbsoluteComponentIndex);
  100. static D3D_FORMAT_COMPONENT_NAME GetComponentName (DXGI_FORMAT Format, UINT AbsoluteComponentIndex);
  101. static HRESULT CalculateExtraPlanarRows (DXGI_FORMAT format, UINT plane0Height, _Out_ UINT& totalHeight);
  102. static HRESULT CalculateMinimumRowMajorRowPitch (DXGI_FORMAT Format, UINT Width, _Out_ UINT& RowPitch);
  103. static HRESULT CalculateMinimumRowMajorSlicePitch (DXGI_FORMAT Format, UINT ContextBasedRowPitch, UINT Height, _Out_ UINT& SlicePitch);
  104. static void GetYCbCrChromaSubsampling (DXGI_FORMAT Format, _Out_ UINT& HorizontalSubsampling, _Out_ UINT& VerticalSubsampling);
  105. static HRESULT CalculateResourceSize (UINT width, UINT height, UINT depth, DXGI_FORMAT format, UINT mipLevels, UINT subresources, _Out_ SIZE_T& totalByteSize, _Out_writes_opt_(subresources) D3D12_MEMCPY_DEST* pDst = nullptr);
  106. static void GetTileShape (D3D12_TILE_SHAPE* pTileShape, DXGI_FORMAT Format, D3D12_RESOURCE_DIMENSION Dimension, UINT SampleCount);
  107. static void Get4KTileShape (D3D12_TILE_SHAPE* pTileShape, DXGI_FORMAT Format, D3D12_RESOURCE_DIMENSION Dimension, UINT SampleCount);
  108. static void GetMipDimensions (UINT8 mipSlice, _Inout_ UINT64* pWidth, _Inout_opt_ UINT64* pHeight = nullptr, _Inout_opt_ UINT64* pDepth = nullptr);
  109. static void GetPlaneSubsampledSizeAndFormatForCopyableLayout(UINT PlaneSlice, DXGI_FORMAT Format, UINT Width, UINT Height, _Out_ DXGI_FORMAT& PlaneFormat, _Out_ UINT& MinPlanePitchWidth, _Out_ UINT& PlaneWidth, _Out_ UINT& PlaneHeight);
  110. static UINT GetDetailTableIndex (DXGI_FORMAT Format);
  111. static UINT GetDetailTableIndexNoThrow (DXGI_FORMAT Format);
  112. static UINT GetDetailTableIndexThrow (DXGI_FORMAT Format);
  113. private:
  114. static const FORMAT_DETAIL* GetFormatDetail (DXGI_FORMAT Format);
  115. };
  116. #endif