• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "include/core/SkImage.h"
12 #include "include/gpu/GrTypes.h"
13 #include "include/gpu/d3d/GrD3DTypes.h"
14 #include "include/private/GrTypesPriv.h"
15 
16 #define GR_D3D_CALL_ERRCHECK(X)                                       \
17     do {                                                              \
18        HRESULT result = X;                                            \
19        SkASSERT(SUCCEEDED(result));                                   \
20        if (!SUCCEEDED(result)) {                                      \
21            SkDebugf("Failed Direct3D call. Error: 0x%08x\n", result); \
22        }                                                              \
23     } while(false)
24 
25 static constexpr bool operator==(const D3D12_CPU_DESCRIPTOR_HANDLE & first,
26                                  const D3D12_CPU_DESCRIPTOR_HANDLE & second) {
27     return first.ptr == second.ptr;
28 }
29 
30 /**
31  * Returns true if the format is compressed.
32  */
33 bool GrDxgiFormatIsCompressed(DXGI_FORMAT);
34 
GrDxgiFormatChannels(DXGI_FORMAT format)35 static constexpr uint32_t GrDxgiFormatChannels(DXGI_FORMAT format) {
36     switch (format) {
37         case DXGI_FORMAT_R8G8B8A8_UNORM:           return kRGBA_SkColorChannelFlags;
38         case DXGI_FORMAT_R8_UNORM:                 return kRed_SkColorChannelFlag;
39         case DXGI_FORMAT_B8G8R8A8_UNORM:           return kRGBA_SkColorChannelFlags;
40         case DXGI_FORMAT_B5G6R5_UNORM:             return kRGB_SkColorChannelFlags;
41         case DXGI_FORMAT_R16G16B16A16_FLOAT:       return kRGBA_SkColorChannelFlags;
42         case DXGI_FORMAT_R16_FLOAT:                return kRed_SkColorChannelFlag;
43         case DXGI_FORMAT_R8G8_UNORM:               return kRG_SkColorChannelFlags;
44         case DXGI_FORMAT_R10G10B10A2_UNORM:        return kRGBA_SkColorChannelFlags;
45         case DXGI_FORMAT_B4G4R4A4_UNORM:           return kRGBA_SkColorChannelFlags;
46         case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:      return kRGBA_SkColorChannelFlags;
47         case DXGI_FORMAT_BC1_UNORM:                return kRGBA_SkColorChannelFlags;
48         case DXGI_FORMAT_R16_UNORM:                return kRed_SkColorChannelFlag;
49         case DXGI_FORMAT_R16G16_UNORM:             return kRG_SkColorChannelFlags;
50         case DXGI_FORMAT_R16G16B16A16_UNORM:       return kRGBA_SkColorChannelFlags;
51         case DXGI_FORMAT_R16G16_FLOAT:             return kRG_SkColorChannelFlags;
52         case DXGI_FORMAT_D24_UNORM_S8_UINT:        return 0;
53         case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:     return 0;
54 
55         default:                                   return 0;
56     }
57 }
58 
GrDxgiFormatBytesPerBlock(DXGI_FORMAT format)59 static constexpr size_t GrDxgiFormatBytesPerBlock(DXGI_FORMAT format) {
60     switch (format) {
61         case DXGI_FORMAT_R8G8B8A8_UNORM:           return 4;
62         case DXGI_FORMAT_R8_UNORM:                 return 1;
63         case DXGI_FORMAT_B8G8R8A8_UNORM:           return 4;
64         case DXGI_FORMAT_B5G6R5_UNORM:             return 2;
65         case DXGI_FORMAT_R16G16B16A16_FLOAT:       return 8;
66         case DXGI_FORMAT_R16_FLOAT:                return 2;
67         case DXGI_FORMAT_R8G8_UNORM:               return 2;
68         case DXGI_FORMAT_R10G10B10A2_UNORM:        return 4;
69         case DXGI_FORMAT_B4G4R4A4_UNORM:           return 2;
70         case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:      return 4;
71         case DXGI_FORMAT_BC1_UNORM:                return 8;
72         case DXGI_FORMAT_R16_UNORM:                return 2;
73         case DXGI_FORMAT_R16G16_UNORM:             return 4;
74         case DXGI_FORMAT_R16G16B16A16_UNORM:       return 8;
75         case DXGI_FORMAT_R16G16_FLOAT:             return 4;
76         case DXGI_FORMAT_D24_UNORM_S8_UINT:        return 4;
77         case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:     return 8;
78 
79         default:                                   return 0;
80     }
81 }
82 
GrDxgiFormatStencilBits(DXGI_FORMAT format)83 static constexpr int GrDxgiFormatStencilBits(DXGI_FORMAT format) {
84     switch (format) {
85         case DXGI_FORMAT_D24_UNORM_S8_UINT:
86             return 8;
87         case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
88             return 8;
89         default:
90             return 0;
91     }
92 }
93 
94 #if defined(SK_DEBUG) || GR_TEST_UTILS
GrDxgiFormatToStr(DXGI_FORMAT dxgiFormat)95 static constexpr const char* GrDxgiFormatToStr(DXGI_FORMAT dxgiFormat) {
96     switch (dxgiFormat) {
97         case DXGI_FORMAT_R8G8B8A8_UNORM:           return "R8G8B8A8_UNORM";
98         case DXGI_FORMAT_R8_UNORM:                 return "R8_UNORM";
99         case DXGI_FORMAT_B8G8R8A8_UNORM:           return "B8G8R8A8_UNORM";
100         case DXGI_FORMAT_B5G6R5_UNORM:             return "R5G6B5_UNORM";
101         case DXGI_FORMAT_R16G16B16A16_FLOAT:       return "R16G16B16A16_FLOAT";
102         case DXGI_FORMAT_R16_FLOAT:                return "R16_FLOAT";
103         case DXGI_FORMAT_R8G8_UNORM:               return "R8G8_UNORM";
104         case DXGI_FORMAT_R10G10B10A2_UNORM:        return "R10G10B10A2_UNORM";
105         case DXGI_FORMAT_B4G4R4A4_UNORM:           return "B4G4R4A4_UNORM";
106         case DXGI_FORMAT_R32G32B32A32_FLOAT:       return "R32G32B32A32_FLOAT";
107         case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:      return "R8G8B8A8_UNORM_SRGB";
108         case DXGI_FORMAT_BC1_UNORM:                return "BC1_UNORM";
109         case DXGI_FORMAT_R16_UNORM:                return "R16_UNORM";
110         case DXGI_FORMAT_R16G16_UNORM:             return "R16G16_UNORM";
111         case DXGI_FORMAT_R16G16B16A16_UNORM:       return "R16G16B16A16_UNORM";
112         case DXGI_FORMAT_R16G16_FLOAT:             return "R16G16_FLOAT";
113         case DXGI_FORMAT_D24_UNORM_S8_UINT:        return "D24_UNORM_S8_UINT";
114         case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:     return "D32_FLOAT_S8X24_UINT";
115 
116         default:                                   return "Unknown";
117     }
118 }
119 #endif
120 
121 #endif
122