24 : fCommandList(
std::move(commandList))
25 , fAllocator(
std::move(allocator)) {
39 this->callFinishedCallbacks();
48 queue->ExecuteCommandLists(1, ppCommandLists);
80 this->callFinishedCallbacks();
93 const D3D12_RESOURCE_TRANSITION_BARRIER* barriers) {
96 for (
int i = 0;
i < numBarriers; ++
i) {
98 D3D12_RESOURCE_BARRIER& newBarrier = fResourceBarriers.
push_back();
99 newBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
100 newBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
101 newBarrier.Transition = barriers[
i];
111 ID3D12Resource* uavResource) {
114 D3D12_RESOURCE_BARRIER& newBarrier = fResourceBarriers.
push_back();
115 newBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
116 newBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
117 newBarrier.UAV.pResource = uavResource;
126 ID3D12Resource* beforeResource,
128 ID3D12Resource* afterResource) {
131 D3D12_RESOURCE_BARRIER& newBarrier = fResourceBarriers.
push_back();
132 newBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
133 newBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
134 newBarrier.Aliasing.pResourceBefore = beforeResource;
135 newBarrier.Aliasing.pResourceAfter = afterResource;
138 if (beforeResource) {
140 this->
addResource(std::move(beforeManagedResource));
146 this->
addResource(std::move(afterManagedResource));
152 if (fResourceBarriers.
size()) {
154 fResourceBarriers.
clear();
161 uint32_t subresourceCount,
162 D3D12_PLACED_SUBRESOURCE_FOOTPRINT* bufferFootprints,
165 SkASSERT(subresourceCount == 1 || (
left == 0 && top == 0));
170 for (uint32_t subresource = 0; subresource < subresourceCount; ++subresource) {
171 D3D12_TEXTURE_COPY_LOCATION
src = {};
172 src.pResource = srcBuffer;
173 src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
174 src.PlacedFootprint = bufferFootprints[subresource];
176 D3D12_TEXTURE_COPY_LOCATION
dst = {};
178 dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
179 dst.SubresourceIndex = subresource;
186 const D3D12_TEXTURE_COPY_LOCATION* dstLocation,
189 const D3D12_TEXTURE_COPY_LOCATION* srcLocation,
190 const D3D12_BOX* srcBox) {
196 fCommandList->CopyTextureRegion(dstLocation, dstX, dstY, 0, srcLocation, srcBox);
200 const D3D12_TEXTURE_COPY_LOCATION* dstLocation,
204 const D3D12_TEXTURE_COPY_LOCATION* srcLocation,
205 const D3D12_BOX* srcBox) {
211 fCommandList->CopyTextureRegion(dstLocation, dstX, dstY, 0, srcLocation, srcBox);
216 UINT subresourceIndex) {
223 ID3D12Resource* dstTexture =
dst->d3dResource();
224 ID3D12Resource* srcTexture =
src->d3dResource();
225 if (subresourceIndex == (
UINT)-1) {
228 SkASSERT(subresourceIndex < src->mipLevels() &&
229 subresourceIndex < dst->mipLevels());
230 D3D12_TEXTURE_COPY_LOCATION srcLoc = {};
231 srcLoc.pResource = srcTexture;
232 srcLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
233 srcLoc.SubresourceIndex = subresourceIndex;
235 D3D12_TEXTURE_COPY_LOCATION dstLoc = {};
236 dstLoc.pResource = dstTexture;
237 dstLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
238 dstLoc.SubresourceIndex = subresourceIndex;
240 fCommandList->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc,
nullptr);
247 ID3D12Resource* srcBuffer, uint64_t srcOffset,
252 ID3D12Resource* dstBuffer =
dst->d3dResource();
253 uint64_t dstSize = dstBuffer->GetDesc().Width;
254 uint64_t srcSize = srcBuffer->GetDesc().Width;
255 if (dstSize == srcSize && srcSize == numBytes) {
258 fCommandList->CopyBufferRegion(dstBuffer, dstOffset, srcBuffer, srcOffset, numBytes);
274 D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator)));
278 allocator.
get(),
nullptr,
279 IID_PPV_ARGS(&commandList)));
283 return std::unique_ptr<GrD3DDirectCommandList>(grCL);
288 bool resolveSubregionSupported)
290 , fResolveSubregionSupported(resolveSubregionSupported) {
291 sk_bzero(fCurrentGraphicsRootDescTable,
sizeof(fCurrentGraphicsRootDescTable));
292 sk_bzero(fCurrentComputeRootDescTable,
sizeof(fCurrentComputeRootDescTable));
295void GrD3DDirectCommandList::onReset() {
296 fCurrentPipeline =
nullptr;
297 fCurrentGraphicsRootSignature =
nullptr;
298 fCurrentComputeRootSignature =
nullptr;
299 fCurrentVertexBuffer =
nullptr;
300 fCurrentVertexStride = 0;
301 fCurrentInstanceBuffer =
nullptr;
302 fCurrentInstanceStride = 0;
303 fCurrentIndexBuffer =
nullptr;
304 fCurrentGraphicsConstantBufferAddress = 0;
305 fCurrentComputeConstantBufferAddress = 0;
306 sk_bzero(fCurrentGraphicsRootDescTable,
sizeof(fCurrentGraphicsRootDescTable));
307 sk_bzero(fCurrentComputeRootDescTable,
sizeof(fCurrentComputeRootDescTable));
308 fCurrentSRVCRVDescriptorHeap =
nullptr;
309 fCurrentSamplerDescriptorHeap =
nullptr;
314 if (pipeline.
get() != fCurrentPipeline) {
317 fCurrentPipeline = pipeline.
get();
333 fCommandList->IASetPrimitiveTopology(primitiveTopology);
342 const D3D12_VIEWPORT* viewports) {
349 if (fCurrentGraphicsRootSignature != rootSig.
get()) {
352 fCurrentGraphicsRootSignature = rootSig.
get();
354 sk_bzero(fCurrentGraphicsRootDescTable,
sizeof(fCurrentGraphicsRootDescTable));
360 if (fCurrentComputeRootSignature != rootSig.
get()) {
363 fCurrentComputeRootSignature = rootSig.
get();
365 sk_bzero(fCurrentComputeRootDescTable,
sizeof(fCurrentComputeRootDescTable));
373 size_t instanceStride) {
374 if (fCurrentVertexBuffer != vertexBuffer.
get() ||
375 fCurrentVertexStride != vertexStride ||
376 fCurrentInstanceBuffer != instanceBuffer.
get() ||
377 fCurrentInstanceStride != instanceStride) {
379 fCurrentVertexBuffer = vertexBuffer.
get();
380 fCurrentVertexStride = vertexStride;
381 fCurrentInstanceBuffer = instanceBuffer.
get();
382 fCurrentInstanceStride = instanceStride;
384 D3D12_VERTEX_BUFFER_VIEW views[2];
387 auto* d3dBuffer =
static_cast<const GrD3DBuffer*
>(vertexBuffer.
get());
388 views[numViews].BufferLocation = d3dBuffer->
d3dResource()->GetGPUVirtualAddress();
389 views[numViews].SizeInBytes = vertexBuffer->
size();
390 views[numViews++].StrideInBytes = vertexStride;
393 if (instanceBuffer) {
394 auto* d3dBuffer =
static_cast<const GrD3DBuffer*
>(instanceBuffer.
get());
395 views[numViews].BufferLocation = d3dBuffer->
d3dResource()->GetGPUVirtualAddress();
396 views[numViews].SizeInBytes = instanceBuffer->
size();
397 views[numViews++].StrideInBytes = instanceStride;
400 fCommandList->IASetVertexBuffers(startSlot, numViews, views);
405 if (fCurrentIndexBuffer != indexBuffer.
get()) {
406 auto* d3dBuffer =
static_cast<const GrD3DBuffer*
>(indexBuffer.
get());
408 D3D12_INDEX_BUFFER_VIEW view = {};
409 view.BufferLocation = d3dBuffer->
d3dResource()->GetGPUVirtualAddress();
410 view.SizeInBytes = indexBuffer->
size();
411 view.Format = DXGI_FORMAT_R16_UINT;
414 fCurrentIndexBuffer = indexBuffer.
get();
420 unsigned int startVertex,
unsigned int startInstance) {
423 fCommandList->DrawInstanced(vertexCount, instanceCount, startVertex, startInstance);
427 unsigned int instanceCount,
428 unsigned int startIndex,
429 unsigned int baseVertex,
430 unsigned int startInstance) {
433 fCommandList->DrawIndexedInstanced(indexCount, instanceCount, startIndex, baseVertex,
438 unsigned int maxCommandCount,
440 size_t argumentBufferOffset) {
445 argumentBuffer->
d3dResource(), argumentBufferOffset,
447 this->
addGrBuffer(sk_ref_sp<const GrBuffer>(argumentBuffer));
452 unsigned int threadGroupCountY,
453 unsigned int threadGroupCountZ) {
456 fCommandList->Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
460 std::array<float, 4>
color,
461 const D3D12_RECT*
rect) {
465 if (msaaTextureResource && msaaTextureResource != renderTarget) {
468 unsigned int numRects =
rect ? 1 : 0;
474 uint8_t stencilClearValue,
475 const D3D12_RECT*
rect) {
478 unsigned int numRects =
rect ? 1 : 0;
479 fCommandList->ClearDepthStencilView(stencil->
view(), D3D12_CLEAR_FLAG_STENCIL, 0,
480 stencilClearValue, numRects,
rect);
487 if (msaaTextureResource && msaaTextureResource != renderTarget) {
492 D3D12_CPU_DESCRIPTOR_HANDLE dsDescriptor;
493 D3D12_CPU_DESCRIPTOR_HANDLE* dsDescriptorPtr =
nullptr;
497 dsDescriptor = d3dStencil->
view();
498 dsDescriptorPtr = &dsDescriptor;
501 fCommandList->OMSetRenderTargets(1, &rtvDescriptor,
false, dsDescriptorPtr);
505 unsigned int dstX,
unsigned int dstY,
507 D3D12_RECT* srcRect) {
515 if (fResolveSubregionSupported) {
519 commandList1->ResolveSubresourceRegion(dstTexture->
d3dResource(), 0, dstX, dstY,
522 D3D12_RESOLVE_MODE_AVERAGE);
532 unsigned int rootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS bufferLocation) {
535 if (bufferLocation != fCurrentGraphicsConstantBufferAddress) {
536 fCommandList->SetGraphicsRootConstantBufferView(rootParameterIndex, bufferLocation);
537 fCurrentGraphicsConstantBufferAddress = bufferLocation;
542 unsigned int rootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS bufferLocation) {
545 if (bufferLocation != fCurrentComputeConstantBufferAddress) {
546 fCommandList->SetComputeRootConstantBufferView(rootParameterIndex, bufferLocation);
547 fCurrentComputeConstantBufferAddress = bufferLocation;
552 unsigned int rootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor) {
555 rootParameterIndex ==
557 if (fCurrentGraphicsRootDescTable[rootParameterIndex].ptr != baseDescriptor.ptr) {
558 fCommandList->SetGraphicsRootDescriptorTable(rootParameterIndex, baseDescriptor);
559 fCurrentGraphicsRootDescTable[rootParameterIndex] = baseDescriptor;
564 unsigned int rootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor) {
567 rootParameterIndex ==
569 if (fCurrentComputeRootDescTable[rootParameterIndex].ptr != baseDescriptor.ptr) {
570 fCommandList->SetComputeRootDescriptorTable(rootParameterIndex, baseDescriptor);
571 fCurrentComputeRootDescTable[rootParameterIndex] = baseDescriptor;
578 ID3D12DescriptorHeap* samplerDescriptorHeap) {
579 if (srvCrvDescriptorHeap != fCurrentSRVCRVDescriptorHeap ||
580 samplerDescriptorHeap != fCurrentSamplerDescriptorHeap) {
581 ID3D12DescriptorHeap* heaps[2] = {
582 srvCrvDescriptorHeap,
583 samplerDescriptorHeap
587 fCurrentSRVCRVDescriptorHeap = srvCrvDescriptorHeap;
588 fCurrentSamplerDescriptorHeap = samplerDescriptorHeap;
602 IID_PPV_ARGS(&allocator)));
606 nullptr, IID_PPV_ARGS(&commandList)));
608 return std::unique_ptr<GrD3DCopyCommandList>(grCL);
sk_bzero(glyphs, sizeof(glyphs))
#define GR_D3D_CALL_ERRCHECK(X)
static SkString resource(SkPDFResourceType type, int index)
static bool left(const SkPoint &p0, const SkPoint &p1)
virtual size_t size() const =0
D3D12_CPU_DESCRIPTOR_HANDLE view() const
ID3D12Resource * d3dResource() const
bool resolveSubresourceRegionSupport() const
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 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 submitResourceBarriers()
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)
TrackedResourceArray< sk_sp< GrRecycledResource > > fTrackedRecycledResources
TrackedResourceArray< sk_sp< GrManagedResource > > fTrackedResources
void addFinishedCallback(sk_sp< skgpu::RefCntedCallback > callback)
ID3D12CommandSignature * commandSignature() const
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)
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)
const GrD3DCaps & d3dCaps() const
ID3D12Device * device() const
ID3D12PipelineState * d3dPipelineState() const
const GrD3DTextureResource * msaaTextureResource() const
D3D12_CPU_DESCRIPTOR_HANDLE colorRenderTargetView() const
@ kShaderViewDescriptorTable
@ kSamplerDescriptorTable
ID3D12RootSignature * rootSignature() const
DXGI_FORMAT dxgiFormat() const
ID3D12Resource * d3dResource() const
D3D12_RESOURCE_STATES currentState() const
sk_sp< Resource > resource() const
GrAttachment * getStencilAttachment(bool useMSAASurface) const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
sk_sp< SkBlender > blender SkRect rect
#define TRACE_EVENT0(category_group, name)