Flutter Engine
The Flutter Engine
GrD3DAttachment.cpp
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
9
11
12GrD3DAttachment::GrD3DAttachment(GrD3DGpu* gpu,
13 SkISize dimensions,
14 UsageFlags supportedUsages,
15 DXGI_FORMAT format,
16 const D3D12_RESOURCE_DESC& desc,
20 std::string_view label)
21 : GrAttachment(gpu,
22 dimensions,
23 supportedUsages,
24 desc.SampleDesc.Count,
27 label)
29 , fView(view)
30 , fFormat(format) {
31 this->registerWithCache(skgpu::Budgeted::kYes);
32}
33
35 SkISize dimensions,
36 int sampleCnt,
37 DXGI_FORMAT format) {
38 D3D12_RESOURCE_DESC resourceDesc = {};
39 resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
40 resourceDesc.Alignment = 0; // default alignment
41 resourceDesc.Width = dimensions.width();
42 resourceDesc.Height = dimensions.height();
43 resourceDesc.DepthOrArraySize = 1;
44 resourceDesc.MipLevels = 1;
45 resourceDesc.Format = format;
46 resourceDesc.SampleDesc.Count = sampleCnt;
47 resourceDesc.SampleDesc.Quality = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN;
48 resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; // use driver-selected swizzle
49 resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
50
51 D3D12_CLEAR_VALUE clearValue = {};
52 clearValue.Format = format;
53 clearValue.DepthStencil.Depth = 0;
54 clearValue.DepthStencil.Stencil = 0;
55
58 D3D12_RESOURCE_STATE_DEPTH_WRITE,
59 GrProtected::kNo, &clearValue, &info)) {
60 return nullptr;
61 }
62
64 gpu->resourceProvider().createDepthStencilView(info.fResource.get());
65
69 format, resourceDesc, info,
70 std::move(state),
71 view,
72 /*label=*/"D3DAttachment_MakeStencil"));
73}
74
76 GrD3DGpu* gpu = this->getD3DGpu();
77 this->releaseResource(gpu);
78
80}
81
83 GrD3DGpu* gpu = this->getD3DGpu();
84 this->releaseResource(gpu);
85
87}
88
89GrD3DGpu* GrD3DAttachment::getD3DGpu() const {
90 SkASSERT(!this->wasDestroyed());
91 return static_cast<GrD3DGpu*>(this->getGpu());
92}
93
94void GrD3DAttachment::onSetLabel() {
95 SkASSERT(this->d3dResource());
96 if (!this->getLabel().empty()) {
97 const std::wstring label = L"_Skia_" + GrD3DMultiByteToWide(this->getLabel());
98 this->d3dResource()->SetName(label.c_str());
99 }
100}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
std::wstring GrD3DMultiByteToWide(const std::string &str)
Definition: GrD3DUtil.cpp:25
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
void onAbandon() override
void onRelease() override
D3D12_CPU_DESCRIPTOR_HANDLE view() const
static sk_sp< GrD3DAttachment > MakeStencil(GrD3DGpu *gpu, SkISize dimensions, int sampleCnt, DXGI_FORMAT format)
GrD3DResourceProvider & resourceProvider()
Definition: GrD3DGpu.h:38
GrD3DDescriptorHeap::CPUHandle createDepthStencilView(ID3D12Resource *textureResource)
ID3D12Resource * d3dResource() const
void releaseResource(GrD3DGpu *gpu)
static bool InitTextureResourceInfo(GrD3DGpu *gpu, const D3D12_RESOURCE_DESC &desc, D3D12_RESOURCE_STATES initialState, GrProtected, D3D12_CLEAR_VALUE *, GrD3DTextureResourceInfo *)
std::string getLabel() const
GrGpu * getGpu() const
bool wasDestroyed() const
SkISize dimensions() const
Definition: GrSurface.h:27
void onAbandon() override
Definition: GrSurface.cpp:86
void onRelease() override
Definition: GrSurface.cpp:81
EMSCRIPTEN_KEEPALIVE void empty()
AtkStateType state
uint32_t uint32_t * format
Definition: GpuTools.h:21
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37