• 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 #include "src/gpu/d3d/GrD3DAttachment.h"
9 
10 #include "src/gpu/d3d/GrD3DGpu.h"
11 
GrD3DAttachment(GrD3DGpu * gpu,SkISize dimensions,UsageFlags supportedUsages,DXGI_FORMAT format,const D3D12_RESOURCE_DESC & desc,const GrD3DTextureResourceInfo & info,sk_sp<GrD3DResourceState> state,const GrD3DDescriptorHeap::CPUHandle & view)12 GrD3DAttachment::GrD3DAttachment(GrD3DGpu* gpu,
13                                  SkISize dimensions,
14                                  UsageFlags supportedUsages,
15                                  DXGI_FORMAT format,
16                                  const D3D12_RESOURCE_DESC& desc,
17                                  const GrD3DTextureResourceInfo& info,
18                                  sk_sp<GrD3DResourceState> state,
19                                  const GrD3DDescriptorHeap::CPUHandle& view)
20         : GrAttachment(gpu, dimensions, supportedUsages, desc.SampleDesc.Count, GrMipmapped::kNo,
21                        GrProtected::kNo)
22         , GrD3DTextureResource(info, state)
23         , fView(view)
24         , fFormat(format) {
25     this->registerWithCache(SkBudgeted::kYes);
26 }
27 
MakeStencil(GrD3DGpu * gpu,SkISize dimensions,int sampleCnt,DXGI_FORMAT format)28 sk_sp<GrD3DAttachment> GrD3DAttachment::MakeStencil(GrD3DGpu* gpu,
29                                                     SkISize dimensions,
30                                                     int sampleCnt,
31                                                     DXGI_FORMAT format) {
32     D3D12_RESOURCE_DESC resourceDesc = {};
33     resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
34     resourceDesc.Alignment = 0;  // default alignment
35     resourceDesc.Width = dimensions.width();
36     resourceDesc.Height = dimensions.height();
37     resourceDesc.DepthOrArraySize = 1;
38     resourceDesc.MipLevels = 1;
39     resourceDesc.Format = format;
40     resourceDesc.SampleDesc.Count = sampleCnt;
41     resourceDesc.SampleDesc.Quality = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN;
42     resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;  // use driver-selected swizzle
43     resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
44 
45     D3D12_CLEAR_VALUE clearValue = {};
46     clearValue.Format = format;
47     clearValue.DepthStencil.Depth = 0;
48     clearValue.DepthStencil.Stencil = 0;
49 
50     GrD3DTextureResourceInfo info;
51     if (!GrD3DTextureResource::InitTextureResourceInfo(gpu, resourceDesc,
52                                                        D3D12_RESOURCE_STATE_DEPTH_WRITE,
53                                                        GrProtected::kNo, &clearValue, &info)) {
54         return nullptr;
55     }
56 
57     GrD3DDescriptorHeap::CPUHandle view =
58             gpu->resourceProvider().createDepthStencilView(info.fResource.get());
59 
60     sk_sp<GrD3DResourceState> state(new GrD3DResourceState(info.fResourceState));
61     return sk_sp<GrD3DAttachment>(new GrD3DAttachment(gpu, dimensions,
62                                                       UsageFlags::kStencilAttachment,
63                                                       format, resourceDesc, info,
64                                                       std::move(state), view));
65 }
66 
onRelease()67 void GrD3DAttachment::onRelease() {
68     GrD3DGpu* gpu = this->getD3DGpu();
69     this->releaseResource(gpu);
70 
71     GrAttachment::onRelease();
72 }
73 
onAbandon()74 void GrD3DAttachment::onAbandon() {
75     GrD3DGpu* gpu = this->getD3DGpu();
76     this->releaseResource(gpu);
77 
78     GrAttachment::onAbandon();
79 }
80 
getD3DGpu() const81 GrD3DGpu* GrD3DAttachment::getD3DGpu() const {
82     SkASSERT(!this->wasDestroyed());
83     return static_cast<GrD3DGpu*>(this->getGpu());
84 }
85