| 1 |
/* |
| 2 |
* Copyright 2020 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef GrD3DCaps_DEFINED |
| 9 |
#define GrD3DCaps_DEFINED |
| 10 |
|
| 11 |
#include "src/gpu/ganesh/GrCaps.h" |
| 12 |
|
| 13 |
#include "include/gpu/ganesh/d3d/GrD3DTypes.h" |
| 14 |
#include "include/private/base/SkTDArray.h" |
| 15 |
#include "src/gpu/ganesh/d3d/GrD3DAttachment.h" |
| 16 |
|
| 17 |
enum class SkTextureCompressionType; |
| 18 |
|
| 19 |
/** |
| 20 |
* Stores some capabilities of a D3D backend. |
| 21 |
*/ |
| 22 |
class GrD3DCaps : public GrCaps { |
| 23 |
public: |
| 24 |
/** |
| 25 |
* Creates a GrD3DCaps that is set such that nothing is supported. The init function should |
| 26 |
* be called to fill out the caps. |
| 27 |
*/ |
| 28 |
GrD3DCaps(const GrContextOptions& contextOptions, IDXGIAdapter1*, ID3D12Device*); |
| 29 |
|
| 30 |
bool isFormatSRGB(const GrBackendFormat&) const override; |
| 31 |
|
| 32 |
bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override; |
| 33 |
bool isFormatTexturable(DXGI_FORMAT) const; |
| 34 |
|
| 35 |
bool isFormatCopyable(const GrBackendFormat&) const override { return true; } |
| 36 |
|
| 37 |
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, |
| 38 |
int sampleCount = 1) const override; |
| 39 |
bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override; |
| 40 |
bool isFormatRenderable(DXGI_FORMAT, int sampleCount) const; |
| 41 |
|
| 42 |
bool isFormatUnorderedAccessible(DXGI_FORMAT) const; |
| 43 |
|
| 44 |
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const override; |
| 45 |
int getRenderTargetSampleCount(int requestedCount, DXGI_FORMAT) const; |
| 46 |
|
| 47 |
int maxRenderTargetSampleCount(const GrBackendFormat&) const override; |
| 48 |
int maxRenderTargetSampleCount(DXGI_FORMAT) const; |
| 49 |
|
| 50 |
GrColorType getFormatColorType(DXGI_FORMAT) const; |
| 51 |
|
| 52 |
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, |
| 53 |
const GrBackendFormat& surfaceFormat, |
| 54 |
GrColorType srcColorType) const override; |
| 55 |
|
| 56 |
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override; |
| 57 |
|
| 58 |
/** |
| 59 |
* Returns both a supported and most preferred stencil format to use in draws. |
| 60 |
*/ |
| 61 |
DXGI_FORMAT preferredStencilFormat() const { |
| 62 |
return fPreferredStencilFormat; |
| 63 |
} |
| 64 |
static int GetStencilFormatTotalBitCount(DXGI_FORMAT format) { |
| 65 |
switch (format) { |
| 66 |
case DXGI_FORMAT_D24_UNORM_S8_UINT: |
| 67 |
return 32; |
| 68 |
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: |
| 69 |
// DXGI_FORMAT_D32_FLOAT_S8X24_UINT has 24 unused bits at the end so total bits is 64. |
| 70 |
return 64; |
| 71 |
default: |
| 72 |
SkASSERT(false); |
| 73 |
return 0; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Helpers used by canCopySurface. In all cases if the SampleCnt parameter is zero that means |
| 79 |
* the surface is not a render target, otherwise it is the number of samples in the render |
| 80 |
* target. |
| 81 |
*/ |
| 82 |
bool canCopyTexture(DXGI_FORMAT dstFormat, int dstSampleCnt, |
| 83 |
DXGI_FORMAT srcFormat, int srcSamplecnt) const; |
| 84 |
|
| 85 |
bool canCopyAsResolve(DXGI_FORMAT dstFormat, int dstSampleCnt, |
| 86 |
DXGI_FORMAT srcFormat, int srcSamplecnt) const; |
| 87 |
|
| 88 |
GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const override; |
| 89 |
|
| 90 |
DXGI_FORMAT getFormatFromColorType(GrColorType colorType) const { |
| 91 |
int idx = static_cast<int>(colorType); |
| 92 |
return fColorTypeToFormatTable[idx]; |
| 93 |
} |
| 94 |
|
| 95 |
skgpu::Swizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const override; |
| 96 |
|
| 97 |
uint64_t computeFormatKey(const GrBackendFormat&) const override; |
| 98 |
|
| 99 |
void addExtraSamplerKey(skgpu::KeyBuilder*, |
| 100 |
GrSamplerState, |
| 101 |
const GrBackendFormat&) const override; |
| 102 |
|
| 103 |
GrProgramDesc makeDesc(GrRenderTarget*, |
| 104 |
const GrProgramInfo&, |
| 105 |
ProgramDescOverrideFlags) const override; |
| 106 |
|
| 107 |
bool resolveSubresourceRegionSupport() const { return fResolveSubresourceRegionSupport; } |
| 108 |
bool standardSwizzleLayoutSupport() const { return fStandardSwizzleLayoutSupport; } |
| 109 |
|
| 110 |
#if defined(GPU_TEST_UTILS) |
| 111 |
std::vector<GrTest::TestFormatColorTypeCombination> getTestingCombinations() const override; |
| 112 |
#endif |
| 113 |
|
| 114 |
private: |
| 115 |
enum D3DVendor { |
| 116 |
kAMD_D3DVendor = 0x1002, |
| 117 |
kARM_D3DVendor = 0x13B5, |
| 118 |
kImagination_D3DVendor = 0x1010, |
| 119 |
kIntel_D3DVendor = 0x8086, |
| 120 |
kNVIDIA_D3DVendor = 0x10DE, |
| 121 |
kQualcomm_D3DVendor = 0x5143, |
| 122 |
}; |
| 123 |
|
| 124 |
void init(const GrContextOptions& contextOptions, IDXGIAdapter1*, ID3D12Device*); |
| 125 |
|
| 126 |
void initGrCaps(const D3D12_FEATURE_DATA_D3D12_OPTIONS&, |
| 127 |
ID3D12Device*); |
| 128 |
void initShaderCaps(int vendorID, const D3D12_FEATURE_DATA_D3D12_OPTIONS& optionsDesc); |
| 129 |
|
| 130 |
void initFormatTable(const DXGI_ADAPTER_DESC&, ID3D12Device*); |
| 131 |
void initStencilFormat(ID3D12Device*); |
| 132 |
|
| 133 |
void applyDriverCorrectnessWorkarounds(int vendorID); |
| 134 |
|
| 135 |
bool onSurfaceSupportsWritePixels(const GrSurface*) const override; |
| 136 |
bool onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect, |
| 137 |
const GrSurfaceProxy* src, const SkIRect& srcRect) const override; |
| 138 |
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override; |
| 139 |
|
| 140 |
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; |
| 141 |
|
| 142 |
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&, |
| 143 |
GrColorType) const override; |
| 144 |
|
| 145 |
skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const override; |
| 146 |
|
| 147 |
// ColorTypeInfo for a specific format |
| 148 |
struct ColorTypeInfo { |
| 149 |
GrColorType fColorType = GrColorType::kUnknown; |
| 150 |
enum { |
| 151 |
kUploadData_Flag = 0x1, |
| 152 |
// Does Ganesh itself support rendering to this colorType & format pair. Renderability |
| 153 |
// still additionally depends on if the format itself is renderable. |
| 154 |
kRenderable_Flag = 0x2, |
| 155 |
// Indicates that this colorType is supported only if we are wrapping a texture with |
| 156 |
// the given format and colorType. We do not allow creation with this pair. |
| 157 |
kWrappedOnly_Flag = 0x4, |
| 158 |
}; |
| 159 |
uint32_t fFlags = 0; |
| 160 |
|
| 161 |
skgpu::Swizzle fReadSwizzle; |
| 162 |
skgpu::Swizzle fWriteSwizzle; |
| 163 |
}; |
| 164 |
|
| 165 |
struct FormatInfo { |
| 166 |
uint32_t colorTypeFlags(GrColorType colorType) const { |
| 167 |
for (int i = 0; i < fColorTypeInfoCount; ++i) { |
| 168 |
if (fColorTypeInfos[i].fColorType == colorType) { |
| 169 |
return fColorTypeInfos[i].fFlags; |
| 170 |
} |
| 171 |
} |
| 172 |
return 0; |
| 173 |
} |
| 174 |
|
| 175 |
void init(const DXGI_ADAPTER_DESC&, ID3D12Device*, DXGI_FORMAT); |
| 176 |
static void InitFormatFlags(const D3D12_FEATURE_DATA_FORMAT_SUPPORT&, uint16_t* flags); |
| 177 |
void initSampleCounts(const DXGI_ADAPTER_DESC& adapterDesc, ID3D12Device*, DXGI_FORMAT); |
| 178 |
|
| 179 |
enum { |
| 180 |
kTexturable_Flag = 0x1, // Can be sampled in a shader |
| 181 |
kRenderable_Flag = 0x2, // Rendertarget and blendable |
| 182 |
kMSAA_Flag = 0x4, |
| 183 |
kResolve_Flag = 0x8, |
| 184 |
kUnorderedAccess_Flag = 0x10, |
| 185 |
}; |
| 186 |
|
| 187 |
uint16_t fFlags = 0; |
| 188 |
|
| 189 |
SkTDArray<int> fColorSampleCounts; |
| 190 |
|
| 191 |
// This GrColorType represents how the actually GPU format lays out its memory. This is used |
| 192 |
// for uploading data to backend textures to make sure we've arranged the memory in the |
| 193 |
// correct order. |
| 194 |
GrColorType fFormatColorType = GrColorType::kUnknown; |
| 195 |
|
| 196 |
std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos; |
| 197 |
int fColorTypeInfoCount = 0; |
| 198 |
}; |
| 199 |
static constexpr size_t kNumDxgiFormats = 15; |
| 200 |
FormatInfo fFormatTable[kNumDxgiFormats]; |
| 201 |
|
| 202 |
FormatInfo& getFormatInfo(DXGI_FORMAT); |
| 203 |
const FormatInfo& getFormatInfo(DXGI_FORMAT) const; |
| 204 |
|
| 205 |
DXGI_FORMAT fColorTypeToFormatTable[kGrColorTypeCnt]; |
| 206 |
void setColorType(GrColorType, std::initializer_list<DXGI_FORMAT> formats); |
| 207 |
|
| 208 |
int fMaxPerStageShaderResourceViews; |
| 209 |
int fMaxPerStageUnorderedAccessViews; |
| 210 |
|
| 211 |
DXGI_FORMAT fPreferredStencilFormat; |
| 212 |
|
| 213 |
bool fResolveSubresourceRegionSupport : 1; |
| 214 |
bool fStandardSwizzleLayoutSupport : 1; |
| 215 |
|
| 216 |
using INHERITED = GrCaps; |
| 217 |
}; |
| 218 |
|
| 219 |
#endif |