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

Commit 1e63279

Browse files
lhkbobSkia Commit-Bot
authored andcommitted
Only use scissor state for native clears
This is the first of many CLs that progressively refine the clipping, scissoring, and clearing APIs. The series of changes focus on simplifying the clear APIs, consolidating clip intersection logic, and moving towards a more explicitly sized render target context (where confusion between approx-fit and exact-fit is handled externally, although I don't take it that far). Next step will be to propagate the simpler calls up to GrRTC. Bug:skia:10205 Change-Id: Idb0c58a63b7a3950a92604dd4c03536d668be7c4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290123 Commit-Queue: Michael Ludwig <[email protected]> Reviewed-by: Chris Dalton <[email protected]>
1 parent 1f60733 commit 1e63279

24 files changed

+135
-155
lines changed

src/gpu/GrOpsRenderPass.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
#include "include/gpu/GrContext.h"
1212
#include "src/gpu/GrCaps.h"
1313
#include "src/gpu/GrContextPriv.h"
14-
#include "src/gpu/GrFixedClip.h"
14+
#include "src/gpu/GrCpuBuffer.h"
1515
#include "src/gpu/GrGpu.h"
1616
#include "src/gpu/GrPrimitiveProcessor.h"
1717
#include "src/gpu/GrProgramInfo.h"
1818
#include "src/gpu/GrRenderTarget.h"
1919
#include "src/gpu/GrRenderTargetPriv.h"
20+
#include "src/gpu/GrScissorState.h"
2021
#include "src/gpu/GrSimpleMesh.h"
2122
#include "src/gpu/GrTexturePriv.h"
2223

@@ -37,21 +38,22 @@ void GrOpsRenderPass::end() {
3738
this->resetActiveBuffers();
3839
}
3940

40-
void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
41+
void GrOpsRenderPass::clear(const GrScissorState& scissor, const SkPMColor4f& color) {
4142
SkASSERT(fRenderTarget);
4243
// A clear at this level will always be a true clear, so make sure clears were not supposed to
4344
// be redirected to draws instead
4445
SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
45-
SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
46+
SkASSERT(!scissor.enabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
4647
fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
47-
this->onClear(clip, color);
48+
this->onClear(scissor, color);
4849
}
4950

50-
void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
51+
void GrOpsRenderPass::clearStencilClip(const GrScissorState& scissor, bool insideStencilMask) {
5152
// As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
5253
SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
54+
SkASSERT(!scissor.enabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
5355
fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
54-
this->onClearStencilClip(clip, insideStencilMask);
56+
this->onClearStencilClip(scissor, insideStencilMask);
5557
}
5658

5759
void GrOpsRenderPass::executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable) {

src/gpu/GrOpsRenderPass.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include "src/gpu/ops/GrDrawOp.h"
1414

1515
class GrOpFlushState;
16-
class GrFixedClip;
1716
class GrGpu;
1817
class GrPipeline;
1918
class GrPrimitiveProcessor;
2019
class GrProgramInfo;
2120
class GrRenderTarget;
21+
class GrScissorState;
2222
class GrSemaphore;
2323
struct SkIRect;
2424
struct SkRect;
@@ -120,11 +120,17 @@ class GrOpsRenderPass {
120120
virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
121121

122122
/**
123-
* Clear the owned render target. Ignores the draw state and clip.
123+
* Clear the owned render target. Clears the full target if 'scissor' is disabled, otherwise it
124+
* is restricted to 'scissor'. Must check caps.performPartialClearsAsDraws() before using an
125+
* enabled scissor test; must check caps.performColorClearsAsDraws() before using this at all.
124126
*/
125-
void clear(const GrFixedClip&, const SkPMColor4f&);
127+
void clear(const GrScissorState& scissor, const SkPMColor4f&);
126128

127-
void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
129+
/**
130+
* Same as clear() but modifies the stencil; check caps.performStencilClearsAsDraws() and
131+
* caps.performPartialClearsAsDraws().
132+
*/
133+
void clearStencilClip(const GrScissorState& scissor, bool insideStencilMask);
128134

129135
/**
130136
* Executes the SkDrawable object for the underlying backend.
@@ -189,8 +195,8 @@ class GrOpsRenderPass {
189195
virtual void onDrawIndexedIndirect(const GrBuffer*, size_t offset, int drawCount) {
190196
SK_ABORT("Not implemented."); // Only called if caps.nativeDrawIndirectSupport().
191197
}
192-
virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0;
193-
virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
198+
virtual void onClear(const GrScissorState&, const SkPMColor4f&) = 0;
199+
virtual void onClearStencilClip(const GrScissorState&, bool insideStencilMask) = 0;
194200
virtual void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}
195201

196202
enum class DrawPipelineStatus {

src/gpu/GrRenderTargetContext.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ void GrRenderTargetContext::internalClear(const GrFixedClip& clip,
558558
fContext, SkIRect::MakeEmpty(), color, /* fullscreen */ true));
559559
}
560560
} else {
561-
if (this->caps()->performPartialClearsAsDraws()) {
561+
if (this->caps()->performPartialClearsAsDraws() || clip.hasWindowRectangles()) {
562562
// performPartialClearsAsDraws() also returns true if any clear has to be a draw.
563563
GrPaint paint;
564564
clear_to_grpaint(color, &paint);
@@ -567,7 +567,7 @@ void GrRenderTargetContext::internalClear(const GrFixedClip& clip,
567567
GrFillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(),
568568
SkRect::Make(clip.scissorRect())));
569569
} else {
570-
std::unique_ptr<GrOp> op(GrClearOp::Make(fContext, clip, color,
570+
std::unique_ptr<GrOp> op(GrClearOp::Make(fContext, clip.scissorState(), color,
571571
this->asSurfaceProxy()));
572572
// This version of the clear op factory can return null if the clip doesn't intersect
573573
// with the surface proxy's boundary
@@ -979,18 +979,23 @@ void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool i
979979
void GrRenderTargetContext::internalStencilClear(const GrFixedClip& clip, bool insideStencilMask) {
980980
this->setNeedsStencil(/* useMixedSamplesIfNotMSAA = */ false);
981981

982-
if (this->caps()->performStencilClearsAsDraws()) {
982+
bool clearWithDraw = this->caps()->performStencilClearsAsDraws() ||
983+
(clip.scissorEnabled() && this->caps()->performPartialClearsAsDraws());
984+
// TODO(michaelludwig): internalStencilClear will eventually just take a GrScissorState so
985+
// we won't need to check window rectangles here.
986+
if (clearWithDraw || clip.hasWindowRectangles()) {
983987
const GrUserStencilSettings* ss = GrStencilSettings::SetClipBitSettings(insideStencilMask);
984-
SkRect rtRect = SkRect::MakeWH(this->width(), this->height());
988+
SkRect rect = clip.scissorEnabled() ? SkRect::Make(clip.scissorRect())
989+
: SkRect::MakeWH(this->width(), this->height());
985990

986991
// Configure the paint to have no impact on the color buffer
987992
GrPaint paint;
988993
paint.setXPFactory(GrDisableColorXPFactory::Get());
989994
this->addDrawOp(clip, GrFillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(),
990-
rtRect, ss));
995+
rect, ss));
991996
} else {
992-
std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make(fContext, clip, insideStencilMask,
993-
this->asRenderTargetProxy()));
997+
std::unique_ptr<GrOp> op(GrClearStencilClipOp::Make(
998+
fContext, clip.scissorState(), insideStencilMask, this->asRenderTargetProxy()));
994999
if (!op) {
9951000
return;
9961001
}

src/gpu/d3d/GrD3DCommandList.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "src/gpu/d3d/GrD3DCommandList.h"
99

10+
#include "src/gpu/GrScissorState.h"
1011
#include "src/gpu/d3d/GrD3DBuffer.h"
1112
#include "src/gpu/d3d/GrD3DGpu.h"
1213
#include "src/gpu/d3d/GrD3DPipelineState.h"
@@ -296,12 +297,13 @@ void GrD3DDirectCommandList::drawIndexedInstanced(unsigned int indexCount,
296297

297298
void GrD3DDirectCommandList::clearRenderTargetView(GrD3DRenderTarget* renderTarget,
298299
const SkPMColor4f& color,
299-
const GrFixedClip& clip) {
300+
const GrScissorState& scissor) {
301+
SkASSERT(!scissor.enabled()); // no cliprects for now
300302
this->addingWork();
301303
this->addResource(renderTarget->resource());
302304
fCommandList->ClearRenderTargetView(renderTarget->colorRenderTargetView(),
303305
color.vec(),
304-
0, NULL); // no cliprects for now
306+
0, NULL);
305307
}
306308

307309
////////////////////////////////////////////////////////////////////////////////////////////////////

src/gpu/d3d/GrD3DCommandList.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GrD3DRenderTarget;
2222
class GrD3DRootSignature;
2323
class GrD3DTextureResource;
2424

25-
class GrFixedClip;
25+
class GrScissorState;
2626

2727
class GrD3DCommandList {
2828
public:
@@ -134,7 +134,7 @@ class GrD3DDirectCommandList : public GrD3DCommandList {
134134
unsigned int startInstance);
135135

136136
void clearRenderTargetView(GrD3DRenderTarget* renderTarget, const SkPMColor4f& color,
137-
const GrFixedClip& clip);
137+
const GrScissorState& scissor);
138138
private:
139139
GrD3DDirectCommandList(gr_cp<ID3D12CommandAllocator> allocator,
140140
gr_cp<ID3D12GraphicsCommandList> commandList);

src/gpu/d3d/GrD3DGpu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,12 @@ bool GrD3DGpu::uploadToTexture(GrD3DTexture* tex, int left, int top, int width,
563563
return true;
564564
}
565565

566-
void GrD3DGpu::clear(const GrFixedClip& clip, const SkPMColor4f& color, GrRenderTarget* rt) {
566+
void GrD3DGpu::clear(const GrScissorState& scissor, const SkPMColor4f& color, GrRenderTarget* rt) {
567567
GrD3DRenderTarget* d3dRT = static_cast<GrD3DRenderTarget*>(rt);
568568

569569
d3dRT->setResourceState(this, D3D12_RESOURCE_STATE_RENDER_TARGET);
570570

571-
fCurrentDirectCommandList->clearRenderTargetView(d3dRT, color, clip);
571+
fCurrentDirectCommandList->clearRenderTargetView(d3dRT, color, scissor);
572572
}
573573

574574
static bool check_resource_info(const GrD3DTextureResourceInfo& info) {

src/gpu/d3d/GrD3DGpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class GrD3DGpu : public GrGpu {
9999
return nullptr;
100100
}
101101

102-
void clear(const GrFixedClip& clip, const SkPMColor4f& color, GrRenderTarget*);
102+
void clear(const GrScissorState& scissor, const SkPMColor4f& color, GrRenderTarget*);
103103

104104
void submit(GrOpsRenderPass* renderPass) override;
105105

src/gpu/d3d/GrD3DOpsRenderPass.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ GrGpu* GrD3DOpsRenderPass::gpu() { return fGpu; }
4646

4747
void GrD3DOpsRenderPass::onBegin() {
4848
if (GrLoadOp::kClear == fColorLoadOp) {
49-
GrFixedClip clip;
50-
fGpu->clear(clip, fClearColor, fRenderTarget);
49+
fGpu->clear(GrScissorState(), fClearColor, fRenderTarget);
5150
}
5251
}
5352

@@ -234,6 +233,6 @@ void GrD3DOpsRenderPass::onDrawIndexedInstanced(int indexCount, int baseIndex, i
234233
fGpu->stats()->incNumDraws();
235234
}
236235

237-
void GrD3DOpsRenderPass::onClear(const GrFixedClip& clip, const SkPMColor4f& color) {
238-
fGpu->clear(clip, color, fRenderTarget);
236+
void GrD3DOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
237+
fGpu->clear(scissor, color, fRenderTarget);
239238
}

src/gpu/d3d/GrD3DOpsRenderPass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class GrD3DOpsRenderPass : public GrOpsRenderPass {
5656
void onDrawIndirect(const GrBuffer*, size_t offset, int drawCount) override {}
5757
void onDrawIndexedIndirect(const GrBuffer*, size_t offset, int drawCount) override {}
5858

59-
void onClear(const GrFixedClip&, const SkPMColor4f& color) override;
59+
void onClear(const GrScissorState& scissor, const SkPMColor4f& color) override;
6060

61-
void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override {}
61+
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override {}
6262

6363
GrD3DGpu* fGpu;
6464

src/gpu/dawn/GrDawnOpsRenderPass.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ void GrDawnOpsRenderPass::submit() {
9494
fGpu->appendCommandBuffer(fEncoder.Finish());
9595
}
9696

97-
void GrDawnOpsRenderPass::onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
97+
void GrDawnOpsRenderPass::onClearStencilClip(const GrScissorState& scissor,
98+
bool insideStencilMask) {
99+
SkASSERT(!scissor.enabled());
98100
fPassEncoder.EndPass();
99101
fPassEncoder = beginRenderPass(wgpu::LoadOp::Load, wgpu::LoadOp::Clear);
100102
}
101103

102-
void GrDawnOpsRenderPass::onClear(const GrFixedClip& clip, const SkPMColor4f& color) {
104+
void GrDawnOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
105+
SkASSERT(!scissor.enabled());
103106
fPassEncoder.EndPass();
104107
fPassEncoder = beginRenderPass(wgpu::LoadOp::Clear, wgpu::LoadOp::Load);
105108
}

0 commit comments

Comments
 (0)