Flutter Engine
The Flutter Engine
GrD3DUtil.h
Go to the documentation of this file.
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 GrD3DUtil_DEFINED
9#define GrD3DUtil_DEFINED
10
12#include "include/gpu/GrTypes.h"
15
16#include <string>
17
18#define GR_D3D_CALL_ERRCHECK(X) \
19 do { \
20 HRESULT result = X; \
21 SkASSERT(SUCCEEDED(result)); \
22 if (!SUCCEEDED(result)) { \
23 SkDebugf("Failed Direct3D call. Error: 0x%08lx\n", result); \
24 } \
25 } while (false)
26
27static constexpr bool operator==(const D3D12_CPU_DESCRIPTOR_HANDLE & first,
28 const D3D12_CPU_DESCRIPTOR_HANDLE & second) {
29 return first.ptr == second.ptr;
30}
31
32/**
33 * Returns true if the format is compressed.
34 */
35bool GrDxgiFormatIsCompressed(DXGI_FORMAT);
36
37static constexpr uint32_t GrDxgiFormatChannels(DXGI_FORMAT format) {
38 switch (format) {
39 case DXGI_FORMAT_R8G8B8A8_UNORM: return kRGBA_SkColorChannelFlags;
40 case DXGI_FORMAT_R8_UNORM: return kRed_SkColorChannelFlag;
41 case DXGI_FORMAT_B8G8R8A8_UNORM: return kRGBA_SkColorChannelFlags;
42 case DXGI_FORMAT_B5G6R5_UNORM: return kRGB_SkColorChannelFlags;
43 case DXGI_FORMAT_R16G16B16A16_FLOAT: return kRGBA_SkColorChannelFlags;
44 case DXGI_FORMAT_R16_FLOAT: return kRed_SkColorChannelFlag;
45 case DXGI_FORMAT_R8G8_UNORM: return kRG_SkColorChannelFlags;
46 case DXGI_FORMAT_R10G10B10A2_UNORM: return kRGBA_SkColorChannelFlags;
47 case DXGI_FORMAT_B4G4R4A4_UNORM: return kRGBA_SkColorChannelFlags;
48 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return kRGBA_SkColorChannelFlags;
49 case DXGI_FORMAT_BC1_UNORM: return kRGBA_SkColorChannelFlags;
50 case DXGI_FORMAT_R16_UNORM: return kRed_SkColorChannelFlag;
51 case DXGI_FORMAT_R16G16_UNORM: return kRG_SkColorChannelFlags;
52 case DXGI_FORMAT_R16G16B16A16_UNORM: return kRGBA_SkColorChannelFlags;
53 case DXGI_FORMAT_R16G16_FLOAT: return kRG_SkColorChannelFlags;
54 case DXGI_FORMAT_D24_UNORM_S8_UINT: return 0;
55 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return 0;
56
57 default: return 0;
58 }
59}
60
61static constexpr GrColorFormatDesc GrDxgiFormatDesc(DXGI_FORMAT format) {
62 switch (format) {
63 case DXGI_FORMAT_R8G8B8A8_UNORM:
65 case DXGI_FORMAT_R8_UNORM:
67 case DXGI_FORMAT_B8G8R8A8_UNORM:
69 case DXGI_FORMAT_B5G6R5_UNORM:
71 case DXGI_FORMAT_R16G16B16A16_FLOAT:
73 case DXGI_FORMAT_R16_FLOAT:
75 case DXGI_FORMAT_R8G8_UNORM:
77 case DXGI_FORMAT_R10G10B10A2_UNORM:
79 case DXGI_FORMAT_B4G4R4A4_UNORM:
81 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
83 case DXGI_FORMAT_R16_UNORM:
85 case DXGI_FORMAT_R16G16_UNORM:
87 case DXGI_FORMAT_R16G16B16A16_UNORM:
89 case DXGI_FORMAT_R16G16_FLOAT:
91
92 // Compressed texture formats are not expected to have a description.
93 case DXGI_FORMAT_BC1_UNORM: return GrColorFormatDesc::MakeInvalid();
94
95 // This type only describes color channels.
96 case DXGI_FORMAT_D24_UNORM_S8_UINT: return GrColorFormatDesc::MakeInvalid();
97 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return GrColorFormatDesc::MakeInvalid();
98
99 default: return GrColorFormatDesc::MakeInvalid();
100 }
101}
102
103static constexpr size_t GrDxgiFormatBytesPerBlock(DXGI_FORMAT format) {
104 switch (format) {
105 case DXGI_FORMAT_R8G8B8A8_UNORM: return 4;
106 case DXGI_FORMAT_R8_UNORM: return 1;
107 case DXGI_FORMAT_B8G8R8A8_UNORM: return 4;
108 case DXGI_FORMAT_B5G6R5_UNORM: return 2;
109 case DXGI_FORMAT_R16G16B16A16_FLOAT: return 8;
110 case DXGI_FORMAT_R16_FLOAT: return 2;
111 case DXGI_FORMAT_R8G8_UNORM: return 2;
112 case DXGI_FORMAT_R10G10B10A2_UNORM: return 4;
113 case DXGI_FORMAT_B4G4R4A4_UNORM: return 2;
114 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return 4;
115 case DXGI_FORMAT_BC1_UNORM: return 8;
116 case DXGI_FORMAT_R16_UNORM: return 2;
117 case DXGI_FORMAT_R16G16_UNORM: return 4;
118 case DXGI_FORMAT_R16G16B16A16_UNORM: return 8;
119 case DXGI_FORMAT_R16G16_FLOAT: return 4;
120 case DXGI_FORMAT_D24_UNORM_S8_UINT: return 4;
121 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return 8;
122
123 default: return 0;
124 }
125}
126
127static constexpr int GrDxgiFormatStencilBits(DXGI_FORMAT format) {
128 switch (format) {
129 case DXGI_FORMAT_D24_UNORM_S8_UINT:
130 return 8;
131 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
132 return 8;
133 default:
134 return 0;
135 }
136}
137
138#if defined(SK_DEBUG) || defined(GR_TEST_UTILS)
139static constexpr const char* GrDxgiFormatToStr(DXGI_FORMAT dxgiFormat) {
140 switch (dxgiFormat) {
141 case DXGI_FORMAT_R8G8B8A8_UNORM: return "R8G8B8A8_UNORM";
142 case DXGI_FORMAT_R8_UNORM: return "R8_UNORM";
143 case DXGI_FORMAT_B8G8R8A8_UNORM: return "B8G8R8A8_UNORM";
144 case DXGI_FORMAT_B5G6R5_UNORM: return "R5G6B5_UNORM";
145 case DXGI_FORMAT_R16G16B16A16_FLOAT: return "R16G16B16A16_FLOAT";
146 case DXGI_FORMAT_R16_FLOAT: return "R16_FLOAT";
147 case DXGI_FORMAT_R8G8_UNORM: return "R8G8_UNORM";
148 case DXGI_FORMAT_R10G10B10A2_UNORM: return "R10G10B10A2_UNORM";
149 case DXGI_FORMAT_B4G4R4A4_UNORM: return "B4G4R4A4_UNORM";
150 case DXGI_FORMAT_R32G32B32A32_FLOAT: return "R32G32B32A32_FLOAT";
151 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return "R8G8B8A8_UNORM_SRGB";
152 case DXGI_FORMAT_BC1_UNORM: return "BC1_UNORM";
153 case DXGI_FORMAT_R16_UNORM: return "R16_UNORM";
154 case DXGI_FORMAT_R16G16_UNORM: return "R16G16_UNORM";
155 case DXGI_FORMAT_R16G16B16A16_UNORM: return "R16G16B16A16_UNORM";
156 case DXGI_FORMAT_R16G16_FLOAT: return "R16G16_FLOAT";
157 case DXGI_FORMAT_D24_UNORM_S8_UINT: return "D24_UNORM_S8_UINT";
158 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return "D32_FLOAT_S8X24_UINT";
159
160 default: return "Unknown";
161 }
162}
163#endif
164
165std::wstring GrD3DMultiByteToWide(const std::string& str);
166
167#endif
std::wstring GrD3DMultiByteToWide(const std::string &str)
Definition: GrD3DUtil.cpp:25
bool GrDxgiFormatIsCompressed(DXGI_FORMAT)
Definition: GrD3DUtil.cpp:15
static constexpr bool operator==(const D3D12_CPU_DESCRIPTOR_HANDLE &first, const D3D12_CPU_DESCRIPTOR_HANDLE &second)
Definition: GrD3DUtil.h:27
static constexpr uint32_t GrDxgiFormatChannels(DXGI_FORMAT format)
Definition: GrD3DUtil.h:37
static constexpr size_t GrDxgiFormatBytesPerBlock(DXGI_FORMAT format)
Definition: GrD3DUtil.h:103
static constexpr int GrDxgiFormatStencilBits(DXGI_FORMAT format)
Definition: GrD3DUtil.h:127
static constexpr GrColorFormatDesc GrDxgiFormatDesc(DXGI_FORMAT format)
Definition: GrD3DUtil.h:61
@ kRGB_SkColorChannelFlags
Definition: SkColor.h:247
@ kRGBA_SkColorChannelFlags
Definition: SkColor.h:248
@ kRed_SkColorChannelFlag
Definition: SkColor.h:239
@ kRG_SkColorChannelFlags
Definition: SkColor.h:246
static constexpr GrColorFormatDesc MakeInvalid()
Definition: GrTypesPriv.h:756
static constexpr GrColorFormatDesc MakeRGBA(int rgba, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:720
static constexpr GrColorFormatDesc MakeRG(int rg, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:744
static constexpr GrColorFormatDesc MakeRGB(int rgb, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:728
static constexpr GrColorFormatDesc MakeR(int r, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:740
uint32_t uint32_t * format