Flutter Engine
The Flutter Engine
GrD3DCommandList.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 GrD3DCommandList_DEFINED
9#define GrD3DCommandList_DEFINED
10
11#include "include/gpu/GrTypes.h"
17
18#include <memory>
19
20class GrD3DGpu;
21class GrD3DBuffer;
23class GrD3DConstantRingBuffer;
24class GrD3DPipeline;
27class GrD3DAttachment;
28class GrD3DTexture;
30
31class GrScissorState;
32
34public:
36 this->releaseResources();
37 }
38
39 enum class SubmitResult {
40 kNoWork,
42 kFailure,
43 };
44 SubmitResult submit(ID3D12CommandQueue* queue);
45
46 bool close();
47 void reset();
48
49 ////////////////////////////////////////////////////////////////////////////
50 // GraphicsCommandList commands
51 ////////////////////////////////////////////////////////////////////////////
52
53 // All barriers should reference subresources of managedResource
54 void resourceBarrier(sk_sp<GrManagedResource> managedResource,
55 int numBarriers,
56 const D3D12_RESOURCE_TRANSITION_BARRIER* barriers);
57
58 void uavBarrier(sk_sp<GrManagedResource> managedResource,
59 ID3D12Resource* uavResource);
60
61 void aliasingBarrier(sk_sp<GrManagedResource> beforeManagedResource,
62 ID3D12Resource* beforeResource,
63 sk_sp<GrManagedResource> afterManagedResource,
64 ID3D12Resource* afterResource);
65
66 // Helper method that calls copyTextureRegion multiple times, once for each subresource
67 // The srcBuffer comes from a staging buffer so we don't need to take any refs to it. Instead,
68 // we ref the whole buffer during sumbit.
69 void copyBufferToTexture(ID3D12Resource* srcBuffer,
70 const GrD3DTextureResource* dstTexture,
71 uint32_t subresourceCount,
72 D3D12_PLACED_SUBRESOURCE_FOOTPRINT* bufferFootprints,
73 int left, int top);
74
76 const D3D12_TEXTURE_COPY_LOCATION* dstLocation,
77 UINT dstX, UINT dstY,
79 const D3D12_TEXTURE_COPY_LOCATION* srcLocation,
80 const D3D12_BOX* srcBox);
81
83 const D3D12_TEXTURE_COPY_LOCATION* dstLocation,
84 UINT dstX,
85 UINT dstY,
87 const D3D12_TEXTURE_COPY_LOCATION* srcLocation,
88 const D3D12_BOX* srcBox);
89
91 const GrD3DTexture* src,
92 UINT subresourceIndex = -1);
93
94 // We don't take a ref to the src buffer because we assume the src buffer is coming from a
95 // staging buffer which will get ref'd during submit.
96 void copyBufferToBuffer(sk_sp<GrD3DBuffer> dstBuffer, uint64_t dstOffset,
97 ID3D12Resource* srcBuffer, uint64_t srcOffset,
98 uint64_t numBytes);
99
101 fTrackedGpuBuffers.push_back(std::move(buffer));
102 }
103
104 // Add ref-counted resource that will be tracked and released when this command buffer finishes
105 // execution. When it is released, it will signal that the resource can be recycled for reuse.
107 fTrackedRecycledResources.push_back(std::move(resource));
108 }
109
110 void releaseResources();
111
112 bool hasWork() const { return fHasWork; }
113
115
116private:
117 static const int kInitialTrackedResourcesCount = 32;
118
119protected:
122
123 // Add ref-counted resource that will be tracked and released when this command buffer finishes
124 // execution
127 fTrackedResources.push_back(std::move(resource));
128 }
129
130 void addingWork();
131 virtual void onReset() {}
132
134
136
137 template<typename T>
142
143
144 // When we create a command list it starts in an active recording state
145 SkDEBUGCODE(bool fIsActive = true;)
146 bool fHasWork = false;
147
148private:
149 void callFinishedCallbacks() { fFinishedCallbacks.clear(); }
150
152
154
156};
157
159public:
160 static std::unique_ptr<GrD3DDirectCommandList> Make(GrD3DGpu* gpu);
161
162 ~GrD3DDirectCommandList() override = default;
163
164 void setPipelineState(const sk_sp<GrD3DPipeline>& pipeline);
165
166 void setStencilRef(unsigned int stencilRef);
167 void setBlendFactor(const float blendFactor[4]);
168 void setPrimitiveTopology(D3D12_PRIMITIVE_TOPOLOGY primitiveTopology);
169 void setScissorRects(unsigned int numRects, const D3D12_RECT* rects);
170 void setViewports(unsigned int numViewports, const D3D12_VIEWPORT* viewports);
171 void setGraphicsRootSignature(const sk_sp<GrD3DRootSignature>& rootSignature);
172 void setComputeRootSignature(const sk_sp<GrD3DRootSignature>& rootSignature);
173 void setVertexBuffers(unsigned int startSlot,
174 sk_sp<const GrBuffer> vertexBuffer, size_t vertexStride,
175 sk_sp<const GrBuffer> instanceBuffer, size_t instanceStride);
176 void setIndexBuffer(sk_sp<const GrBuffer> indexBuffer);
177 void drawInstanced(unsigned int vertexCount, unsigned int instanceCount,
178 unsigned int startVertex, unsigned int startInstance);
179 void drawIndexedInstanced(unsigned int indexCount, unsigned int instanceCount,
180 unsigned int startIndex, unsigned int baseVertex,
181 unsigned int startInstance);
182 void executeIndirect(const sk_sp<GrD3DCommandSignature> commandSig, unsigned int maxCommandCnt,
183 const GrD3DBuffer* argumentBuffer, size_t argumentBufferOffset);
184 void dispatch(unsigned int threadGroupCountX, unsigned int threadGroupCountY,
185 unsigned int threadGroupCountZ = 1);
186
187 void clearRenderTargetView(const GrD3DRenderTarget* renderTarget,
188 std::array<float, 4> color,
189 const D3D12_RECT* rect);
191 uint8_t stencilClearValue,
192 const D3D12_RECT* rect);
193 void setRenderTarget(const GrD3DRenderTarget* renderTarget);
194 void resolveSubresourceRegion(const GrD3DTextureResource* dstTexture,
195 unsigned int dstX, unsigned int dstY,
196 const GrD3DTextureResource* srcTexture,
197 D3D12_RECT* srcRect);
198
199 void setGraphicsRootConstantBufferView(unsigned int rootParameterIndex,
200 D3D12_GPU_VIRTUAL_ADDRESS bufferLocation);
201 void setGraphicsRootDescriptorTable(unsigned int rootParameterIndex,
202 D3D12_GPU_DESCRIPTOR_HANDLE bufferLocation);
203 void setComputeRootConstantBufferView(unsigned int rootParameterIndex,
204 D3D12_GPU_VIRTUAL_ADDRESS bufferLocation);
205 void setComputeRootDescriptorTable(unsigned int rootParameterIndex,
206 D3D12_GPU_DESCRIPTOR_HANDLE bufferLocation);
207 void setDescriptorHeaps(ID3D12DescriptorHeap* srvDescriptorHeap,
208 ID3D12DescriptorHeap* samplerDescriptorHeap);
209
211
212private:
215 bool resolveSubregionSupported);
216
217 void onReset() override;
218
219 const GrD3DPipeline* fCurrentPipeline = nullptr;
220 const GrD3DRootSignature* fCurrentGraphicsRootSignature = nullptr;
221 const GrD3DRootSignature* fCurrentComputeRootSignature = nullptr;
222 const GrBuffer* fCurrentVertexBuffer = nullptr;
223 size_t fCurrentVertexStride = 0;
224 const GrBuffer* fCurrentInstanceBuffer = nullptr;
225 size_t fCurrentInstanceStride = 0;
226 const GrBuffer* fCurrentIndexBuffer = nullptr;
227
228 D3D12_GPU_VIRTUAL_ADDRESS fCurrentGraphicsConstantBufferAddress = 0;
229 D3D12_GPU_VIRTUAL_ADDRESS fCurrentComputeConstantBufferAddress = 0;
230 D3D12_GPU_DESCRIPTOR_HANDLE fCurrentGraphicsRootDescTable[GrD3DRootSignature::kParamIndexCount];
231 D3D12_GPU_DESCRIPTOR_HANDLE fCurrentComputeRootDescTable[GrD3DRootSignature::kParamIndexCount];
232 const ID3D12DescriptorHeap* fCurrentSRVCRVDescriptorHeap = nullptr;
233 const ID3D12DescriptorHeap* fCurrentSamplerDescriptorHeap = nullptr;
234
235 bool fResolveSubregionSupported;
236};
237
239public:
240 static std::unique_ptr<GrD3DCopyCommandList> Make(GrD3DGpu* gpu);
241
242private:
245};
246#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkString resource(SkPDFResourceType type, int index)
static bool left(const SkPoint &p0, const SkPoint &p1)
void addGrBuffer(sk_sp< const GrBuffer > buffer)
SkDEBUGCODE(bool fIsActive=true;) bool fHasWork
gr_cp< ID3D12GraphicsCommandList > fCommandList
bool hasWork() const
TrackedResourceArray< sk_sp< const GrBuffer > > fTrackedGpuBuffers
void aliasingBarrier(sk_sp< GrManagedResource > beforeManagedResource, ID3D12Resource *beforeResource, sk_sp< GrManagedResource > afterManagedResource, ID3D12Resource *afterResource)
void addRecycledResource(sk_sp< GrRecycledResource > resource)
virtual void onReset()
void copyTextureToTexture(const GrD3DTexture *dst, const GrD3DTexture *src, UINT subresourceIndex=-1)
void resourceBarrier(sk_sp< GrManagedResource > managedResource, int numBarriers, const D3D12_RESOURCE_TRANSITION_BARRIER *barriers)
SubmitResult submit(ID3D12CommandQueue *queue)
GrD3DCommandList(gr_cp< ID3D12CommandAllocator > allocator, gr_cp< ID3D12GraphicsCommandList > commandList)
void copyTextureRegionToTexture(sk_sp< GrManagedResource > dst, const D3D12_TEXTURE_COPY_LOCATION *dstLocation, UINT dstX, UINT dstY, sk_sp< GrManagedResource > src, const D3D12_TEXTURE_COPY_LOCATION *srcLocation, const D3D12_BOX *srcBox)
void uavBarrier(sk_sp< GrManagedResource > managedResource, ID3D12Resource *uavResource)
void copyBufferToTexture(ID3D12Resource *srcBuffer, const GrD3DTextureResource *dstTexture, uint32_t subresourceCount, D3D12_PLACED_SUBRESOURCE_FOOTPRINT *bufferFootprints, int left, int top)
void copyTextureRegionToBuffer(sk_sp< const GrBuffer > dst, const D3D12_TEXTURE_COPY_LOCATION *dstLocation, UINT dstX, UINT dstY, sk_sp< GrManagedResource > src, const D3D12_TEXTURE_COPY_LOCATION *srcLocation, const D3D12_BOX *srcBox)
void addResource(sk_sp< GrManagedResource > resource)
void copyBufferToBuffer(sk_sp< GrD3DBuffer > dstBuffer, uint64_t dstOffset, ID3D12Resource *srcBuffer, uint64_t srcOffset, uint64_t numBytes)
virtual ~GrD3DCommandList()
TrackedResourceArray< sk_sp< GrRecycledResource > > fTrackedRecycledResources
TrackedResourceArray< sk_sp< GrManagedResource > > fTrackedResources
void addFinishedCallback(sk_sp< skgpu::RefCntedCallback > callback)
static std::unique_ptr< GrD3DCopyCommandList > Make(GrD3DGpu *gpu)
void clearRenderTargetView(const GrD3DRenderTarget *renderTarget, std::array< float, 4 > color, const D3D12_RECT *rect)
void executeIndirect(const sk_sp< GrD3DCommandSignature > commandSig, unsigned int maxCommandCnt, const GrD3DBuffer *argumentBuffer, size_t argumentBufferOffset)
void setComputeRootConstantBufferView(unsigned int rootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS bufferLocation)
void addSampledTextureRef(GrD3DTexture *)
void setComputeRootDescriptorTable(unsigned int rootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE bufferLocation)
void setGraphicsRootSignature(const sk_sp< GrD3DRootSignature > &rootSignature)
void setStencilRef(unsigned int stencilRef)
void setPrimitiveTopology(D3D12_PRIMITIVE_TOPOLOGY primitiveTopology)
void setGraphicsRootConstantBufferView(unsigned int rootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS bufferLocation)
void setVertexBuffers(unsigned int startSlot, sk_sp< const GrBuffer > vertexBuffer, size_t vertexStride, sk_sp< const GrBuffer > instanceBuffer, size_t instanceStride)
void setDescriptorHeaps(ID3D12DescriptorHeap *srvDescriptorHeap, ID3D12DescriptorHeap *samplerDescriptorHeap)
static std::unique_ptr< GrD3DDirectCommandList > Make(GrD3DGpu *gpu)
void setRenderTarget(const GrD3DRenderTarget *renderTarget)
void setBlendFactor(const float blendFactor[4])
void resolveSubresourceRegion(const GrD3DTextureResource *dstTexture, unsigned int dstX, unsigned int dstY, const GrD3DTextureResource *srcTexture, D3D12_RECT *srcRect)
void setViewports(unsigned int numViewports, const D3D12_VIEWPORT *viewports)
~GrD3DDirectCommandList() override=default
void clearDepthStencilView(const GrD3DAttachment *, uint8_t stencilClearValue, const D3D12_RECT *rect)
void setIndexBuffer(sk_sp< const GrBuffer > indexBuffer)
void setPipelineState(const sk_sp< GrD3DPipeline > &pipeline)
void setScissorRects(unsigned int numRects, const D3D12_RECT *rects)
void dispatch(unsigned int threadGroupCountX, unsigned int threadGroupCountY, unsigned int threadGroupCountZ=1)
void setComputeRootSignature(const sk_sp< GrD3DRootSignature > &rootSignature)
void drawInstanced(unsigned int vertexCount, unsigned int instanceCount, unsigned int startVertex, unsigned int startInstance)
void setGraphicsRootDescriptorTable(unsigned int rootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE bufferLocation)
void drawIndexedInstanced(unsigned int indexCount, unsigned int instanceCount, unsigned int startIndex, unsigned int baseVertex, unsigned int startInstance)
static constexpr unsigned int kParamIndexCount
DlColor color
@ kSuccess
Definition: embedder.h:73
VkQueue queue
Definition: main.cc:55
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
dst
Definition: cp.py:12
unsigned int UINT
Definition: windows_types.h:32