Don't flush pipeline state when querying sample locations in GL
This was a relic from back when we could use EXT_raster_multisample.
Since MSAA is now always baked into the framebuffer attachments, this
is no longer necessary.
Bug: skia:
Change-Id: I47c66fcdbd008e057dab5eae457bb70ec8e6bb9f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/208460
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 810457a..bba9545 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -403,20 +403,12 @@
}
}
-int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget, const GrPipeline& pipeline) {
+int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget) {
SkASSERT(this->caps()->sampleLocationsSupport());
SkASSERT(renderTarget->numStencilSamples() > 1);
- SkASSERT(pipeline.isHWAntialiasState());
-
- GrStencilSettings stencil;
- if (pipeline.isStencilEnabled()) {
- SkASSERT(renderTarget->renderTargetPriv().getStencilAttachment());
- stencil.reset(*pipeline.getUserStencil(), pipeline.hasStencilClip(),
- renderTarget->renderTargetPriv().numStencilBits());
- }
SkSTArray<16, SkPoint> sampleLocations;
- this->querySampleLocations(renderTarget, stencil, &sampleLocations);
+ this->querySampleLocations(renderTarget, &sampleLocations);
return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations);
}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index a80fa12..adbe926 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -278,10 +278,7 @@
// Queries the per-pixel HW sample locations for the given render target, and then finds or
// assigns a key that uniquely identifies the sample pattern. The actual sample locations can be
// retrieved with retrieveSampleLocations().
- //
- // NOTE: The pipeline argument is required in order for us to flush draw state prior to querying
- // multisample info. The pipeline itself is not expected to affect sample locations.
- int findOrAssignSamplePatternKey(GrRenderTarget*, const GrPipeline&);
+ int findOrAssignSamplePatternKey(GrRenderTarget*);
// Retrieves the per-pixel HW sample locations for the given sample pattern key, and, as a
// by-product, the actual number of samples in use. (This may differ from the number of samples
@@ -498,8 +495,7 @@
// Queries the effective number of samples in use by the hardware for the given render target,
// and queries the individual sample locations.
- virtual void querySampleLocations(
- GrRenderTarget*, const GrStencilSettings&, SkTArray<SkPoint>*) = 0;
+ virtual void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) = 0;
// Called before certain draws in order to guarantee coherent results from dst reads.
virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0;
diff --git a/src/gpu/GrGpuCommandBuffer.cpp b/src/gpu/GrGpuCommandBuffer.cpp
index e663fd1..a80b088 100644
--- a/src/gpu/GrGpuCommandBuffer.cpp
+++ b/src/gpu/GrGpuCommandBuffer.cpp
@@ -15,6 +15,7 @@
#include "GrMesh.h"
#include "GrPrimitiveProcessor.h"
#include "GrRenderTarget.h"
+#include "GrRenderTargetPriv.h"
#include "SkRect.h"
void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
@@ -99,5 +100,17 @@
}
this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
bounds);
+#ifdef SK_DEBUG
+ GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures();
+ for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
+ processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures();
+ }
+ processorFeatures |= pipeline.getXferProcessor().requestedFeatures();
+ if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
+ // Verify we always have the same sample pattern key, regardless of graphics state.
+ SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
+ == fRenderTarget->renderTargetPriv().getSamplePatternKey());
+ }
+#endif
return true;
}
diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index a066145..6709dc4 100644
--- a/src/gpu/GrProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -231,7 +231,7 @@
if (processorFeatures & GrProcessor::CustomFeatures::kSampleLocations) {
SkASSERT(pipeline.isHWAntialiasState());
- b.add32(renderTarget->renderTargetPriv().getSamplePatternKey(pipeline));
+ b.add32(renderTarget->renderTargetPriv().getSamplePatternKey());
}
// --------DO NOT MOVE HEADER ABOVE THIS LINE--------------------------------------------------
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index f265fba..4897349 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -91,17 +91,13 @@
return this->getStencilAttachment()->bits();
}
-int GrRenderTargetPriv::getSamplePatternKey(const GrPipeline& pipeline) const {
+int GrRenderTargetPriv::getSamplePatternKey() const {
SkASSERT(fRenderTarget->fSampleCnt > 1);
if (GrSamplePatternDictionary::kInvalidSamplePatternKey == fRenderTarget->fSamplePatternKey) {
fRenderTarget->fSamplePatternKey =
- fRenderTarget->getGpu()->findOrAssignSamplePatternKey(fRenderTarget, pipeline);
+ fRenderTarget->getGpu()->findOrAssignSamplePatternKey(fRenderTarget);
}
SkASSERT(GrSamplePatternDictionary::kInvalidSamplePatternKey
!= fRenderTarget->fSamplePatternKey);
- // Verify we always have the same sample pattern key every time this is called, regardless of
- // pipeline state.
- SkASSERT(fRenderTarget->getGpu()->findOrAssignSamplePatternKey(fRenderTarget, pipeline)
- == fRenderTarget->fSamplePatternKey);
return fRenderTarget->fSamplePatternKey;
}
diff --git a/src/gpu/GrRenderTargetPriv.h b/src/gpu/GrRenderTargetPriv.h
index d781a9c..1820415 100644
--- a/src/gpu/GrRenderTargetPriv.h
+++ b/src/gpu/GrRenderTargetPriv.h
@@ -37,19 +37,16 @@
/**
* Returns a unique key that identifies this render target's sample pattern. (Must be
* multisampled.)
- *
- * NOTE: The pipeline argument is only required in case we need to flush draw state and actually
- * query multisample info. The pipeline itself is not expected to affect sample locations.
*/
- int getSamplePatternKey(const GrPipeline&) const;
+ int getSamplePatternKey() const;
/**
- * Retrieves the per-pixel HW sample locations for this render target, and, as a by-product, the actual
- * number of samples in use. (This may differ from fSampleCnt.) Sample locations are returned as
- * 0..1 offsets relative to the top-left corner of the pixel.
+ * Retrieves the per-pixel HW sample locations for this render target, and, as a by-product, the
+ * actual number of samples in use. (This may differ from fSampleCnt.) Sample locations are
+ * returned as 0..1 offsets relative to the top-left corner of the pixel.
*/
- const SkTArray<SkPoint>& getSampleLocations(const GrPipeline& pipeline) const {
- int samplePatternKey = this->getSamplePatternKey(pipeline);
+ const SkTArray<SkPoint>& getSampleLocations() const {
+ int samplePatternKey = this->getSamplePatternKey();
return fRenderTarget->getGpu()->retrieveSampleLocations(samplePatternKey);
}
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index c81fe6b..148b649 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3931,11 +3931,8 @@
}
void GrGLGpu::querySampleLocations(
- GrRenderTarget* renderTarget, const GrStencilSettings& stencilSettings,
- SkTArray<SkPoint>* sampleLocations) {
- this->flushStencil(stencilSettings);
- this->flushHWAAState(renderTarget, true);
- this->flushRenderTarget(static_cast<GrGLRenderTarget*>(renderTarget));
+ GrRenderTarget* renderTarget, SkTArray<SkPoint>* sampleLocations) {
+ this->flushRenderTargetNoColorWrites(static_cast<GrGLRenderTarget*>(renderTarget));
int effectiveSampleCnt;
GR_GL_GetIntegerv(this->glInterface(), GR_GL_SAMPLES, &effectiveSampleCnt);
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 57505b4..a85f918 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -184,8 +184,7 @@
void onResetTextureBindings() override;
- void querySampleLocations(
- GrRenderTarget*, const GrStencilSettings&, SkTArray<SkPoint>*) override;
+ void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override;
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
index 5670f58..bec9e04 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
@@ -263,9 +263,8 @@
== fUsedProcessorFeaturesAllStages_DebugOnly);
if (CustomFeatures::kSampleLocations & fProgramBuilder->header().processorFeatures()) {
- const GrPipeline& pipeline = fProgramBuilder->pipeline();
const SkTArray<SkPoint>& sampleLocations =
- fProgramBuilder->renderTarget()->renderTargetPriv().getSampleLocations(pipeline);
+ fProgramBuilder->renderTarget()->renderTargetPriv().getSampleLocations();
this->definitions().append("const float2 _sampleOffsets[] = float2[](");
for (int i = 0; i < sampleLocations.count(); ++i) {
SkPoint offset = sampleLocations[i] - SkPoint::Make(.5f, .5f);
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index d36e425..dae2b6c 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -42,7 +42,7 @@
GrPixelConfig config() const { return fRenderTarget->config(); }
int effectiveSampleCnt() const {
SkASSERT(GrProcessor::CustomFeatures::kSampleLocations & header().processorFeatures());
- return fRenderTarget->renderTargetPriv().getSampleLocations(fPipeline).count();
+ return fRenderTarget->renderTargetPriv().getSampleLocations().count();
}
GrSurfaceOrigin origin() const { return fOrigin; }
const GrPipeline& pipeline() const { return fPipeline; }
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 1e99683..c9095fe 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -54,8 +54,7 @@
void onResetContext(uint32_t resetBits) override {}
- void querySampleLocations(
- GrRenderTarget*, const GrStencilSettings&, SkTArray<SkPoint>*) override {
+ void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override {
SkASSERT(!this->caps()->sampleLocationsSupport());
SK_ABORT("Sample locations not implemented for mock GPU.");
}
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index 895866d..e806996 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -131,8 +131,7 @@
void onResetContext(uint32_t resetBits) override {}
- void querySampleLocations(
- GrRenderTarget*, const GrStencilSettings&, SkTArray<SkPoint>*) override {
+ void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override {
SkASSERT(!this->caps()->sampleLocationsSupport());
SK_ABORT("Sample locations not yet implemented for Metal.");
}
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 93f746e..f161353 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -73,8 +73,7 @@
kSkip_SyncQueue
};
- void querySampleLocations(
- GrRenderTarget*, const GrStencilSettings&, SkTArray<SkPoint>*) override {
+ void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override {
SkASSERT(!this->caps()->sampleLocationsSupport());
SK_ABORT("Sample locations not yet implemented for Vulkan.");
}