69void GrVkOpsRenderPass::setAttachmentLayouts(LoadFromResolve loadFromResolve) {
128 vkStencil->setImageLayout(fGpu,
146 if ((0 != granularity.
width && 1 != granularity.
width)) {
148 int rightAdj = srcBounds.
fRight % granularity.
width;
150 rightAdj = granularity.
width - rightAdj;
153 if (dstBounds->
fRight > maxWidth) {
154 dstBounds->
fRight = maxWidth;
155 dstBounds->
fLeft = 0;
165 if ((0 != granularity.
height && 1 != granularity.
height)) {
168 if (bottomAdj != 0) {
169 bottomAdj = granularity.
height - bottomAdj;
172 if (dstBounds->
fBottom > maxHeight) {
173 dstBounds->
fBottom = maxHeight;
184bool GrVkOpsRenderPass::beginRenderPass(
const VkClearValue& clearColor,
185 LoadFromResolve loadFromResolve) {
186 this->setAttachmentLayouts(loadFromResolve);
188 bool firstSubpassUsesSecondaryCB =
204 if ((0 != granularity.
width && 1 != granularity.
width) ||
210 dimensions.height());
212 adjustedBounds = nativeBounds;
216 adjustedBounds, firstSubpassUsesSecondaryCB)) {
217 if (fCurrentSecondaryCommandBuffer) {
218 fCurrentSecondaryCommandBuffer->end(fGpu);
220 fCurrentRenderPass =
nullptr;
225 this->loadResolveIntoMSAA(adjustedBounds);
252 if (!fCurrentRenderPass) {
259 if (!fCurrentSecondaryCommandBuffer) {
260 fCurrentRenderPass =
nullptr;
263 fCurrentSecondaryCommandBuffer->begin(fGpu, fFramebuffer.
get(), fCurrentRenderPass);
272 return this->beginRenderPass(vkClearColor, fLoadFromResolve);
275bool GrVkOpsRenderPass::initWrapped() {
279 fCurrentRenderPass->
ref();
282 if (!fCurrentSecondaryCommandBuffer) {
292GrGpu* GrVkOpsRenderPass::gpu() {
return fGpu; }
295 if (fCurrentSecondaryCommandBuffer) {
296 return fCurrentSecondaryCommandBuffer.get();
304void GrVkOpsRenderPass::loadResolveIntoMSAA(
const SkIRect& nativeBounds) {
323 if (!fCurrentRenderPass) {
329 if (this->wrapsSecondaryCommandBuffer()) {
334 std::move(fCurrentSecondaryCommandBuffer));
338 if (fCurrentSecondaryCommandBuffer) {
370 for (
int i = 0;
i < sampledProxies.
size(); ++
i) {
371 if (sampledProxies[
i]->isInstantiated()) {
372 SkASSERT(sampledProxies[
i]->asTextureProxy());
384 fFramebuffer = std::move(framebuffer);
390 fSelfDependencyFlags = selfDepFlags;
391 fLoadFromResolve = loadFromResolve;
393 if (this->wrapsSecondaryCommandBuffer()) {
394 return this->initWrapped();
397 return this->init(colorInfo, resolveInfo, stencilInfo);
401 if (fCurrentSecondaryCommandBuffer) {
405 fCurrentSecondaryCommandBuffer.release()->recycle(fGpu->
cmdPool());
407 if (fCurrentRenderPass) {
408 fCurrentRenderPass->
unref();
409 fCurrentRenderPass =
nullptr;
411 fCurrentCBIsEmpty =
true;
414 fFramebuffer.
reset();
419 fOverridePipelinesForResolveLoad =
false;
426bool GrVkOpsRenderPass::wrapsSecondaryCommandBuffer()
const {
432void GrVkOpsRenderPass::onClearStencilClip(
const GrScissorState& scissor,
bool insideStencilMask) {
433 if (!fCurrentRenderPass) {
449 if (insideStencilMask) {
450 vkStencilColor.
stencil = (1 << (stencilBitCount - 1));
461 vkRect = scissor.
rect();
473 uint32_t stencilIndex;
481 this->currentCommandBuffer()->
clearAttachments(fGpu, 1, &attachment, 1, &clearRect);
482 fCurrentCBIsEmpty =
false;
485void GrVkOpsRenderPass::onClear(
const GrScissorState& scissor, std::array<float, 4>
color) {
486 if (!fCurrentRenderPass) {
509 vkRect = scissor.
rect();
527 this->currentCommandBuffer()->
clearAttachments(fGpu, 1, &attachment, 1, &clearRect);
528 fCurrentCBIsEmpty =
false;
533void GrVkOpsRenderPass::addAdditionalRenderPass(
bool mustUseSecondaryCommandBuffer) {
534 SkASSERT(!this->wrapsSecondaryCommandBuffer());
543 fOverridePipelinesForResolveLoad |=
559 fCurrentRenderPass->
unref();
560 fCurrentRenderPass =
nullptr;
563 auto fb = vkRT->
getFramebuffer(withResolve, withStencil, fSelfDependencyFlags, loadFromResolve);
570 const GrVkResourceProvider::CompatibleRPHandle& rpHandle =
579 if (!fCurrentRenderPass) {
584 mustUseSecondaryCommandBuffer) {
587 if (!fCurrentSecondaryCommandBuffer) {
588 fCurrentRenderPass =
nullptr;
591 fCurrentSecondaryCommandBuffer->begin(fGpu, fFramebuffer.
get(), fCurrentRenderPass);
597 this->beginRenderPass(vkClearColor, loadFromResolve);
601 if (!fCurrentRenderPass) {
605 if (fCurrentSecondaryCommandBuffer) {
606 fCurrentSecondaryCommandBuffer->end(fGpu);
615 this->addAdditionalRenderPass(
false);
620void GrVkOpsRenderPass::onEnd() {
621 if (fCurrentSecondaryCommandBuffer && !this->wrapsSecondaryCommandBuffer()) {
622 fCurrentSecondaryCommandBuffer->end(fGpu);
626bool GrVkOpsRenderPass::onBindPipeline(
const GrProgramInfo& programInfo,
const SkRect& drawBounds) {
627 if (!fCurrentRenderPass) {
634 rtRect.
roundOut(&fCurrentPipelineBounds);
642 VkRenderPass compatibleRenderPass = fCurrentRenderPass->
vkRenderPass();
644 fRenderTarget, programInfo, compatibleRenderPass, fOverridePipelinesForResolveLoad);
645 if (!fCurrentPipelineState) {
656 if (!fCurrentPipelineState->
setAndBindUniforms(fGpu, colorAttachment->dimensions(), programInfo,
664 fGpu, currentCB, colorAttachment->dimensions(),
fOrigin,
665 fCurrentPipelineBounds);
675void GrVkOpsRenderPass::onSetScissorRect(
const SkIRect& scissor) {
677 if (!combinedScissorRect.
intersect(fCurrentPipelineBounds, scissor)) {
688 auto vkTex =
static_cast<GrVkTexture*
>(tex)->textureImage();
700 check_sampled_texture(geomProcTextures[
i]->peekTexture(), colorAttachment, fGpu);
703 check_sampled_texture(te.
texture(), colorAttachment, fGpu);
706 check_sampled_texture(dstTexture, colorAttachment, fGpu);
709 if (!fCurrentPipelineState->
setAndBindTextures(fGpu, geomProc, pipeline, geomProcTextures,
710 this->currentCommandBuffer())) {
720 this->currentCommandBuffer());
730 if (!fCurrentRenderPass) {
747 uint32_t binding = 0;
750 SkASSERT(!gpuVertexBuffer->isCpuBuffer());
751 SkASSERT(!gpuVertexBuffer->isMapped());
754 if (instanceBuffer) {
757 SkASSERT(!gpuInstanceBuffer->isCpuBuffer());
758 SkASSERT(!gpuInstanceBuffer->isMapped());
759 currCmdBuf->
bindInputBuffer(fGpu, binding++, std::move(instanceBuffer));
763 SkASSERT(!gpuIndexBuffer->isCpuBuffer());
764 SkASSERT(!gpuIndexBuffer->isMapped());
769void GrVkOpsRenderPass::onDrawInstanced(
int instanceCount,
771 int vertexCount,
int baseVertex) {
772 if (!fCurrentRenderPass) {
777 this->currentCommandBuffer()->
draw(fGpu, vertexCount, instanceCount, baseVertex, baseInstance);
779 fCurrentCBIsEmpty =
false;
782void GrVkOpsRenderPass::onDrawIndexedInstanced(
int indexCount,
int baseIndex,
int instanceCount,
783 int baseInstance,
int baseVertex) {
784 if (!fCurrentRenderPass) {
789 this->currentCommandBuffer()->
drawIndexed(fGpu, indexCount, instanceCount,
790 baseIndex, baseVertex, baseInstance);
792 fCurrentCBIsEmpty =
false;
795void GrVkOpsRenderPass::onDrawIndirect(
const GrBuffer* drawIndirectBuffer,
size_t offset,
798 if (!fCurrentRenderPass) {
807 uint32_t remainingDraws = drawCount;
809 while (remainingDraws >= 1) {
810 uint32_t currDrawCount =
std::min(remainingDraws, maxDrawCount);
813 remainingDraws -= currDrawCount;
814 offset += stride * currDrawCount;
817 fCurrentCBIsEmpty =
false;
820void GrVkOpsRenderPass::onDrawIndexedIndirect(
const GrBuffer* drawIndirectBuffer,
size_t offset,
823 if (!fCurrentRenderPass) {
831 uint32_t remainingDraws = drawCount;
833 while (remainingDraws >= 1) {
834 uint32_t currDrawCount =
std::min(remainingDraws, maxDrawCount);
837 remainingDraws -= currDrawCount;
838 offset += stride * currDrawCount;
841 fCurrentCBIsEmpty =
false;
847 if (!fCurrentRenderPass) {
856 if (!fCurrentSecondaryCommandBuffer) {
858 this->addAdditionalRenderPass(
true);
860 if (!fCurrentRenderPass) {
865 SkASSERT(fCurrentSecondaryCommandBuffer);
873#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
874 vkInfo.fFromSwapchainOrAndroidWindow =
883 fCurrentCBIsEmpty =
false;
885 drawable->draw(
info);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
int GrBackendFormatStencilBits(const GrBackendFormat &format)
std::function< void(GrDeferredTextureUploadWritePixelsFn &)> GrDeferredTextureUploadFn
@ kBottomLeft_GrSurfaceOrigin
void adjust_bounds_to_granularity(SkIRect *dstBounds, const SkIRect &srcBounds, const VkExtent2D &granularity, int maxWidth, int maxHeight)
void get_vk_load_store_ops(GrLoadOp loadOpIn, GrStoreOp storeOpIn, VkAttachmentLoadOp *loadOp, VkAttachmentStoreOp *storeOp)
#define SK_ABORT(message,...)
sk_sp< T > sk_ref_sp(T *obj)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static constexpr bool SkToBool(const T &x)
virtual bool isCpuBuffer() const =0
bool nativeDrawIndirectSupport() const
bool usePrimitiveRestart() const
GrDirectContextPriv priv()
int numTextureSamplers() const
const GrDirectContext * getContext() const
const GrCaps * caps() const
void set(GrRenderTarget *rt, GrSurfaceOrigin origin)
GrRenderTarget * fRenderTarget
const skgpu::Swizzle & writeSwizzle() const
bool isScissorTestEnabled() const
void visitTextureEffects(const std::function< void(const GrTextureEffect &)> &) const
GrTexture * peekDstTexture() const
const GrXferProcessor & getXferProcessor() const
GrSurfaceOrigin origin() const
const GrPipeline & pipeline() const
const SkIRect & rect() const
virtual GrBackendFormat backendFormat() const =0
SkISize dimensions() const
GrTexture * texture() const
bool mustLoadFullImageWithDiscardableMSAA() const
bool preferPrimaryOverSecondaryCommandBuffers() const
uint32_t maxDrawIndirectDrawCount() const
void bindIndexBuffer(GrVkGpu *gpu, sk_sp< const GrBuffer > buffer)
void drawIndexed(const GrVkGpu *gpu, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
void clearAttachments(const GrVkGpu *gpu, int numAttachments, const VkClearAttachment *attachments, int numRects, const VkClearRect *clearRects)
void bindInputBuffer(GrVkGpu *gpu, uint32_t binding, sk_sp< const GrBuffer > buffer)
void drawIndirect(const GrVkGpu *gpu, sk_sp< const GrBuffer > indirectBuffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
void draw(const GrVkGpu *gpu, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
void drawIndexedIndirect(const GrVkGpu *gpu, sk_sp< const GrBuffer > indirectBuffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
std::unique_ptr< GrVkSecondaryCommandBuffer > findOrCreateSecondaryCommandBuffer(GrVkGpu *gpu)
void returnExternalGrSecondaryCommandBuffer(std::unique_ptr< GrVkSecondaryCommandBuffer >)
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const
const GrVkRenderPass * externalRenderPass() const
GrVkImage * resolveAttachment()
GrVkImage * colorAttachment()
std::unique_ptr< GrVkSecondaryCommandBuffer > externalCommandBuffer()
GrVkImage * stencilAttachment()
const GrVkCaps & vkCaps() const
bool loadMSAAFromResolve(GrVkCommandBuffer *commandBuffer, const GrVkRenderPass &renderPass, GrAttachment *dst, GrVkImage *src, const SkIRect &srcRect)
void addDrawable(std::unique_ptr< SkDrawable::GpuDrawHandler > drawable)
bool beginRenderPass(const GrVkRenderPass *, sk_sp< const GrVkFramebuffer >, const VkClearValue *colorClear, const GrSurface *, const SkIRect &renderPassBounds, bool forSecondaryCB)
void endRenderPass(GrRenderTarget *target, GrSurfaceOrigin origin, const SkIRect &bounds)
GrVkResourceProvider & resourceProvider()
GrVkCommandPool * cmdPool() const
bool isDeviceLost() const override
GrVkPrimaryCommandBuffer * currentCommandBuffer() const
bool protectedContext() const
void submitSecondaryCommandBuffer(std::unique_ptr< GrVkSecondaryCommandBuffer >)
void setImageLayout(const GrVkGpu *gpu, VkImageLayout newLayout, VkAccessFlags dstAccessMask, VkPipelineStageFlags dstStageMask, bool byRegion)
VkFormat imageFormat() const
void updateImageLayout(VkImageLayout newLayout)
gr_rp< const GrVkDescriptorSet > inputDescSetForBlending(GrVkGpu *gpu)
const GrVkImageInfo & vkImageInfo() const
bool set(GrRenderTarget *, sk_sp< GrVkFramebuffer >, GrSurfaceOrigin, const SkIRect &bounds, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const GrOpsRenderPass::LoadAndStoreInfo &resolveInfo, GrVkRenderPass::SelfDependencyFlags selfDepFlags, GrVkRenderPass::LoadFromResolve loadFromResolve, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies)
GrVkOpsRenderPass(GrVkGpu *)
void onExecuteDrawable(std::unique_ptr< SkDrawable::GpuDrawHandler >) override
void inlineUpload(GrOpFlushState *state, GrDeferredTextureUploadFn &upload) override
~GrVkOpsRenderPass() override
bool setAndBindTextures(GrVkGpu *, const GrGeometryProcessor &, const GrPipeline &, const GrSurfaceProxy *const geomProcTextures[], GrVkCommandBuffer *)
bool setAndBindUniforms(GrVkGpu *, SkISize colorAttachmentDimensions, const GrProgramInfo &, GrVkCommandBuffer *)
void bindPipeline(const GrVkGpu *gpu, GrVkCommandBuffer *commandBuffer)
bool setAndBindInputAttachment(GrVkGpu *, gr_rp< const GrVkDescriptorSet > inputDescSet, GrVkCommandBuffer *)
static void SetDynamicScissorRectState(GrVkGpu *, GrVkCommandBuffer *, SkISize colorAttachmentDimensions, GrSurfaceOrigin, const SkIRect &scissorRect)
static void SetDynamicBlendConstantState(GrVkGpu *, GrVkCommandBuffer *, const skgpu::Swizzle &writeSwizzle, const GrXferProcessor &)
static void SetDynamicViewportState(GrVkGpu *, GrVkCommandBuffer *, SkISize colorAttachmentDimensions)
void nexSubpass(GrVkGpu *gpu, bool forSecondaryCB)
bool colorAttachmentIndex(uint32_t *index) const
const VkExtent2D & granularity() const
LoadFromResolve loadFromResolve() const
bool stencilAttachmentIndex(uint32_t *index) const
bool hasStencilAttachment() const
VkRenderPass vkRenderPass() const
bool hasResolveAttachment() const
const GrVkFramebuffer * getFramebuffer(bool withResolve, bool withStencil, SelfDependencyFlags selfDepFlags, LoadFromResolve)
GrVkPipelineState * findOrCreateCompatiblePipelineState(GrRenderTarget *, const GrProgramInfo &, VkRenderPass compatibleRenderPass, bool overrideSubpassForResolveLoad)
const GrVkRenderPass * findRenderPass(GrVkRenderTarget *target, const GrVkRenderPass::LoadStoreOps &colorOps, const GrVkRenderPass::LoadStoreOps &resolveOps, const GrVkRenderPass::LoadStoreOps &stencilOps, CompatibleRPHandle *compatibleHandle, bool withResolve, bool withStencil, SelfDependencyFlags selfDepFlags, LoadFromResolve)
GrVkImage * textureImage() const
void reset(T *ptr=nullptr)
static float min(float r, float g, float b)
Optional< SkRect > bounds
static SkIRect MakeIRectRelativeTo(GrSurfaceOrigin origin, int rtHeight, SkIRect devRect)
std::array< float, 4 > fClearColor
uint32_t fColorAttachmentIndex
VkRenderPass fCompatibleRenderPass
VkCommandBuffer fSecondaryCommandBuffer
bool intersect(const SkIRect &r)
int32_t fBottom
larger y-axis bounds
constexpr int32_t height() const
int32_t fTop
smaller y-axis bounds
static constexpr SkIRect MakeSize(const SkISize &size)
static constexpr SkIRect MakeEmpty()
constexpr int32_t width() const
void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
int32_t fLeft
smaller x-axis bounds
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
bool contains(int32_t x, int32_t y) const
int32_t fRight
larger x-axis bounds
void setSize(SkISize size)
static SkRect Make(const SkISize &size)
bool intersect(const SkRect &r)
void roundOut(SkIRect *dst) const
VkImageAspectFlags aspectMask
VkClearDepthStencilValue depthStencil
VkFlags VkPipelineStageFlags
@ VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
@ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
@ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
@ VK_IMAGE_LAYOUT_GENERAL
@ VK_IMAGE_ASPECT_COLOR_BIT
@ VK_IMAGE_ASPECT_STENCIL_BIT
@ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
@ VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
@ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
@ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
@ VK_ACCESS_SHADER_READ_BIT
@ VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
@ VK_ATTACHMENT_LOAD_OP_CLEAR
@ VK_ATTACHMENT_LOAD_OP_LOAD
@ VK_ATTACHMENT_LOAD_OP_DONT_CARE
@ VK_ATTACHMENT_STORE_OP_DONT_CARE
@ VK_ATTACHMENT_STORE_OP_STORE
@ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
@ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
@ VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT