Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
GrD3DGpu Class Reference

#include <GrD3DGpu.h>

Inheritance diagram for GrD3DGpu:
GrGpu

Public Member Functions

 ~GrD3DGpu () override
 
const GrD3DCapsd3dCaps () const
 
GrD3DResourceProviderresourceProvider ()
 
GrThreadSafePipelineBuilderpipelineBuilder () override
 
sk_sp< GrThreadSafePipelineBuilderrefPipelineBuilder () override
 
ID3D12Device * device () const
 
ID3D12CommandQueue * queue () const
 
GrD3DMemoryAllocatormemoryAllocator () const
 
GrD3DDirectCommandListcurrentCommandList () const
 
GrStagingBufferManagerstagingBufferManager () override
 
void takeOwnershipOfBuffer (sk_sp< GrGpuBuffer >) override
 
GrRingBufferuniformsRingBuffer () override
 
bool protectedContext () const
 
void xferBarrier (GrRenderTarget *, GrXferBarrierType) override
 
void deleteBackendTexture (const GrBackendTexture &) override
 
bool compile (const GrProgramDesc &, const GrProgramInfo &) override
 
sk_sp< GrAttachmentmakeStencilAttachment (const GrBackendFormat &, SkISize dimensions, int numStencilSamples) override
 
GrBackendFormat getPreferredStencilFormat (const GrBackendFormat &) override
 
sk_sp< GrAttachmentmakeMSAAAttachment (SkISize dimensions, const GrBackendFormat &format, int numSamples, GrProtected isProtected, GrMemoryless isMemoryless) override
 
void addResourceBarriers (sk_sp< GrManagedResource > resource, int numBarriers, D3D12_RESOURCE_TRANSITION_BARRIER *barriers) const
 
void addBufferResourceBarriers (GrD3DBuffer *buffer, int numBarriers, D3D12_RESOURCE_TRANSITION_BARRIER *barriers) const
 
std::unique_ptr< GrSemaphoremakeSemaphore (bool isOwned) override
 
std::unique_ptr< GrSemaphorewrapBackendSemaphore (const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership) override
 
void insertSemaphore (GrSemaphore *semaphore) override
 
void waitSemaphore (GrSemaphore *semaphore) override
 
std::unique_ptr< GrSemaphoreprepareTextureForCrossContextUsage (GrTexture *) override
 
void submit (GrOpsRenderPass *renderPass) override
 
void endRenderPass (GrRenderTarget *target, GrSurfaceOrigin origin, const SkIRect &bounds)
 
void checkFinishProcs () override
 
void finishOutstandingGpuWork () override
 
- Public Member Functions inherited from GrGpu
 GrGpu (GrDirectContext *direct)
 
virtual ~GrGpu ()
 
GrDirectContextgetContext ()
 
const GrDirectContextgetContext () const
 
const GrCapscaps () const
 
sk_sp< const GrCapsrefCaps () const
 
virtual void disconnect (DisconnectType)
 
virtual bool isDeviceLost () const
 
void markContextDirty (uint32_t state=kAll_GrBackendState)
 
sk_sp< GrTexturecreateTexture (SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Budgeted budgeted, GrProtected isProtected, GrColorType textureColorType, GrColorType srcColorType, const GrMipLevel texels[], int texelLevelCount, std::string_view label)
 
sk_sp< GrTexturecreateTexture (SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, GrProtected isProtected, std::string_view label)
 
sk_sp< GrTexturecreateCompressedTexture (SkISize dimensions, const GrBackendFormat &format, skgpu::Budgeted budgeted, skgpu::Mipmapped mipmapped, GrProtected isProtected, const void *data, size_t dataSize)
 
sk_sp< GrTexturewrapBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType)
 
sk_sp< GrTexturewrapCompressedBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable)
 
sk_sp< GrTexturewrapRenderableBackendTexture (const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable)
 
sk_sp< GrRenderTargetwrapBackendRenderTarget (const GrBackendRenderTarget &)
 
sk_sp< GrRenderTargetwrapVulkanSecondaryCBAsRenderTarget (const SkImageInfo &, const GrVkDrawableInfo &)
 
sk_sp< GrGpuBuffercreateBuffer (size_t size, GrGpuBufferType intendedType, GrAccessPattern accessPattern)
 
void resolveRenderTarget (GrRenderTarget *, const SkIRect &resolveRect)
 
bool regenerateMipMapLevels (GrTexture *)
 
void resetTextureBindings ()
 
bool readPixels (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType dstColorType, void *buffer, size_t rowBytes)
 
bool writePixels (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling=false)
 
bool writePixels (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType srcColorType, const void *buffer, size_t rowBytes, bool prepForTexSampling=false)
 
bool transferFromBufferToBuffer (sk_sp< GrGpuBuffer > src, size_t srcOffset, sk_sp< GrGpuBuffer > dst, size_t dstOffset, size_t size)
 
bool transferPixelsTo (GrTexture *texture, SkIRect rect, GrColorType textureColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset, size_t rowBytes)
 
bool transferPixelsFrom (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset)
 
bool copySurface (GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter filter)
 
GrOpsRenderPassgetOpsRenderPass (GrRenderTarget *renderTarget, bool useMSAASurface, GrAttachment *stencil, GrSurfaceOrigin, const SkIRect &bounds, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies, GrXferBarrierFlags renderPassXferBarriers)
 
void executeFlushInfo (SkSpan< GrSurfaceProxy * >, SkSurfaces::BackendSurfaceAccess access, const GrFlushInfo &, const skgpu::MutableTextureState *newState)
 
virtual void willExecute ()
 
bool submitToGpu (GrSyncCpu sync)
 
bool checkAndResetOOMed ()
 
virtual void releaseUnlockedBackendObjects ()
 
Statsstats ()
 
void dumpJSON (SkJSONWriter *) const
 
GrBackendTexture createBackendTexture (SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label)
 
bool clearBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color)
 
GrBackendTexture createCompressedBackendTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, GrProtected)
 
bool updateCompressedBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t length)
 
virtual bool setBackendTextureState (const GrBackendTexture &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState, sk_sp< skgpu::RefCntedCallback > finishedCallback)
 
virtual bool setBackendRenderTargetState (const GrBackendRenderTarget &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState, sk_sp< skgpu::RefCntedCallback > finishedCallback)
 
virtual bool precompileShader (const SkData &key, const SkData &data)
 
void handleDirtyContext ()
 
virtual void storeVkPipelineCacheData ()
 

Static Public Member Functions

static std::unique_ptr< GrGpuMake (const GrD3DBackendContext &backendContext, const GrContextOptions &, GrDirectContext *)
 

Private Member Functions

sk_sp< GrTextureonCreateTexture (SkISize, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, skgpu::Budgeted, GrProtected, int mipLevelCount, uint32_t levelClearMask, std::string_view label) override
 
sk_sp< GrTextureonCreateCompressedTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, const void *data, size_t dataSize) override
 
sk_sp< GrTextureonWrapBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType) override
 
sk_sp< GrTextureonWrapCompressedBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable) override
 
sk_sp< GrTextureonWrapRenderableBackendTexture (const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable) override
 
sk_sp< GrRenderTargetonWrapBackendRenderTarget (const GrBackendRenderTarget &) override
 
sk_sp< GrGpuBufferonCreateBuffer (size_t sizeInBytes, GrGpuBufferType, GrAccessPattern) override
 
bool onReadPixels (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType dstColorType, void *, size_t rowBytes) override
 
bool onWritePixels (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel[], int mipLevelCount, bool prepForTexSampling) override
 
bool onTransferFromBufferToBuffer (sk_sp< GrGpuBuffer > src, size_t srcOffset, sk_sp< GrGpuBuffer > dst, size_t dstOffset, size_t size) override
 
bool onTransferPixelsTo (GrTexture *, SkIRect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer >, size_t offset, size_t rowBytes) override
 
bool onTransferPixelsFrom (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer >, size_t offset) override
 
bool onCopySurface (GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter) override
 
bool onRegenerateMipMapLevels (GrTexture *) override
 
void onResolveRenderTarget (GrRenderTarget *target, const SkIRect &) override
 
void addFinishedProc (GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext) override
 
GrOpsRenderPassonGetOpsRenderPass (GrRenderTarget *, bool useMSAASurface, GrAttachment *, GrSurfaceOrigin, const SkIRect &, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies, GrXferBarrierFlags renderPassXferBarriers) override
 
void prepareSurfacesForBackendAccessAndStateUpdates (SkSpan< GrSurfaceProxy * > proxies, SkSurfaces::BackendSurfaceAccess access, const skgpu::MutableTextureState *newState) override
 
bool onSubmitToGpu (GrSyncCpu sync) override
 
GrBackendTexture onCreateBackendTexture (SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label) override
 
bool onClearBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color) override
 
GrBackendTexture onCreateCompressedBackendTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, GrProtected) override
 
bool onUpdateCompressedBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t size) override
 

Additional Inherited Members

- Public Types inherited from GrGpu
enum class  DisconnectType { kAbandon , kCleanup }
 
- Protected Member Functions inherited from GrGpu
void didWriteToSurface (GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds, uint32_t mipLevels=1) const
 
void setOOMed ()
 
void initCaps (sk_sp< const GrCaps > caps)
 
- Static Protected Member Functions inherited from GrGpu
static bool CompressedDataIsCorrect (SkISize dimensions, SkTextureCompressionType, skgpu::Mipmapped, const void *data, size_t length)
 
- Protected Attributes inherited from GrGpu
Stats fStats
 

Detailed Description

Definition at line 28 of file GrD3DGpu.h.

Constructor & Destructor Documentation

◆ ~GrD3DGpu()

GrD3DGpu::~GrD3DGpu ( )
override

Definition at line 109 of file GrD3DGpu.cpp.

109 {
110 this->destroyResources();
111}

Member Function Documentation

◆ addBufferResourceBarriers()

void GrD3DGpu::addBufferResourceBarriers ( GrD3DBuffer buffer,
int  numBarriers,
D3D12_RESOURCE_TRANSITION_BARRIER *  barriers 
) const

Definition at line 1729 of file GrD3DGpu.cpp.

1731 {
1732 SkASSERT(fCurrentDirectCommandList);
1734
1735 fCurrentDirectCommandList->resourceBarrier(nullptr, numBarriers, barriers);
1736 fCurrentDirectCommandList->addGrBuffer(sk_ref_sp<const GrBuffer>(buffer));
1737}
#define SkASSERT(cond)
Definition SkAssert.h:116
static const uint8_t buffer[]

◆ addFinishedProc()

void GrD3DGpu::addFinishedProc ( GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 245 of file GrD3DGpu.cpp.

246 {
247 SkASSERT(finishedProc);
248 this->addFinishedCallback(skgpu::RefCntedCallback::Make(finishedProc, finishedContext));
249}
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)

◆ addResourceBarriers()

void GrD3DGpu::addResourceBarriers ( sk_sp< GrManagedResource resource,
int  numBarriers,
D3D12_RESOURCE_TRANSITION_BARRIER *  barriers 
) const

Definition at line 1720 of file GrD3DGpu.cpp.

1722 {
1723 SkASSERT(fCurrentDirectCommandList);
1724 SkASSERT(resource);
1725
1726 fCurrentDirectCommandList->resourceBarrier(std::move(resource), numBarriers, barriers);
1727}

◆ checkFinishProcs()

void GrD3DGpu::checkFinishProcs ( )
inlineoverridevirtual

Implements GrGpu.

Definition at line 117 of file GrD3DGpu.h.

117{ this->checkForFinishedCommandLists(); }

◆ compile()

bool GrD3DGpu::compile ( const GrProgramDesc ,
const GrProgramInfo  
)
overridevirtual

In this case we have a program descriptor and a program info but no render target.

Implements GrGpu.

Definition at line 1649 of file GrD3DGpu.cpp.

1649 {
1650 return false;
1651}

◆ currentCommandList()

GrD3DDirectCommandList * GrD3DGpu::currentCommandList ( ) const
inline

Definition at line 48 of file GrD3DGpu.h.

48{ return fCurrentDirectCommandList.get(); }

◆ d3dCaps()

const GrD3DCaps & GrD3DGpu::d3dCaps ( ) const
inline

Definition at line 36 of file GrD3DGpu.h.

36{ return static_cast<const GrD3DCaps&>(*this->caps()); }
const GrCaps * caps() const
Definition GrGpu.h:73

◆ deleteBackendTexture()

void GrD3DGpu::deleteBackendTexture ( const GrBackendTexture )
overridevirtual

Frees a texture created by createBackendTexture(). If ownership of the backend texture has been transferred to a context using adopt semantics this should not be called.

Implements GrGpu.

Definition at line 1644 of file GrD3DGpu.cpp.

1644 {
1645 SkASSERT(GrBackendApi::kDirect3D == tex.fBackend);
1646 // Nothing to do here, will get cleaned up when the GrBackendTexture object goes away
1647}

◆ device()

ID3D12Device * GrD3DGpu::device ( ) const
inline

Definition at line 43 of file GrD3DGpu.h.

43{ return fDevice.get(); }
T * get() const
Definition GrD3DTypes.h:108

◆ endRenderPass()

void GrD3DGpu::endRenderPass ( GrRenderTarget target,
GrSurfaceOrigin  origin,
const SkIRect bounds 
)

Definition at line 240 of file GrD3DGpu.cpp.

241 {
242 this->didWriteToSurface(target, origin, &bounds);
243}
void didWriteToSurface(GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds, uint32_t mipLevels=1) const
Definition GrGpu.cpp:665

◆ finishOutstandingGpuWork()

void GrD3DGpu::finishOutstandingGpuWork ( )
overridevirtual

Implements GrGpu.

Definition at line 1800 of file GrD3DGpu.cpp.

1800 {
1801 this->waitForQueueCompletion();
1802}

◆ getPreferredStencilFormat()

GrBackendFormat GrD3DGpu::getPreferredStencilFormat ( const GrBackendFormat )
inlineoverridevirtual

Implements GrGpu.

Definition at line 83 of file GrD3DGpu.h.

83 {
84 return GrBackendFormat::MakeDxgi(this->d3dCaps().preferredStencilFormat());
85 }
const GrD3DCaps & d3dCaps() const
Definition GrD3DGpu.h:36

◆ insertSemaphore()

void GrD3DGpu::insertSemaphore ( GrSemaphore semaphore)
overridevirtual

Implements GrGpu.

Definition at line 1786 of file GrD3DGpu.cpp.

1786 {
1787 SkASSERT(semaphore);
1788 GrD3DSemaphore* d3dSem = static_cast<GrD3DSemaphore*>(semaphore);
1789 // TODO: Do we need to track the lifetime of this? How do we know it's done?
1790 fQueue->Signal(d3dSem->fence(), d3dSem->value());
1791}
uint64_t value() const
ID3D12Fence * fence() const

◆ Make()

std::unique_ptr< GrGpu > GrD3DGpu::Make ( const GrD3DBackendContext backendContext,
const GrContextOptions contextOptions,
GrDirectContext direct 
)
static

Definition at line 50 of file GrD3DGpu.cpp.

52 {
54 if (!memoryAllocator) {
55 // We were not given a memory allocator at creation
57 backendContext.fAdapter.get(), backendContext.fDevice.get());
58 }
59 if (!memoryAllocator) {
60 SkDEBUGFAIL("No supplied Direct3D memory allocator and unable to create one internally.");
61 return nullptr;
62 }
63
64 return std::unique_ptr<GrGpu>(new GrD3DGpu(direct,
65 contextOptions,
66 backendContext,
68}
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118
static sk_sp< GrD3DMemoryAllocator > Make(IDXGIAdapter *adapter, ID3D12Device *device)
GrD3DMemoryAllocator * memoryAllocator() const
Definition GrD3DGpu.h:46
gr_cp< ID3D12Device > fDevice
sk_sp< GrD3DMemoryAllocator > fMemoryAllocator
gr_cp< IDXGIAdapter1 > fAdapter

◆ makeMSAAAttachment()

sk_sp< GrAttachment > GrD3DGpu::makeMSAAAttachment ( SkISize  dimensions,
const GrBackendFormat format,
int  numSamples,
GrProtected  isProtected,
GrMemoryless  isMemoryless 
)
inlineoverridevirtual

Implements GrGpu.

Definition at line 87 of file GrD3DGpu.h.

91 {
92 return nullptr;
93 }

◆ makeSemaphore()

std::unique_ptr< GrSemaphore > GrD3DGpu::makeSemaphore ( bool  isOwned)
overridevirtual

Implements GrGpu.

Definition at line 1772 of file GrD3DGpu.cpp.

1772 {
1773 return GrD3DSemaphore::Make(this);
1774}
static std::unique_ptr< GrD3DSemaphore > Make(GrD3DGpu *gpu)

◆ makeStencilAttachment()

sk_sp< GrAttachment > GrD3DGpu::makeStencilAttachment ( const GrBackendFormat ,
SkISize  dimensions,
int  numStencilSamples 
)
overridevirtual

Implements GrGpu.

Definition at line 1324 of file GrD3DGpu.cpp.

1325 {
1326 DXGI_FORMAT sFmt = this->d3dCaps().preferredStencilFormat();
1327
1329 return GrD3DAttachment::MakeStencil(this, dimensions, numStencilSamples, sFmt);
1330}
static sk_sp< GrD3DAttachment > MakeStencil(GrD3DGpu *gpu, SkISize dimensions, int sampleCnt, DXGI_FORMAT format)
DXGI_FORMAT preferredStencilFormat() const
Definition GrD3DCaps.h:62
void incStencilAttachmentCreates()
Definition GrGpu.h:539
Stats fStats
Definition GrGpu.h:703

◆ memoryAllocator()

GrD3DMemoryAllocator * GrD3DGpu::memoryAllocator ( ) const
inline

Definition at line 46 of file GrD3DGpu.h.

46{ return fMemoryAllocator.get(); }
T * get() const
Definition SkRefCnt.h:303

◆ onClearBackendTexture()

bool GrD3DGpu::onClearBackendTexture ( const GrBackendTexture backendTexture,
sk_sp< skgpu::RefCntedCallback finishedCallback,
std::array< float, 4 >  color 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1452 of file GrD3DGpu.cpp.

1454 {
1456 SkAssertResult(backendTexture.getD3DTextureResourceInfo(&info));
1458
1459 sk_sp<GrD3DResourceState> state = backendTexture.getGrD3DResourceState();
1460 SkASSERT(state);
1462 GrD3DTexture::MakeWrappedTexture(this, backendTexture.dimensions(),
1464 kRW_GrIOType, info, std::move(state));
1465 if (!texture) {
1466 return false;
1467 }
1468
1469 GrD3DDirectCommandList* cmdList = this->currentCommandList();
1470 if (!cmdList) {
1471 return false;
1472 }
1473
1474 texture->setResourceState(this, D3D12_RESOURCE_STATE_COPY_DEST);
1475
1476 ID3D12Resource* d3dResource = texture->d3dResource();
1477 SkASSERT(d3dResource);
1478 D3D12_RESOURCE_DESC desc = d3dResource->GetDesc();
1479 unsigned int mipLevelCount = 1;
1480 if (backendTexture.fMipmapped == skgpu::Mipmapped::kYes) {
1481 mipLevelCount = SkMipmap::ComputeLevelCount(backendTexture.dimensions()) + 1;
1482 }
1483 SkASSERT(mipLevelCount == info.fLevelCount);
1484 AutoSTMalloc<15, D3D12_PLACED_SUBRESOURCE_FOOTPRINT> placedFootprints(mipLevelCount);
1485 UINT numRows;
1486 UINT64 rowSizeInBytes;
1487 UINT64 combinedBufferSize;
1488 // We reuse the same top-level buffer area for all levels, hence passing 1 for level count.
1489 fDevice->GetCopyableFootprints(&desc,
1490 /* first resource */ 0,
1491 /* mip level count */ 1,
1492 /* base offset */ 0,
1493 placedFootprints.get(),
1494 &numRows,
1495 &rowSizeInBytes,
1496 &combinedBufferSize);
1497 SkASSERT(combinedBufferSize);
1498
1499 GrStagingBufferManager::Slice slice = fStagingBufferManager.allocateStagingBufferSlice(
1500 combinedBufferSize, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
1501 if (!slice.fBuffer) {
1502 return false;
1503 }
1504
1505 char* bufferData = (char*)slice.fOffsetMapPtr;
1506 SkASSERT(bufferData);
1507 if (!copy_color_data(this->d3dCaps(),
1508 bufferData,
1509 info.fFormat,
1510 backendTexture.dimensions(),
1511 placedFootprints,
1512 color)) {
1513 return false;
1514 }
1515 // Update the offsets in the footprint to be relative to the slice's offset
1516 placedFootprints[0].Offset += slice.fOffset;
1517 // Since we're sharing data for all the levels, set all the upper level footprints to the base.
1518 UINT w = placedFootprints[0].Footprint.Width;
1519 UINT h = placedFootprints[0].Footprint.Height;
1520 for (unsigned int i = 1; i < mipLevelCount; ++i) {
1521 w = std::max(1U, w/2);
1522 h = std::max(1U, h/2);
1523 placedFootprints[i].Offset = placedFootprints[0].Offset;
1524 placedFootprints[i].Footprint.Format = placedFootprints[0].Footprint.Format;
1525 placedFootprints[i].Footprint.Width = w;
1526 placedFootprints[i].Footprint.Height = h;
1527 placedFootprints[i].Footprint.Depth = 1;
1528 placedFootprints[i].Footprint.RowPitch = placedFootprints[0].Footprint.RowPitch;
1529 }
1530
1531 ID3D12Resource* d3dBuffer = static_cast<GrD3DBuffer*>(slice.fBuffer)->d3dResource();
1532 cmdList->copyBufferToTexture(d3dBuffer,
1533 texture.get(),
1534 mipLevelCount,
1535 placedFootprints.get(),
1536 /*left*/ 0,
1537 /*top */ 0);
1538
1539 if (finishedCallback) {
1540 this->addFinishedCallback(std::move(finishedCallback));
1541 }
1542
1543 return true;
1544}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static bool copy_color_data(const GrD3DCaps &caps, char *mapPtr, DXGI_FORMAT dxgiFormat, SkISize dimensions, D3D12_PLACED_SUBRESOURCE_FOOTPRINT *placedFootprints, std::array< float, 4 > color)
bool GrDxgiFormatIsCompressed(DXGI_FORMAT format)
Definition GrD3DUtil.cpp:15
@ kRW_GrIOType
SkColor4f color
#define SkAssertResult(cond)
Definition SkAssert.h:123
SkISize dimensions() const
void copyBufferToTexture(ID3D12Resource *srcBuffer, const GrD3DTextureResource *dstTexture, uint32_t subresourceCount, D3D12_PLACED_SUBRESOURCE_FOOTPRINT *bufferFootprints, int left, int top)
GrD3DDirectCommandList * currentCommandList() const
Definition GrD3DGpu.h:48
static sk_sp< GrD3DTexture > MakeWrappedTexture(GrD3DGpu *, SkISize dimensions, GrWrapCacheable, GrIOType, const GrD3DTextureResourceInfo &, sk_sp< GrD3DResourceState >)
Slice allocateStagingBufferSlice(size_t size, size_t requiredAlignment=1)
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition SkMipmap.cpp:134
AtkStateType state
FlTexture * texture
SkScalar w
SkScalar h
unsigned int UINT

◆ onCopySurface()

bool GrD3DGpu::onCopySurface ( GrSurface dst,
const SkIRect dstRect,
GrSurface src,
const SkIRect srcRect,
GrSamplerState::Filter   
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 442 of file GrD3DGpu.cpp.

444 {
445 if (srcRect.size() != dstRect.size()) {
446 return false;
447 }
448 if (src->isProtected() && !dst->isProtected()) {
449 SkDebugf("Can't copy from protected memory to non-protected");
450 return false;
451 }
452
453 int dstSampleCnt = get_surface_sample_cnt(dst);
454 int srcSampleCnt = get_surface_sample_cnt(src);
455
456 GrD3DTextureResource* dstTexResource;
457 GrD3DTextureResource* srcTexResource;
458 GrRenderTarget* dstRT = dst->asRenderTarget();
459 if (dstRT) {
460 GrD3DRenderTarget* d3dRT = static_cast<GrD3DRenderTarget*>(dstRT);
461 dstTexResource = d3dRT->numSamples() > 1 ? d3dRT->msaaTextureResource() : d3dRT;
462 } else {
463 SkASSERT(dst->asTexture());
464 dstTexResource = static_cast<GrD3DTexture*>(dst->asTexture());
465 }
466 GrRenderTarget* srcRT = src->asRenderTarget();
467 if (srcRT) {
468 GrD3DRenderTarget* d3dRT = static_cast<GrD3DRenderTarget*>(srcRT);
469 srcTexResource = d3dRT->numSamples() > 1 ? d3dRT->msaaTextureResource() : d3dRT;
470 } else {
471 SkASSERT(src->asTexture());
472 srcTexResource = static_cast<GrD3DTexture*>(src->asTexture());
473 }
474
475 DXGI_FORMAT dstFormat = dstTexResource->dxgiFormat();
476 DXGI_FORMAT srcFormat = srcTexResource->dxgiFormat();
477
478 const SkIPoint dstPoint = dstRect.topLeft();
479 if (this->d3dCaps().canCopyAsResolve(dstFormat, dstSampleCnt, srcFormat, srcSampleCnt)) {
480 this->copySurfaceAsResolve(dst, src, srcRect, dstPoint);
481 return true;
482 }
483
484 if (this->d3dCaps().canCopyTexture(dstFormat, dstSampleCnt, srcFormat, srcSampleCnt)) {
485 this->copySurfaceAsCopyTexture(dst, src, dstTexResource, srcTexResource, srcRect, dstPoint);
486 return true;
487 }
488
489 return false;
490}
static int get_surface_sample_cnt(GrSurface *surf)
Definition GrD3DGpu.cpp:435
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
bool canCopyAsResolve(DXGI_FORMAT dstFormat, int dstSampleCnt, DXGI_FORMAT srcFormat, int srcSamplecnt) const
Definition GrD3DCaps.cpp:83
const GrD3DTextureResource * msaaTextureResource() const
DXGI_FORMAT dxgiFormat() const
int numSamples() const
dst
Definition cp.py:12
constexpr SkISize size() const
Definition SkRect.h:172
constexpr SkIPoint topLeft() const
Definition SkRect.h:151

◆ onCreateBackendTexture()

GrBackendTexture GrD3DGpu::onCreateBackendTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrRenderable  renderable,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected,
std::string_view  label 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1402 of file GrD3DGpu.cpp.

1407 {
1408 const GrD3DCaps& caps = this->d3dCaps();
1409
1410 if (this->protectedContext() != (isProtected == GrProtected::kYes)) {
1411 return {};
1412 }
1413
1414 DXGI_FORMAT dxgiFormat;
1415 if (!format.asDxgiFormat(&dxgiFormat)) {
1416 return {};
1417 }
1418
1419 // TODO: move the texturability check up to GrGpu::createBackendTexture and just assert here
1420 if (!caps.isFormatTexturable(dxgiFormat)) {
1421 return {};
1422 }
1423
1425 if (!this->createTextureResourceForBackendSurface(dxgiFormat, dimensions, GrTexturable::kYes,
1426 renderable, mipmapped, 1, &info,
1427 isProtected)) {
1428 return {};
1429 }
1430
1431 return GrBackendTexture(dimensions.width(), dimensions.height(), info);
1432}
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
bool protectedContext() const
Definition GrD3DGpu.h:55
uint32_t uint32_t * format
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37

◆ onCreateBuffer()

sk_sp< GrGpuBuffer > GrD3DGpu::onCreateBuffer ( size_t  sizeInBytes,
GrGpuBufferType  type,
GrAccessPattern  accessPattern 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1318 of file GrD3DGpu.cpp.

1320 {
1321 return GrD3DBuffer::Make(this, sizeInBytes, type, accessPattern);
1322}
static sk_sp< GrD3DBuffer > Make(GrD3DGpu *, size_t size, GrGpuBufferType, GrAccessPattern)

◆ onCreateCompressedBackendTexture()

GrBackendTexture GrD3DGpu::onCreateCompressedBackendTexture ( SkISize  dimensions,
const GrBackendFormat format,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1546 of file GrD3DGpu.cpp.

1549 {
1550 return this->onCreateBackendTexture(dimensions,
1551 format,
1552 GrRenderable::kNo,
1553 mipmapped,
1554 isProtected,
1555 /*label=*/"D3DGpu_CreateCompressedBackendTexture");
1556}
GrBackendTexture onCreateBackendTexture(SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label) override

◆ onCreateCompressedTexture()

sk_sp< GrTexture > GrD3DGpu::onCreateCompressedTexture ( SkISize  dimensions,
const GrBackendFormat format,
skgpu::Budgeted  budgeted,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected,
const void *  data,
size_t  dataSize 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 358 of file GrD3DGpu.cpp.

364 {
365 DXGI_FORMAT dxgiFormat;
366 SkAssertResult(format.asDxgiFormat(&dxgiFormat));
368
371 compression, dimensions, mipmapped == skgpu::Mipmapped::kYes));
372
373 int mipLevelCount = 1;
374 if (mipmapped == skgpu::Mipmapped::kYes) {
375 mipLevelCount = SkMipmap::ComputeLevelCount(dimensions.width(), dimensions.height()) + 1;
376 }
377 GrMipmapStatus mipmapStatus = mipLevelCount > 1 ? GrMipmapStatus::kValid
379
380 sk_sp<GrD3DTexture> d3dTex = this->createD3DTexture(
381 dimensions,
382 dxgiFormat,
383 GrRenderable::kNo,
384 1,
385 budgeted,
386 isProtected,
387 mipLevelCount,
388 mipmapStatus,
389 /*label=*/"D3DGpu_CreateCompressedTexture");
390 if (!d3dTex) {
391 return nullptr;
392 }
393
394 ID3D12Resource* d3dResource = d3dTex->d3dResource();
395 SkASSERT(d3dResource);
396 D3D12_RESOURCE_DESC desc = d3dResource->GetDesc();
397 // Either upload only the first miplevel or all miplevels
398 SkASSERT(1 == mipLevelCount || mipLevelCount == (int)desc.MipLevels);
399
400 AutoTMalloc<D3D12_PLACED_SUBRESOURCE_FOOTPRINT> placedFootprints(mipLevelCount);
401 AutoTMalloc<UINT> numRows(mipLevelCount);
402 AutoTMalloc<UINT64> rowSizeInBytes(mipLevelCount);
403 UINT64 combinedBufferSize;
404 // We reset the width and height in the description to match our subrectangle size
405 // so we don't end up allocating more space than we need.
406 desc.Width = dimensions.width();
407 desc.Height = dimensions.height();
408 fDevice->GetCopyableFootprints(&desc, 0, mipLevelCount, 0, placedFootprints.get(),
409 numRows.get(), rowSizeInBytes.get(), &combinedBufferSize);
410 SkASSERT(combinedBufferSize);
411
412 GrStagingBufferManager::Slice slice = fStagingBufferManager.allocateStagingBufferSlice(
413 combinedBufferSize, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
414 if (!slice.fBuffer) {
415 return nullptr;
416 }
417
418 char* bufferData = (char*)slice.fOffsetMapPtr;
419
420 copy_compressed_data(bufferData, desc.Format, placedFootprints.get(), numRows.get(),
421 rowSizeInBytes.get(), data, mipLevelCount);
422
423 // Update the offsets in the footprints to be relative to the slice's offset
424 for (int i = 0; i < mipLevelCount; ++i) {
425 placedFootprints[i].Offset += slice.fOffset;
426 }
427
428 ID3D12Resource* d3dBuffer = static_cast<GrD3DBuffer*>(slice.fBuffer)->d3dResource();
429 fCurrentDirectCommandList->copyBufferToTexture(d3dBuffer, d3dTex.get(), mipLevelCount,
430 placedFootprints.get(), 0, 0);
431
432 return std::move(d3dTex);
433}
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
static void copy_compressed_data(char *mapPtr, DXGI_FORMAT dxgiFormat, D3D12_PLACED_SUBRESOURCE_FOOTPRINT *placedFootprints, UINT *numRows, UINT64 *rowSizeInBytes, const void *compressedData, int numMipLevels)
Definition GrD3DGpu.cpp:339
GrMipmapStatus
size_t SkCompressedFormatDataSize(SkTextureCompressionType compressionType, SkISize dimensions, bool mipmapped)
#define SkDEBUGCODE(...)
Definition SkDebug.h:23

◆ onCreateTexture()

sk_sp< GrTexture > GrD3DGpu::onCreateTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrRenderable  renderable,
int  renderTargetSampleCnt,
skgpu::Budgeted  budgeted,
GrProtected  isProtected,
int  mipLevelCount,
uint32_t  levelClearMask,
std::string_view  label 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 309 of file GrD3DGpu.cpp.

317 {
318 DXGI_FORMAT dxgiFormat;
319 SkAssertResult(format.asDxgiFormat(&dxgiFormat));
321
322 GrMipmapStatus mipmapStatus = mipLevelCount > 1 ? GrMipmapStatus::kDirty
324
325 sk_sp<GrD3DTexture> tex = this->createD3DTexture(dimensions, dxgiFormat, renderable,
326 renderTargetSampleCnt, budgeted, isProtected,
327 mipLevelCount, mipmapStatus, label);
328 if (!tex) {
329 return nullptr;
330 }
331
332 if (levelClearMask) {
333 // TODO
334 }
335
336 return std::move(tex);
337}

◆ onGetOpsRenderPass()

GrOpsRenderPass * GrD3DGpu::onGetOpsRenderPass ( GrRenderTarget rt,
bool  useMSAASurface,
GrAttachment ,
GrSurfaceOrigin  origin,
const SkIRect bounds,
const GrOpsRenderPass::LoadAndStoreInfo colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo stencilInfo,
const skia_private::TArray< GrSurfaceProxy *, true > &  sampledProxies,
GrXferBarrierFlags  renderPassXferBarriers 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 139 of file GrD3DGpu.cpp.

148 {
149 if (!fCachedOpsRenderPass) {
150 fCachedOpsRenderPass.reset(new GrD3DOpsRenderPass(this));
151 }
152
153 if (!fCachedOpsRenderPass->set(rt, origin, bounds, colorInfo, stencilInfo, sampledProxies)) {
154 return nullptr;
155 }
156 return fCachedOpsRenderPass.get();
157}

◆ onReadPixels()

bool GrD3DGpu::onReadPixels ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  dstColorType,
void *  buffer,
size_t  rowBytes 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 586 of file GrD3DGpu.cpp.

591 {
593
594 if (surfaceColorType != dstColorType) {
595 return false;
596 }
597
598 GrD3DTextureResource* texResource = nullptr;
599 GrD3DRenderTarget* rt = static_cast<GrD3DRenderTarget*>(surface->asRenderTarget());
600 if (rt) {
601 texResource = rt;
602 } else {
603 texResource = static_cast<GrD3DTexture*>(surface->asTexture());
604 }
605
606 if (!texResource) {
607 return false;
608 }
609
610 D3D12_RESOURCE_DESC desc = texResource->d3dResource()->GetDesc();
611 D3D12_PLACED_SUBRESOURCE_FOOTPRINT placedFootprint;
612 UINT64 transferTotalBytes;
613 fDevice->GetCopyableFootprints(&desc, 0, 1, 0, &placedFootprint,
614 nullptr, nullptr, &transferTotalBytes);
615 SkASSERT(transferTotalBytes);
617 this->getContext()->priv().resourceProvider();
618 sk_sp<GrGpuBuffer> transferBuffer = resourceProvider->createBuffer(
619 transferTotalBytes,
623 if (!transferBuffer) {
624 return false;
625 }
626
627 this->readOrTransferPixels(texResource, rect, transferBuffer, placedFootprint);
628 this->submitDirectCommandList(SyncQueue::kForce);
629
630 // Copy back to CPU buffer
631 size_t bpp = GrColorTypeBytesPerPixel(dstColorType);
632 if (GrDxgiFormatBytesPerBlock(texResource->dxgiFormat()) != bpp) {
633 return false;
634 }
635 size_t tightRowBytes = bpp * rect.width();
636
637 const void* mappedMemory = transferBuffer->map();
638 if (!mappedMemory) {
639 return false;
640 }
641
643 rowBytes,
644 mappedMemory,
645 placedFootprint.Footprint.RowPitch,
646 tightRowBytes,
647 rect.height());
648
649 transferBuffer->unmap();
650
651 return true;
652}
static constexpr size_t GrDxgiFormatBytesPerBlock(DXGI_FORMAT format)
Definition GrD3DUtil.h:101
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
@ kDynamic_GrAccessPattern
static void SkRectMemcpy(void *dst, size_t dstRB, const void *src, size_t srcRB, size_t trimRowBytes, int rowCount)
GrD3DResourceProvider & resourceProvider()
Definition GrD3DGpu.h:38
ID3D12Resource * d3dResource() const
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
GrDirectContext * getContext()
Definition GrGpu.h:67
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350

◆ onRegenerateMipMapLevels()

bool GrD3DGpu::onRegenerateMipMapLevels ( GrTexture tex)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1104 of file GrD3DGpu.cpp.

1104 {
1105 auto * d3dTex = static_cast<GrD3DTexture*>(tex);
1107 int width = tex->width();
1108 int height = tex->height();
1109
1110 // determine if we can read from and mipmap this format
1111 const GrD3DCaps & caps = this->d3dCaps();
1112 if (!caps.isFormatTexturable(d3dTex->dxgiFormat()) ||
1113 !caps.mipmapSupport()) {
1114 return false;
1115 }
1116
1117 sk_sp<GrD3DTexture> uavTexture;
1118 sk_sp<GrD3DTexture> bgraAliasTexture;
1119 DXGI_FORMAT originalFormat = d3dTex->dxgiFormat();
1120 D3D12_RESOURCE_DESC originalDesc = d3dTex->d3dResource()->GetDesc();
1121 // if the format is unordered accessible and resource flag is set, use resource for uav
1122 if (caps.isFormatUnorderedAccessible(originalFormat) &&
1123 (originalDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) {
1124 uavTexture = sk_ref_sp(d3dTex);
1125 } else {
1126 // need to make a copy and use that for our uav
1127 D3D12_RESOURCE_DESC uavDesc = originalDesc;
1128 uavDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
1129 // if the format is unordered accessible, copy to resource with same format and flag set
1130 if (!caps.isFormatUnorderedAccessible(originalFormat)) {
1131 // for the BGRA and sRGB cases, we find a suitable RGBA format to use instead
1132 if (is_bgra(originalFormat)) {
1133 uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1134 // Technically if this support is not available we should not be doing
1135 // aliasing. However, on Intel the BGRA and RGBA swizzle appears to be
1136 // the same so it still works. We may need to disable BGRA support
1137 // on a case-by-base basis if this doesn't hold true in general.
1138 if (caps.standardSwizzleLayoutSupport()) {
1139 uavDesc.Layout = D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE;
1140 }
1141 // TODO: enable when sRGB shader supported
1142 //} else if (is_srgb(originalFormat)) {
1143 // uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1144 } else {
1145 return false;
1146 }
1147 }
1148 // TODO: make this a scratch texture
1149 GrProtected grProtected = tex->isProtected() ? GrProtected::kYes : GrProtected::kNo;
1150 uavTexture = GrD3DTexture::MakeNewTexture(this,
1152 tex->dimensions(),
1153 uavDesc,
1154 grProtected,
1156 /*label=*/"RegenerateMipMapLevels");
1157 if (!uavTexture) {
1158 return false;
1159 }
1160
1161 d3dTex->setResourceState(this, D3D12_RESOURCE_STATE_COPY_SOURCE);
1162 if (!caps.isFormatUnorderedAccessible(originalFormat) && is_bgra(originalFormat)) {
1163 // for BGRA, we alias this uavTexture with a BGRA texture and copy to that
1164 bgraAliasTexture = GrD3DTexture::MakeAliasingTexture(this, uavTexture, originalDesc,
1165 D3D12_RESOURCE_STATE_COPY_DEST);
1166 // make the BGRA version the active alias
1167 this->currentCommandList()->aliasingBarrier(nullptr,
1168 nullptr,
1169 bgraAliasTexture->resource(),
1170 bgraAliasTexture->d3dResource());
1171 // copy top miplevel to bgraAliasTexture (should already be in COPY_DEST state)
1172 this->currentCommandList()->copyTextureToTexture(bgraAliasTexture.get(), d3dTex, 0);
1173 // make the RGBA version the active alias
1174 this->currentCommandList()->aliasingBarrier(bgraAliasTexture->resource(),
1175 bgraAliasTexture->d3dResource(),
1176 uavTexture->resource(),
1177 uavTexture->d3dResource());
1178 } else {
1179 // copy top miplevel to uavTexture
1180 uavTexture->setResourceState(this, D3D12_RESOURCE_STATE_COPY_DEST);
1181 this->currentCommandList()->copyTextureToTexture(uavTexture.get(), d3dTex, 0);
1182 }
1183 }
1184
1185 uint32_t levelCount = d3dTex->mipLevels();
1186 // SkMipmap doesn't include the base level in the level count so we have to add 1
1187 SkASSERT((int)levelCount == SkMipmap::ComputeLevelCount(tex->width(), tex->height()) + 1);
1188
1189 sk_sp<GrD3DRootSignature> rootSig = fResourceProvider.findOrCreateRootSignature(1, 1);
1191
1192 // TODO: use linear vs. srgb shader based on texture format
1194 if (!pipeline) {
1195 return false;
1196 }
1197 this->currentCommandList()->setPipelineState(std::move(pipeline));
1198
1199 // set sampler
1201 std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> samplers(1);
1202 samplers[0] = fResourceProvider.findOrCreateCompatibleSampler(samplerState);
1203 this->currentCommandList()->addSampledTextureRef(uavTexture.get());
1204 sk_sp<GrD3DDescriptorTable> samplerTable = fResourceProvider.findOrCreateSamplerTable(samplers);
1205
1206 // Transition the top subresource to be readable in the compute shader
1207 D3D12_RESOURCE_STATES currentResourceState = uavTexture->currentState();
1208 D3D12_RESOURCE_TRANSITION_BARRIER barrier;
1209 barrier.pResource = uavTexture->d3dResource();
1210 barrier.Subresource = 0;
1211 barrier.StateBefore = currentResourceState;
1212 barrier.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
1213 this->addResourceBarriers(uavTexture->resource(), 1, &barrier);
1214
1215 // Generate the miplevels
1216 for (unsigned int dstMip = 1; dstMip < levelCount; ++dstMip) {
1217 unsigned int srcMip = dstMip - 1;
1218 width = std::max(1, width / 2);
1219 height = std::max(1, height / 2);
1220
1221 unsigned int sampleMode = 0;
1222 if (is_odd(width) && is_odd(height)) {
1223 sampleMode = 1;
1224 } else if (is_odd(width)) {
1225 sampleMode = 2;
1226 } else if (is_odd(height)) {
1227 sampleMode = 3;
1228 }
1229
1230 // set constants
1231 struct {
1232 SkSize inverseSize;
1233 uint32_t mipLevel;
1234 uint32_t sampleMode;
1235 } constantData = { {1.f / width, 1.f / height}, srcMip, sampleMode };
1236
1237 D3D12_GPU_VIRTUAL_ADDRESS constantsAddress =
1238 fResourceProvider.uploadConstantData(&constantData, sizeof(constantData));
1241 constantsAddress);
1242
1243 std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> shaderViews;
1244 // create SRV
1246 fResourceProvider.createShaderResourceView(uavTexture->d3dResource(), srcMip, 1);
1247 shaderViews.push_back(srvHandle.fHandle);
1248 fMipmapCPUDescriptors.push_back(srvHandle);
1249 // create UAV
1251 fResourceProvider.createUnorderedAccessView(uavTexture->d3dResource(), dstMip);
1252 shaderViews.push_back(uavHandle.fHandle);
1253 fMipmapCPUDescriptors.push_back(uavHandle);
1254
1255 // set up shaderView descriptor table
1257 fResourceProvider.findOrCreateShaderViewTable(shaderViews);
1258
1259 // bind both descriptor tables
1260 this->currentCommandList()->setDescriptorHeaps(srvTable->heap(), samplerTable->heap());
1263 srvTable->baseGpuDescriptor());
1266 samplerTable->baseGpuDescriptor());
1267
1268 // Transition resource state of dstMip subresource so we can write to it
1269 barrier.Subresource = dstMip;
1270 barrier.StateBefore = currentResourceState;
1271 barrier.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
1272 this->addResourceBarriers(uavTexture->resource(), 1, &barrier);
1273
1274 // Using the form (x+7)/8 ensures that the remainder is covered as well
1275 this->currentCommandList()->dispatch((width+7)/8, (height+7)/8);
1276
1277 // guarantee UAV writes have completed
1278 this->currentCommandList()->uavBarrier(uavTexture->resource(), uavTexture->d3dResource());
1279
1280 // Transition resource state of dstMip subresource so we can read it in the next stage
1281 barrier.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
1282 barrier.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
1283 this->addResourceBarriers(uavTexture->resource(), 1, &barrier);
1284 }
1285
1286 // copy back if necessary
1287 if (uavTexture.get() != d3dTex) {
1288 d3dTex->setResourceState(this, D3D12_RESOURCE_STATE_COPY_DEST);
1289 if (bgraAliasTexture) {
1290 // make the BGRA version the active alias
1291 this->currentCommandList()->aliasingBarrier(uavTexture->resource(),
1292 uavTexture->d3dResource(),
1293 bgraAliasTexture->resource(),
1294 bgraAliasTexture->d3dResource());
1295 // copy from bgraAliasTexture to d3dTex
1296 bgraAliasTexture->setResourceState(this, D3D12_RESOURCE_STATE_COPY_SOURCE);
1297 this->currentCommandList()->copyTextureToTexture(d3dTex, bgraAliasTexture.get());
1298 } else {
1299 barrier.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
1300 barrier.StateBefore = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
1301 barrier.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
1302 this->addResourceBarriers(uavTexture->resource(), 1, &barrier);
1303 this->currentCommandList()->copyTextureToTexture(d3dTex, uavTexture.get());
1304 }
1305 } else {
1306 // For simplicity our resource state tracking considers all subresources to have the same
1307 // state. However, we've changed that state one subresource at a time without going through
1308 // the tracking system, so we need to patch up the resource states back to the original.
1309 barrier.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
1310 barrier.StateBefore = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
1311 barrier.StateAfter = currentResourceState;
1312 this->addResourceBarriers(d3dTex->resource(), 1, &barrier);
1313 }
1314
1315 return true;
1316}
static bool is_bgra(DXGI_FORMAT format)
static bool is_odd(int x)
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
bool mipmapSupport() const
Definition GrCaps.h:72
bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const override
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 uavBarrier(sk_sp< GrManagedResource > managedResource, ID3D12Resource *uavResource)
void setComputeRootConstantBufferView(unsigned int rootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS bufferLocation)
void addSampledTextureRef(GrD3DTexture *)
void setComputeRootDescriptorTable(unsigned int rootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE bufferLocation)
void setDescriptorHeaps(ID3D12DescriptorHeap *srvDescriptorHeap, ID3D12DescriptorHeap *samplerDescriptorHeap)
void setPipelineState(const sk_sp< GrD3DPipeline > &pipeline)
void dispatch(unsigned int threadGroupCountX, unsigned int threadGroupCountY, unsigned int threadGroupCountZ=1)
void setComputeRootSignature(const sk_sp< GrD3DRootSignature > &rootSignature)
void addResourceBarriers(sk_sp< GrManagedResource > resource, int numBarriers, D3D12_RESOURCE_TRANSITION_BARRIER *barriers) const
GrD3DDescriptorHeap::CPUHandle createUnorderedAccessView(ID3D12Resource *resource, unsigned int mipSlice)
GrD3DDescriptorHeap::CPUHandle createShaderResourceView(ID3D12Resource *resource, unsigned int mostDetailedMip=0, unsigned int mipLevels=-1)
D3D12_GPU_VIRTUAL_ADDRESS uploadConstantData(void *data, size_t size)
sk_sp< GrD3DDescriptorTable > findOrCreateShaderViewTable(const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &shaderViews)
D3D12_CPU_DESCRIPTOR_HANDLE findOrCreateCompatibleSampler(const GrSamplerState &params)
sk_sp< GrD3DPipeline > findOrCreateMipmapPipeline()
sk_sp< GrD3DDescriptorTable > findOrCreateSamplerTable(const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &samplers)
sk_sp< GrD3DRootSignature > findOrCreateRootSignature(int numTextureSamplers, int numUAVs=0)
static sk_sp< GrD3DTexture > MakeNewTexture(GrD3DGpu *, skgpu::Budgeted, SkISize dimensions, const D3D12_RESOURCE_DESC &, GrProtected, GrMipmapStatus, std::string_view label)
static sk_sp< GrD3DTexture > MakeAliasingTexture(GrD3DGpu *, sk_sp< GrD3DTexture >, const D3D12_RESOURCE_DESC &newDesc, D3D12_RESOURCE_STATES)
SkISize dimensions() const
Definition GrSurface.h:27
bool isProtected() const
Definition GrSurface.h:87
int height() const
Definition GrSurface.h:37
int width() const
Definition GrSurface.h:32
GrTextureType textureType() const
Definition GrTexture.h:55
Protected
Definition GpuTypes.h:61
int32_t height
int32_t width
D3D12_CPU_DESCRIPTOR_HANDLE fHandle

◆ onResolveRenderTarget()

void GrD3DGpu::onResolveRenderTarget ( GrRenderTarget target,
const SkIRect resolveRect 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 578 of file GrD3DGpu.cpp.

578 {
579 SkASSERT(target->numSamples() > 1);
580 GrD3DRenderTarget* rt = static_cast<GrD3DRenderTarget*>(target);
582
583 this->resolveTexture(target, resolveRect.fLeft, resolveRect.fTop, rt, resolveRect);
584}
uint32_t * target
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33

◆ onSubmitToGpu()

bool GrD3DGpu::onSubmitToGpu ( GrSyncCpu  sync)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1764 of file GrD3DGpu.cpp.

1764 {
1765 if (sync == GrSyncCpu::kYes) {
1766 return this->submitDirectCommandList(SyncQueue::kForce);
1767 } else {
1768 return this->submitDirectCommandList(SyncQueue::kSkip);
1769 }
1770}

◆ onTransferFromBufferToBuffer()

bool GrD3DGpu::onTransferFromBufferToBuffer ( sk_sp< GrGpuBuffer src,
size_t  srcOffset,
sk_sp< GrGpuBuffer dst,
size_t  dstOffset,
size_t  size 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 816 of file GrD3DGpu.cpp.

820 {
821 if (!this->currentCommandList()) {
822 return false;
823 }
824
825 sk_sp<GrD3DBuffer> d3dSrc(static_cast<GrD3DBuffer*>(src.release()));
826 sk_sp<GrD3DBuffer> d3dDst(static_cast<GrD3DBuffer*>(dst.release()));
827
828 fCurrentDirectCommandList->copyBufferToBuffer(std::move(d3dDst),
829 dstOffset,
830 d3dSrc->d3dResource(),
831 srcOffset,
832 size);
833
834 // copyBufferToBuffer refs the dst but not the src
835 this->currentCommandList()->addGrBuffer(std::move(src));
836
837 return true;
838}
void addGrBuffer(sk_sp< const GrBuffer > buffer)

◆ onTransferPixelsFrom()

bool GrD3DGpu::onTransferPixelsFrom ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 908 of file GrD3DGpu.cpp.

913 {
914 if (!this->currentCommandList()) {
915 return false;
916 }
917 SkASSERT(surface);
918 SkASSERT(transferBuffer);
919 // TODO
920 //if (fProtectedContext == GrProtected::kYes) {
921 // return false;
922 //}
923
924 // D3D requires offsets for texture transfers to be aligned to this value
925 if (SkToBool(offset & (D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT-1))) {
926 return false;
927 }
928
929 GrD3DTextureResource* texResource = nullptr;
930 GrD3DRenderTarget* rt = static_cast<GrD3DRenderTarget*>(surface->asRenderTarget());
931 if (rt) {
932 texResource = rt;
933 } else {
934 texResource = static_cast<GrD3DTexture*>(surface->asTexture());
935 }
936
937 if (!texResource) {
938 return false;
939 }
940
941 SkDEBUGCODE(DXGI_FORMAT format = texResource->dxgiFormat());
943
944 D3D12_RESOURCE_DESC desc = texResource->d3dResource()->GetDesc();
945 desc.Width = rect.width();
946 desc.Height = rect.height();
947 D3D12_PLACED_SUBRESOURCE_FOOTPRINT placedFootprint;
948 UINT64 transferTotalBytes;
949 fDevice->GetCopyableFootprints(&desc, 0, 1, offset, &placedFootprint,
950 nullptr, nullptr, &transferTotalBytes);
951 SkASSERT(transferTotalBytes);
952
953 this->readOrTransferPixels(texResource, rect, transferBuffer, placedFootprint);
954
955 // TODO: It's not clear how to ensure the transfer is done before we read from the buffer,
956 // other than maybe doing a resource state transition.
957
958 return true;
959}
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
Point offset

◆ onTransferPixelsTo()

bool GrD3DGpu::onTransferPixelsTo ( GrTexture texture,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset,
size_t  rowBytes 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 840 of file GrD3DGpu.cpp.

846 {
847 if (!this->currentCommandList()) {
848 return false;
849 }
850
851 if (!transferBuffer) {
852 return false;
853 }
854
855 size_t bpp = GrColorTypeBytesPerPixel(bufferColorType);
856 if (GrBackendFormatBytesPerPixel(texture->backendFormat()) != bpp) {
857 return false;
858 }
859
860 // D3D requires offsets for texture transfers to be aligned to this value
861 if (SkToBool(bufferOffset & (D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT-1))) {
862 return false;
863 }
864
865 GrD3DTexture* d3dTex = static_cast<GrD3DTexture*>(texture);
866 if (!d3dTex) {
867 return false;
868 }
869
870 SkDEBUGCODE(DXGI_FORMAT format = d3dTex->dxgiFormat());
871
872 // Can't transfer compressed data
874
876
877 SkASSERT(SkIRect::MakeSize(texture->dimensions()).contains(rect));
878
879 // Set up copy region
880 D3D12_PLACED_SUBRESOURCE_FOOTPRINT placedFootprint = {};
881 ID3D12Resource* d3dResource = d3dTex->d3dResource();
882 SkASSERT(d3dResource);
883 D3D12_RESOURCE_DESC desc = d3dResource->GetDesc();
884 desc.Width = rect.width();
885 desc.Height = rect.height();
886 UINT64 totalBytes;
887 fDevice->GetCopyableFootprints(&desc, 0, 1, 0, &placedFootprint,
888 nullptr, nullptr, &totalBytes);
889 placedFootprint.Offset = bufferOffset;
890
891 // Change state of our target so it can be copied to
892 d3dTex->setResourceState(this, D3D12_RESOURCE_STATE_COPY_DEST);
893
894 // Copy the buffer to the image.
895 ID3D12Resource* d3dBuffer = static_cast<GrD3DBuffer*>(transferBuffer.get())->d3dResource();
896 fCurrentDirectCommandList->copyBufferToTexture(d3dBuffer,
897 d3dTex,
898 1,
899 &placedFootprint,
900 rect.left(),
901 rect.top());
902 this->currentCommandList()->addGrBuffer(std::move(transferBuffer));
903
904 d3dTex->markMipmapsDirty();
905 return true;
906}
size_t GrBackendFormatBytesPerPixel(const GrBackendFormat &format)
void setResourceState(const GrD3DGpu *gpu, D3D12_RESOURCE_STATES newResourceState, unsigned int subresource=D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES)
void markMipmapsDirty()
Definition GrTexture.cpp:25
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463

◆ onUpdateCompressedBackendTexture()

bool GrD3DGpu::onUpdateCompressedBackendTexture ( const GrBackendTexture backendTexture,
sk_sp< skgpu::RefCntedCallback finishedCallback,
const void *  data,
size_t  size 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1558 of file GrD3DGpu.cpp.

1561 {
1563 SkAssertResult(backendTexture.getD3DTextureResourceInfo(&info));
1564
1565 sk_sp<GrD3DResourceState> state = backendTexture.getGrD3DResourceState();
1566 SkASSERT(state);
1568 backendTexture.dimensions(),
1571 info,
1572 std::move(state));
1573 if (!texture) {
1574 return false;
1575 }
1576
1577 GrD3DDirectCommandList* cmdList = this->currentCommandList();
1578 if (!cmdList) {
1579 return false;
1580 }
1581
1582 texture->setResourceState(this, D3D12_RESOURCE_STATE_COPY_DEST);
1583
1584 ID3D12Resource* d3dResource = texture->d3dResource();
1585 SkASSERT(d3dResource);
1586 D3D12_RESOURCE_DESC desc = d3dResource->GetDesc();
1587 unsigned int mipLevelCount = 1;
1588 if (backendTexture.hasMipmaps()) {
1589 mipLevelCount = SkMipmap::ComputeLevelCount(backendTexture.dimensions().width(),
1590 backendTexture.dimensions().height()) + 1;
1591 }
1592 SkASSERT(mipLevelCount == info.fLevelCount);
1593 AutoTMalloc<D3D12_PLACED_SUBRESOURCE_FOOTPRINT> placedFootprints(mipLevelCount);
1594 UINT64 combinedBufferSize;
1595 AutoTMalloc<UINT> numRows(mipLevelCount);
1596 AutoTMalloc<UINT64> rowSizeInBytes(mipLevelCount);
1597 fDevice->GetCopyableFootprints(&desc,
1598 0,
1599 mipLevelCount,
1600 0,
1601 placedFootprints.get(),
1602 numRows.get(),
1603 rowSizeInBytes.get(),
1604 &combinedBufferSize);
1605 SkASSERT(combinedBufferSize);
1607
1608 GrStagingBufferManager::Slice slice = fStagingBufferManager.allocateStagingBufferSlice(
1609 combinedBufferSize, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
1610 if (!slice.fBuffer) {
1611 return false;
1612 }
1613
1614 char* bufferData = (char*)slice.fOffsetMapPtr;
1615 SkASSERT(bufferData);
1616 copy_compressed_data(bufferData,
1617 info.fFormat,
1618 placedFootprints.get(),
1619 numRows.get(),
1620 rowSizeInBytes.get(),
1621 data,
1622 info.fLevelCount);
1623
1624 // Update the offsets in the footprints to be relative to the slice's offset
1625 for (unsigned int i = 0; i < mipLevelCount; ++i) {
1626 placedFootprints[i].Offset += slice.fOffset;
1627 }
1628
1629 ID3D12Resource* d3dBuffer = static_cast<GrD3DBuffer*>(slice.fBuffer)->d3dResource();
1630 cmdList->copyBufferToTexture(d3dBuffer,
1631 texture.get(),
1632 mipLevelCount,
1633 placedFootprints.get(),
1634 0,
1635 0);
1636
1637 if (finishedCallback) {
1638 this->addFinishedCallback(std::move(finishedCallback));
1639 }
1640
1641 return true;
1642}
bool hasMipmaps() const

◆ onWrapBackendRenderTarget()

sk_sp< GrRenderTarget > GrD3DGpu::onWrapBackendRenderTarget ( const GrBackendRenderTarget rt)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1056 of file GrD3DGpu.cpp.

1056 {
1058 if (!rt.getD3DTextureResourceInfo(&info)) {
1059 return nullptr;
1060 }
1061
1062 if (!check_resource_info(info)) {
1063 return nullptr;
1064 }
1065
1066 if (!check_rt_resource_info(this->d3dCaps(), info, rt.sampleCnt())) {
1067 return nullptr;
1068 }
1069
1070 // TODO: support protected context
1071 if (rt.isProtected()) {
1072 return nullptr;
1073 }
1074
1075 sk_sp<GrD3DResourceState> state = rt.getGrD3DResourceState();
1076
1078 this, rt.dimensions(), rt.sampleCnt(), info, std::move(state));
1079
1080 // We don't allow the client to supply a premade stencil buffer. We always create one if needed.
1081 SkASSERT(!rt.stencilBits());
1082 if (tgt) {
1083 SkASSERT(tgt->canAttemptStencilAttachment(tgt->numSamples() > 1));
1084 }
1085
1086 return std::move(tgt);
1087}
static bool check_resource_info(const GrD3DTextureResourceInfo &info)
Definition GrD3DGpu.cpp:961
static bool check_rt_resource_info(const GrD3DCaps &caps, const GrD3DTextureResourceInfo &info, int sampleCnt)
Definition GrD3DGpu.cpp:979
SkISize dimensions() const
static sk_sp< GrD3DRenderTarget > MakeWrappedRenderTarget(GrD3DGpu *, SkISize, int sampleCnt, const GrD3DTextureResourceInfo &, sk_sp< GrD3DResourceState >)

◆ onWrapBackendTexture()

sk_sp< GrTexture > GrD3DGpu::onWrapBackendTexture ( const GrBackendTexture tex,
GrWrapOwnership  ,
GrWrapCacheable  wrapType,
GrIOType  ioType 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 987 of file GrD3DGpu.cpp.

990 {
991 GrD3DTextureResourceInfo textureInfo;
992 if (!tex.getD3DTextureResourceInfo(&textureInfo)) {
993 return nullptr;
994 }
995
996 if (!check_resource_info(textureInfo)) {
997 return nullptr;
998 }
999
1000 if (!check_tex_resource_info(this->d3dCaps(), textureInfo)) {
1001 return nullptr;
1002 }
1003
1004 // TODO: support protected context
1005 if (tex.isProtected()) {
1006 return nullptr;
1007 }
1008
1009 sk_sp<GrD3DResourceState> state = tex.getGrD3DResourceState();
1010 SkASSERT(state);
1011 return GrD3DTexture::MakeWrappedTexture(this, tex.dimensions(), wrapType, ioType, textureInfo,
1012 std::move(state));
1013}
static bool check_tex_resource_info(const GrD3DCaps &caps, const GrD3DTextureResourceInfo &info)
Definition GrD3DGpu.cpp:968

◆ onWrapCompressedBackendTexture()

sk_sp< GrTexture > GrD3DGpu::onWrapCompressedBackendTexture ( const GrBackendTexture tex,
GrWrapOwnership  ownership,
GrWrapCacheable  wrapType 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1015 of file GrD3DGpu.cpp.

1017 {
1018 return this->onWrapBackendTexture(tex, ownership, wrapType, kRead_GrIOType);
1019}
@ kRead_GrIOType
sk_sp< GrTexture > onWrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType) override
Definition GrD3DGpu.cpp:987

◆ onWrapRenderableBackendTexture()

sk_sp< GrTexture > GrD3DGpu::onWrapRenderableBackendTexture ( const GrBackendTexture tex,
int  sampleCnt,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1021 of file GrD3DGpu.cpp.

1024 {
1025 GrD3DTextureResourceInfo textureInfo;
1026 if (!tex.getD3DTextureResourceInfo(&textureInfo)) {
1027 return nullptr;
1028 }
1029
1030 if (!check_resource_info(textureInfo)) {
1031 return nullptr;
1032 }
1033
1034 if (!check_tex_resource_info(this->d3dCaps(), textureInfo)) {
1035 return nullptr;
1036 }
1037 if (!check_rt_resource_info(this->d3dCaps(), textureInfo, sampleCnt)) {
1038 return nullptr;
1039 }
1040
1041 // TODO: support protected context
1042 if (tex.isProtected()) {
1043 return nullptr;
1044 }
1045
1046 sampleCnt = this->d3dCaps().getRenderTargetSampleCount(sampleCnt, textureInfo.fFormat);
1047
1048 sk_sp<GrD3DResourceState> state = tex.getGrD3DResourceState();
1049 SkASSERT(state);
1050
1052 sampleCnt, cacheable,
1053 textureInfo, std::move(state));
1054}
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const override
static sk_sp< GrD3DTextureRenderTarget > MakeWrappedTextureRenderTarget(GrD3DGpu *, SkISize dimensions, int sampleCnt, GrWrapCacheable, const GrD3DTextureResourceInfo &, sk_sp< GrD3DResourceState >)

◆ onWritePixels()

bool GrD3DGpu::onWritePixels ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  srcColorType,
const GrMipLevel  texels[],
int  mipLevelCount,
bool  prepForTexSampling 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 688 of file GrD3DGpu.cpp.

694 {
695 GrD3DTexture* d3dTex = static_cast<GrD3DTexture*>(surface->asTexture());
696 if (!d3dTex) {
697 return false;
698 }
699
700 // Make sure we have at least the base level
701 if (!mipLevelCount || !texels[0].fPixels) {
702 return false;
703 }
704
706 bool success = false;
707
708 // Need to change the resource state to COPY_DEST in order to upload to it
709 d3dTex->setResourceState(this, D3D12_RESOURCE_STATE_COPY_DEST);
710
711 SkASSERT(mipLevelCount <= d3dTex->maxMipmapLevel() + 1);
712 success = this->uploadToTexture(d3dTex, rect, srcColorType, texels, mipLevelCount);
713
714 if (prepForTexSampling) {
715 d3dTex->setResourceState(this, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
716 }
717
718 return success;
719}

◆ pipelineBuilder()

GrThreadSafePipelineBuilder * GrD3DGpu::pipelineBuilder ( )
overridevirtual

Implements GrGpu.

Definition at line 41 of file GrD3DGpu.cpp.

41 {
42 return nullptr;
43}

◆ prepareSurfacesForBackendAccessAndStateUpdates()

void GrD3DGpu::prepareSurfacesForBackendAccessAndStateUpdates ( SkSpan< GrSurfaceProxy * >  proxies,
SkSurfaces::BackendSurfaceAccess  access,
const skgpu::MutableTextureState newState 
)
overrideprivatevirtual

Reimplemented from GrGpu.

Definition at line 1739 of file GrD3DGpu.cpp.

1742 {
1743 // prepare proxies by transitioning to PRESENT renderState
1744 if (!proxies.empty() && access == SkSurfaces::BackendSurfaceAccess::kPresent) {
1745 GrD3DTextureResource* resource;
1746 for (GrSurfaceProxy* proxy : proxies) {
1747 SkASSERT(proxy->isInstantiated());
1748 if (GrTexture* tex = proxy->peekTexture()) {
1749 resource = static_cast<GrD3DTexture*>(tex);
1750 } else {
1751 GrRenderTarget* rt = proxy->peekRenderTarget();
1752 SkASSERT(rt);
1753 resource = static_cast<GrD3DRenderTarget*>(rt);
1754 }
1755 resource->prepareForPresent(this);
1756 }
1757 }
1758}
void prepareForPresent(GrD3DGpu *gpu)
constexpr bool empty() const
Definition SkSpan_impl.h:96
@ kPresent
back-end surface will be used for presenting to screen

◆ prepareTextureForCrossContextUsage()

std::unique_ptr< GrSemaphore > GrD3DGpu::prepareTextureForCrossContextUsage ( GrTexture )
inlineoverridevirtual

Put this texture in a safe and known state for use across multiple contexts. Depending on the backend, this may return a GrSemaphore. If so, other contexts should wait on that semaphore before using this texture.

Implements GrGpu.

Definition at line 109 of file GrD3DGpu.h.

109 {
110 return nullptr;
111 }

◆ protectedContext()

bool GrD3DGpu::protectedContext ( ) const
inline

Definition at line 55 of file GrD3DGpu.h.

55{ return false; }

◆ queue()

ID3D12CommandQueue * GrD3DGpu::queue ( ) const
inline

Definition at line 44 of file GrD3DGpu.h.

44{ return fQueue.get(); }

◆ refPipelineBuilder()

sk_sp< GrThreadSafePipelineBuilder > GrD3DGpu::refPipelineBuilder ( )
overridevirtual

Implements GrGpu.

Definition at line 45 of file GrD3DGpu.cpp.

45 {
46 return nullptr;
47}

◆ resourceProvider()

GrD3DResourceProvider & GrD3DGpu::resourceProvider ( )
inline

Definition at line 38 of file GrD3DGpu.h.

38{ return fResourceProvider; }

◆ stagingBufferManager()

GrStagingBufferManager * GrD3DGpu::stagingBufferManager ( )
inlineoverridevirtual

Reimplemented from GrGpu.

Definition at line 50 of file GrD3DGpu.h.

50{ return &fStagingBufferManager; }

◆ submit()

void GrD3DGpu::submit ( GrOpsRenderPass renderPass)
overridevirtual

Implements GrGpu.

Definition at line 233 of file GrD3DGpu.cpp.

233 {
234 SkASSERT(fCachedOpsRenderPass.get() == renderPass);
235
236 fCachedOpsRenderPass->submit();
237 fCachedOpsRenderPass.reset();
238}

◆ takeOwnershipOfBuffer()

void GrD3DGpu::takeOwnershipOfBuffer ( sk_sp< GrGpuBuffer buffer)
overridevirtual

Reimplemented from GrGpu.

Definition at line 1760 of file GrD3DGpu.cpp.

1760 {
1761 fCurrentDirectCommandList->addGrBuffer(std::move(buffer));
1762}

◆ uniformsRingBuffer()

GrRingBuffer * GrD3DGpu::uniformsRingBuffer ( )
inlineoverridevirtual

Reimplemented from GrGpu.

Definition at line 53 of file GrD3DGpu.h.

53{ return &fConstantsRingBuffer; }

◆ waitSemaphore()

void GrD3DGpu::waitSemaphore ( GrSemaphore semaphore)
overridevirtual

Implements GrGpu.

Definition at line 1793 of file GrD3DGpu.cpp.

1793 {
1794 SkASSERT(semaphore);
1795 GrD3DSemaphore* d3dSem = static_cast<GrD3DSemaphore*>(semaphore);
1796 // TODO: Do we need to track the lifetime of this?
1797 fQueue->Wait(d3dSem->fence(), d3dSem->value());
1798}

◆ wrapBackendSemaphore()

std::unique_ptr< GrSemaphore > GrD3DGpu::wrapBackendSemaphore ( const GrBackendSemaphore semaphore,
GrSemaphoreWrapType  ,
GrWrapOwnership   
)
overridevirtual

Implements GrGpu.

Definition at line 1775 of file GrD3DGpu.cpp.

1777 {
1778 SkASSERT(this->caps()->backendSemaphoreSupport());
1779 GrD3DFenceInfo fenceInfo;
1780 if (!semaphore.getD3DFenceInfo(&fenceInfo)) {
1781 return nullptr;
1782 }
1783 return GrD3DSemaphore::MakeWrapped(fenceInfo);
1784}
static std::unique_ptr< GrD3DSemaphore > MakeWrapped(const GrD3DFenceInfo &)

◆ xferBarrier()

void GrD3DGpu::xferBarrier ( GrRenderTarget ,
GrXferBarrierType   
)
inlineoverridevirtual

Implements GrGpu.

Definition at line 57 of file GrD3DGpu.h.

57{}

The documentation for this class was generated from the following files: