Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 47111d1

Browse files
egdanielSkia Commit-Bot
authored andcommitted
Fix d3d clear op rect.
Make sure we take into account the origin when setting this rect. Change-Id: I9cd35a25cb1489984597946bbeb7563a347c7c86 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296518 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
1 parent 83cd46b commit 47111d1

File tree

5 files changed

+35
-43
lines changed

5 files changed

+35
-43
lines changed

src/gpu/d3d/GrD3DCommandList.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,33 +334,25 @@ void GrD3DDirectCommandList::drawIndexedInstanced(unsigned int indexCount,
334334

335335
void GrD3DDirectCommandList::clearRenderTargetView(const GrD3DRenderTarget* renderTarget,
336336
const SkPMColor4f& color,
337-
const GrScissorState& scissor) {
337+
const D3D12_RECT* rect) {
338338
this->addingWork();
339339
this->addResource(renderTarget->resource());
340340
if (renderTarget->numSamples() > 1) {
341341
this->addResource(renderTarget->msaaTextureResource()->resource());
342342
}
343-
unsigned int numRects = 0;
344-
D3D12_RECT scissorRect;
345-
D3D12_RECT* scissorRectPtr = nullptr;
346-
if (scissor.enabled()) {
347-
scissorRect = { scissor.rect().left(), scissor.rect().top(),
348-
scissor.rect().right(), scissor.rect().bottom() };
349-
scissorRectPtr = &scissorRect;
350-
}
343+
unsigned int numRects = rect ? 1 : 0;
351344
fCommandList->ClearRenderTargetView(renderTarget->colorRenderTargetView(),
352-
color.vec(),
353-
numRects, scissorRectPtr);
345+
color.vec(), numRects, rect);
354346
}
355347

356348
void GrD3DDirectCommandList::clearDepthStencilView(const GrD3DStencilAttachment* stencil,
357349
uint8_t stencilClearValue,
358350
const D3D12_RECT* rect) {
359351
this->addingWork();
360352
this->addResource(stencil->resource());
361-
353+
unsigned int numRects = rect ? 1 : 0;
362354
fCommandList->ClearDepthStencilView(stencil->view(), D3D12_CLEAR_FLAG_STENCIL, 0,
363-
stencilClearValue, 1, rect);
355+
stencilClearValue, numRects, rect);
364356
}
365357

366358
void GrD3DDirectCommandList::setRenderTarget(const GrD3DRenderTarget* renderTarget) {

src/gpu/d3d/GrD3DCommandList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class GrD3DDirectCommandList : public GrD3DCommandList {
144144
unsigned int startInstance);
145145

146146
void clearRenderTargetView(const GrD3DRenderTarget* renderTarget, const SkPMColor4f& color,
147-
const GrScissorState& scissor);
147+
const D3D12_RECT* rect);
148148
void clearDepthStencilView(const GrD3DStencilAttachment*, uint8_t stencilClearValue,
149149
const D3D12_RECT* rect);
150150
void setRenderTarget(const GrD3DRenderTarget* renderTarget);

src/gpu/d3d/GrD3DGpu.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,6 @@ bool GrD3DGpu::uploadToTexture(GrD3DTexture* tex, int left, int top, int width,
567567
return true;
568568
}
569569

570-
void GrD3DGpu::clear(const GrScissorState& scissor, const SkPMColor4f& color, GrRenderTarget* rt) {
571-
GrD3DRenderTarget* d3dRT = static_cast<GrD3DRenderTarget*>(rt);
572-
573-
d3dRT->setResourceState(this, D3D12_RESOURCE_STATE_RENDER_TARGET);
574-
575-
fCurrentDirectCommandList->clearRenderTargetView(d3dRT, color, scissor);
576-
}
577-
578570
static bool check_resource_info(const GrD3DTextureResourceInfo& info) {
579571
if (!info.fResource.get()) {
580572
return false;

src/gpu/d3d/GrD3DGpu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class GrD3DGpu : public GrGpu {
9999
return nullptr;
100100
}
101101

102-
void clear(const GrScissorState& scissor, const SkPMColor4f& color, GrRenderTarget*);
103-
104102
void submit(GrOpsRenderPass* renderPass) override;
105103

106104
void checkFinishProcs() override {}

src/gpu/d3d/GrD3DOpsRenderPass.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ void GrD3DOpsRenderPass::onBegin() {
4949
fGpu->currentCommandList()->setRenderTarget(d3dRT);
5050

5151
if (GrLoadOp::kClear == fColorLoadOp) {
52-
fGpu->currentCommandList()->clearRenderTargetView(
53-
d3dRT, fClearColor, GrScissorState(fRenderTarget->dimensions()));
52+
// Passing in nullptr for the rect clears the entire d3d RT. Is this correct? Does the load
53+
// op respect the logical bounds of a RT?
54+
fGpu->currentCommandList()->clearRenderTargetView(d3dRT, fClearColor, nullptr);
5455
}
5556

5657
if (auto stencil = d3dRT->renderTargetPriv().getStencilAttachment()) {
@@ -245,8 +246,32 @@ void GrD3DOpsRenderPass::onDrawIndexedInstanced(int indexCount, int baseIndex, i
245246
fGpu->stats()->incNumDraws();
246247
}
247248

249+
static D3D12_RECT scissor_to_d3d_clear_rect(const GrScissorState& scissor,
250+
const GrSurface* surface,
251+
GrSurfaceOrigin origin) {
252+
D3D12_RECT clearRect;
253+
// Flip rect if necessary
254+
SkIRect d3dRect;
255+
if (!scissor.enabled()) {
256+
d3dRect.setXYWH(0, 0, surface->width(), surface->height());
257+
} else if (kBottomLeft_GrSurfaceOrigin != origin) {
258+
d3dRect = scissor.rect();
259+
} else {
260+
d3dRect.setLTRB(scissor.rect().fLeft, surface->height() - scissor.rect().fBottom,
261+
scissor.rect().fRight, surface->height() - scissor.rect().fTop);
262+
}
263+
clearRect.left = d3dRect.fLeft;
264+
clearRect.right = d3dRect.fRight;
265+
clearRect.top = d3dRect.fTop;
266+
clearRect.bottom = d3dRect.fBottom;
267+
return clearRect;
268+
}
269+
248270
void GrD3DOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
249-
fGpu->clear(scissor, color, fRenderTarget);
271+
D3D12_RECT clearRect = scissor_to_d3d_clear_rect(scissor, fRenderTarget, fOrigin);
272+
auto d3dRT = static_cast<GrD3DRenderTarget*>(fRenderTarget);
273+
SkASSERT(d3dRT->grD3DResourceState()->getResourceState() == D3D12_RESOURCE_STATE_RENDER_TARGET);
274+
fGpu->currentCommandList()->clearRenderTargetView(d3dRT, color, &clearRect);
250275
}
251276

252277
void GrD3DOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) {
@@ -264,22 +289,7 @@ void GrD3DOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool
264289
stencilColor = (1 << (stencilBitCount - 1));
265290
}
266291

267-
D3D12_RECT clearRect;
268-
// Flip rect if necessary
269-
SkIRect d3dRect;
270-
if (!scissor.enabled()) {
271-
d3dRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height());
272-
} else if (kBottomLeft_GrSurfaceOrigin != fOrigin) {
273-
d3dRect = scissor.rect();
274-
} else {
275-
d3dRect.setLTRB(scissor.rect().fLeft, fRenderTarget->height() - scissor.rect().fBottom,
276-
scissor.rect().fRight, fRenderTarget->height() - scissor.rect().fTop);
277-
}
278-
279-
clearRect.left = d3dRect.fLeft;
280-
clearRect.right = d3dRect.fRight;
281-
clearRect.top = d3dRect.fTop;
282-
clearRect.bottom = d3dRect.fBottom;
292+
D3D12_RECT clearRect = scissor_to_d3d_clear_rect(scissor, fRenderTarget, fOrigin);
283293

284294
auto d3dStencil = static_cast<GrD3DStencilAttachment*>(sb);
285295
fGpu->currentCommandList()->clearDepthStencilView(d3dStencil, stencilColor, &clearRect);

0 commit comments

Comments
 (0)