Remove more uses of GrRenderTarget from GrVkOpsRenderPass.

There are still a couple more uses of GrRenderTarget in the render pass
but they involve larger changes which will be pulled out into their
individual CLs.

Bug: skia:11809
Change-Id: I1f0cc2505250916e32dde03e505ed05c3179bc47
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398656
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2021-04-20 12:42:11 -04:00 committed by Skia Commit-Bot
parent 422f630d5d
commit a36cb40671
5 changed files with 37 additions and 27 deletions

View File

@ -646,16 +646,19 @@ bool GrVkOpsRenderPass::onBindPipeline(const GrProgramInfo& programInfo, const S
// same place (i.e., the target renderTargetProxy) they had best agree. // same place (i.e., the target renderTargetProxy) they had best agree.
SkASSERT(programInfo.origin() == fOrigin); SkASSERT(programInfo.origin() == fOrigin);
if (!fCurrentPipelineState->setAndBindUniforms(fGpu, fRenderTarget, programInfo, currentCB)) { auto colorAttachment = fFramebuffer->colorAttachment();
if (!fCurrentPipelineState->setAndBindUniforms(fGpu, colorAttachment->dimensions(), programInfo,
currentCB)) {
return false; return false;
} }
if (!programInfo.pipeline().isScissorTestEnabled()) { if (!programInfo.pipeline().isScissorTestEnabled()) {
// "Disable" scissor by setting it to the full pipeline bounds. // "Disable" scissor by setting it to the full pipeline bounds.
GrVkPipeline::SetDynamicScissorRectState(fGpu, currentCB, fRenderTarget, fOrigin, GrVkPipeline::SetDynamicScissorRectState(
fGpu, currentCB, colorAttachment->dimensions(), fOrigin,
fCurrentPipelineBounds); fCurrentPipelineBounds);
} }
GrVkPipeline::SetDynamicViewportState(fGpu, currentCB, fRenderTarget); GrVkPipeline::SetDynamicViewportState(fGpu, currentCB, colorAttachment->dimensions());
GrVkPipeline::SetDynamicBlendConstantState(fGpu, currentCB, GrVkPipeline::SetDynamicBlendConstantState(fGpu, currentCB,
programInfo.pipeline().writeSwizzle(), programInfo.pipeline().writeSwizzle(),
programInfo.pipeline().getXferProcessor()); programInfo.pipeline().getXferProcessor());
@ -668,13 +671,14 @@ void GrVkOpsRenderPass::onSetScissorRect(const SkIRect& scissor) {
if (!combinedScissorRect.intersect(fCurrentPipelineBounds, scissor)) { if (!combinedScissorRect.intersect(fCurrentPipelineBounds, scissor)) {
combinedScissorRect = SkIRect::MakeEmpty(); combinedScissorRect = SkIRect::MakeEmpty();
} }
GrVkPipeline::SetDynamicScissorRectState(fGpu, this->currentCommandBuffer(), fRenderTarget, GrVkPipeline::SetDynamicScissorRectState(fGpu, this->currentCommandBuffer(),
fFramebuffer->colorAttachment()->dimensions(),
fOrigin, combinedScissorRect); fOrigin, combinedScissorRect);
} }
#ifdef SK_DEBUG #ifdef SK_DEBUG
void check_sampled_texture(GrTexture* tex, GrRenderTarget* rt, GrVkGpu* gpu) { void check_sampled_texture(GrTexture* tex, GrAttachment* colorAttachment, GrVkGpu* gpu) {
SkASSERT(!tex->isProtected() || (rt->isProtected() && gpu->protectedContext())); SkASSERT(!tex->isProtected() || (colorAttachment->isProtected() && gpu->protectedContext()));
auto vkTex = static_cast<GrVkTexture*>(tex)->textureAttachment(); auto vkTex = static_cast<GrVkTexture*>(tex)->textureAttachment();
SkASSERT(vkTex->currentLayout() == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); SkASSERT(vkTex->currentLayout() == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
} }
@ -685,14 +689,15 @@ bool GrVkOpsRenderPass::onBindTextures(const GrGeometryProcessor& geomProc,
const GrPipeline& pipeline) { const GrPipeline& pipeline) {
#ifdef SK_DEBUG #ifdef SK_DEBUG
SkASSERT(fCurrentPipelineState); SkASSERT(fCurrentPipelineState);
auto colorAttachment = fFramebuffer->colorAttachment();
for (int i = 0; i < geomProc.numTextureSamplers(); ++i) { for (int i = 0; i < geomProc.numTextureSamplers(); ++i) {
check_sampled_texture(geomProcTextures[i]->peekTexture(), fRenderTarget, fGpu); check_sampled_texture(geomProcTextures[i]->peekTexture(), colorAttachment, fGpu);
} }
pipeline.visitTextureEffects([&](const GrTextureEffect& te) { pipeline.visitTextureEffects([&](const GrTextureEffect& te) {
check_sampled_texture(te.texture(), fRenderTarget, fGpu); check_sampled_texture(te.texture(), colorAttachment, fGpu);
}); });
if (GrTexture* dstTexture = pipeline.peekDstTexture()) { if (GrTexture* dstTexture = pipeline.peekDstTexture()) {
check_sampled_texture(dstTexture, fRenderTarget, fGpu); check_sampled_texture(dstTexture, colorAttachment, fGpu);
} }
#endif #endif
if (!fCurrentPipelineState->setAndBindTextures(fGpu, geomProc, pipeline, geomProcTextures, if (!fCurrentPipelineState->setAndBindTextures(fGpu, geomProc, pipeline, geomProcTextures,

View File

@ -670,11 +670,11 @@ void GrVkPipeline::freeGPUData() const {
void GrVkPipeline::SetDynamicScissorRectState(GrVkGpu* gpu, void GrVkPipeline::SetDynamicScissorRectState(GrVkGpu* gpu,
GrVkCommandBuffer* cmdBuffer, GrVkCommandBuffer* cmdBuffer,
const GrRenderTarget* renderTarget, SkISize colorAttachmentDimensions,
GrSurfaceOrigin rtOrigin, GrSurfaceOrigin rtOrigin,
const SkIRect& scissorRect) { const SkIRect& scissorRect) {
SkASSERT(scissorRect.isEmpty() || SkASSERT(scissorRect.isEmpty() ||
SkIRect::MakeWH(renderTarget->width(), renderTarget->height()).contains(scissorRect)); SkIRect::MakeSize(colorAttachmentDimensions).contains(scissorRect));
VkRect2D scissor; VkRect2D scissor;
scissor.offset.x = scissorRect.fLeft; scissor.offset.x = scissorRect.fLeft;
@ -683,7 +683,7 @@ void GrVkPipeline::SetDynamicScissorRectState(GrVkGpu* gpu,
scissor.offset.y = scissorRect.fTop; scissor.offset.y = scissorRect.fTop;
} else { } else {
SkASSERT(kBottomLeft_GrSurfaceOrigin == rtOrigin); SkASSERT(kBottomLeft_GrSurfaceOrigin == rtOrigin);
scissor.offset.y = renderTarget->height() - scissorRect.fBottom; scissor.offset.y = colorAttachmentDimensions.height() - scissorRect.fBottom;
} }
scissor.extent.height = scissorRect.height(); scissor.extent.height = scissorRect.height();
@ -694,13 +694,13 @@ void GrVkPipeline::SetDynamicScissorRectState(GrVkGpu* gpu,
void GrVkPipeline::SetDynamicViewportState(GrVkGpu* gpu, void GrVkPipeline::SetDynamicViewportState(GrVkGpu* gpu,
GrVkCommandBuffer* cmdBuffer, GrVkCommandBuffer* cmdBuffer,
const GrRenderTarget* renderTarget) { SkISize colorAttachmentDimensions) {
// We always use one viewport the size of the RT // We always use one viewport the size of the RT
VkViewport viewport; VkViewport viewport;
viewport.x = 0.0f; viewport.x = 0.0f;
viewport.y = 0.0f; viewport.y = 0.0f;
viewport.width = SkIntToScalar(renderTarget->width()); viewport.width = SkIntToScalar(colorAttachmentDimensions.width());
viewport.height = SkIntToScalar(renderTarget->height()); viewport.height = SkIntToScalar(colorAttachmentDimensions.height());
viewport.minDepth = 0.0f; viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f; viewport.maxDepth = 1.0f;
cmdBuffer->setViewport(gpu, 0, 1, &viewport); cmdBuffer->setViewport(gpu, 0, 1, &viewport);

View File

@ -61,9 +61,13 @@ public:
return fPipelineLayout; return fPipelineLayout;
} }
static void SetDynamicScissorRectState(GrVkGpu*, GrVkCommandBuffer*, const GrRenderTarget*, static void SetDynamicScissorRectState(GrVkGpu*,
GrVkCommandBuffer*,
SkISize colorAttachmentDimensions,
GrSurfaceOrigin, const SkIRect& scissorRect); GrSurfaceOrigin, const SkIRect& scissorRect);
static void SetDynamicViewportState(GrVkGpu*, GrVkCommandBuffer*, const GrRenderTarget*); static void SetDynamicViewportState(GrVkGpu*,
GrVkCommandBuffer*,
SkISize colorAttachmentDimensions);
static void SetDynamicBlendConstantState(GrVkGpu*, static void SetDynamicBlendConstantState(GrVkGpu*,
GrVkCommandBuffer*, GrVkCommandBuffer*,
const GrSwizzle& writeSwizzle, const GrSwizzle& writeSwizzle,

View File

@ -73,10 +73,10 @@ void GrVkPipelineState::freeGPUResources(GrVkGpu* gpu) {
} }
bool GrVkPipelineState::setAndBindUniforms(GrVkGpu* gpu, bool GrVkPipelineState::setAndBindUniforms(GrVkGpu* gpu,
const GrRenderTarget* renderTarget, SkISize colorAttachmentDimensions,
const GrProgramInfo& programInfo, const GrProgramInfo& programInfo,
GrVkCommandBuffer* commandBuffer) { GrVkCommandBuffer* commandBuffer) {
this->setRenderTargetState(renderTarget, programInfo.origin()); this->setRenderTargetState(colorAttachmentDimensions, programInfo.origin());
fGeometryProcessor->setData(fDataManager, *gpu->caps()->shaderCaps(), programInfo.geomProc()); fGeometryProcessor->setData(fDataManager, *gpu->caps()->shaderCaps(), programInfo.geomProc());
for (int i = 0; i < programInfo.pipeline().numFragmentProcessors(); ++i) { for (int i = 0; i < programInfo.pipeline().numFragmentProcessors(); ++i) {
@ -247,20 +247,21 @@ bool GrVkPipelineState::setAndBindInputAttachment(GrVkGpu* gpu,
return true; return true;
} }
void GrVkPipelineState::setRenderTargetState(const GrRenderTarget* rt, GrSurfaceOrigin origin) { void GrVkPipelineState::setRenderTargetState(SkISize colorAttachmentDimensions,
GrSurfaceOrigin origin) {
// Load the RT height uniform if it is needed to y-flip gl_FragCoord. // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
if (fBuiltinUniformHandles.fRTHeightUni.isValid() && if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
fRenderTargetState.fRenderTargetSize.fHeight != rt->height()) { fRenderTargetState.fRenderTargetSize.fHeight != colorAttachmentDimensions.height()) {
fDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, SkIntToScalar(rt->height())); fDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
SkIntToScalar(colorAttachmentDimensions.height()));
} }
// set RT adjustment // set RT adjustment
SkISize dimensions = rt->dimensions();
SkASSERT(fBuiltinUniformHandles.fRTAdjustmentUni.isValid()); SkASSERT(fBuiltinUniformHandles.fRTAdjustmentUni.isValid());
if (fRenderTargetState.fRenderTargetOrigin != origin || if (fRenderTargetState.fRenderTargetOrigin != origin ||
fRenderTargetState.fRenderTargetSize != dimensions) { fRenderTargetState.fRenderTargetSize != colorAttachmentDimensions) {
fRenderTargetState.fRenderTargetSize = dimensions; fRenderTargetState.fRenderTargetSize = colorAttachmentDimensions;
fRenderTargetState.fRenderTargetOrigin = origin; fRenderTargetState.fRenderTargetOrigin = origin;
float rtAdjustmentVec[4]; float rtAdjustmentVec[4];

View File

@ -53,7 +53,7 @@ public:
~GrVkPipelineState(); ~GrVkPipelineState();
bool setAndBindUniforms(GrVkGpu*, const GrRenderTarget*, const GrProgramInfo&, bool setAndBindUniforms(GrVkGpu*, SkISize colorAttachmentDimensions, const GrProgramInfo&,
GrVkCommandBuffer*); GrVkCommandBuffer*);
/** /**
* This must be called after setAndBindUniforms() since that function invalidates texture * This must be called after setAndBindUniforms() since that function invalidates texture
@ -109,7 +109,7 @@ private:
}; };
// Helper for setData() that sets the view matrix and loads the render target height uniform // Helper for setData() that sets the view matrix and loads the render target height uniform
void setRenderTargetState(const GrRenderTarget*, GrSurfaceOrigin); void setRenderTargetState(SkISize colorAttachmentDimensions, GrSurfaceOrigin);
// GrManagedResources // GrManagedResources
sk_sp<const GrVkPipeline> fPipeline; sk_sp<const GrVkPipeline> fPipeline;