Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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,
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
90 void copyTextureToTexture(const GrD3DTexture* dst,
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
126 SkASSERT(resource);
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
SkColor4f color
#define SkASSERT(cond)
Definition SkAssert.h:116
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
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)
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
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static const uint8_t buffer[]
unsigned int UINT