[graphite] Connect DrawPass and CommandBuffer levels together for Textures and Samplers

Bug: skia:12701
Change-Id: Ide780f9dac1b92855e634726d261630ef5d017fc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/523426
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-03-23 15:05:58 -04:00 committed by SkCQ
parent 8bb0f47c61
commit d67d52ec0f
3 changed files with 45 additions and 12 deletions

View File

@ -23,6 +23,8 @@
#include "experimental/graphite/src/RecorderPriv.h"
#include "experimental/graphite/src/Renderer.h"
#include "experimental/graphite/src/ResourceProvider.h"
#include "experimental/graphite/src/Sampler.h"
#include "experimental/graphite/src/Texture.h"
#include "experimental/graphite/src/TextureProxy.h"
#include "experimental/graphite/src/UniformManager.h"
#include "experimental/graphite/src/geom/BoundsManager.h"
@ -442,7 +444,8 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
lastShadingUniforms = key.shadingUniforms();
}
if (textureBindingsChange) {
// TODO: add BindTexturesAndSamplers command here
auto textureDataBlock = textureDataCache->lookup(key.textureBindings());
drawPass->fCommands.emplace_back(BindTexturesAndSamplers{textureDataBlock});
lastTextureBindings = key.textureBindings();
}
if (draw.fGeometry.clip().scissor() != lastScissor) {
@ -487,11 +490,28 @@ void DrawPass::addCommands(ResourceProvider* resourceProvider,
case CommandType::kBindGraphicsPipeline: {
auto& d = c.fBindGraphicsPipeline;
buffer->bindGraphicsPipeline(fullPipelines[d.fPipelineIndex]);
break; }
} break;
case CommandType::kBindUniformBuffer: {
auto& d = c.fBindUniformBuffer;
buffer->bindUniformBuffer(d.fSlot, sk_ref_sp(d.fInfo.fBuffer), d.fInfo.fOffset);
break; }
} break;
case CommandType::kBindTexturesAndSamplers: {
auto& d = c.fBindTexturesAndSamplers;
for (int i = 0; i < d.fTextureBlock->numTextures(); ++i) {
const auto &texture = d.fTextureBlock->texture(i);
sk_sp<Sampler> sampler = resourceProvider->findOrCreateCompatibleSampler(
texture.fSamplingOptions, texture.fTileModes[0], texture.fTileModes[1]);
SkASSERT(texture.fProxy->texture());
SkASSERT(sampler);
buffer->bindTextureAndSampler(texture.fProxy->refTexture(),
std::move(sampler),
i);
}
} break;
case CommandType::kBindDrawBuffers: {
auto& d = c.fBindDrawBuffers;
buffer->bindDrawBuffers(d.fVertices, d.fInstances, d.fIndices);

View File

@ -18,6 +18,8 @@
#include <memory>
class SkTextureDataBlock;
namespace skgpu {
class BoundsManager;
@ -92,6 +94,11 @@ private:
BindBufferInfo fInfo;
UniformSlot fSlot;
};
struct BindTexturesAndSamplers {
// The data backing this pointer is stored in the TextureDataCache. Its lifetime is for
// a single Recording (thus guaranteed to be longer than this DrawPass' lifetime).
SkTextureDataBlock* fTextureBlock;
};
struct BindDrawBuffers {
BindBufferInfo fVertices;
BindBufferInfo fInstances;
@ -132,6 +139,7 @@ private:
enum class CommandType {
kBindGraphicsPipeline,
kBindUniformBuffer,
kBindTexturesAndSamplers,
kBindDrawBuffers,
kDraw,
kDrawIndexed,
@ -147,20 +155,23 @@ private:
struct Command {
CommandType fType;
union {
BindGraphicsPipeline fBindGraphicsPipeline;
BindUniformBuffer fBindUniformBuffer;
BindDrawBuffers fBindDrawBuffers;
Draw fDraw;
DrawIndexed fDrawIndexed;
DrawInstanced fDrawInstanced;
DrawIndexedInstanced fDrawIndexedInstanced;
SetScissor fSetScissor;
BindGraphicsPipeline fBindGraphicsPipeline;
BindUniformBuffer fBindUniformBuffer;
BindTexturesAndSamplers fBindTexturesAndSamplers;
BindDrawBuffers fBindDrawBuffers;
Draw fDraw;
DrawIndexed fDrawIndexed;
DrawInstanced fDrawInstanced;
DrawIndexedInstanced fDrawIndexedInstanced;
SetScissor fSetScissor;
};
explicit Command(BindGraphicsPipeline d)
: fType(CommandType::kBindGraphicsPipeline), fBindGraphicsPipeline(d) {}
explicit Command(BindUniformBuffer d)
: fType(CommandType::kBindUniformBuffer), fBindUniformBuffer(d) {}
explicit Command(BindTexturesAndSamplers d)
: fType(CommandType::kBindTexturesAndSamplers), fBindTexturesAndSamplers(d) {}
explicit Command(BindDrawBuffers d)
: fType(CommandType::kBindDrawBuffers), fBindDrawBuffers(d) {}
explicit Command(Draw d)

View File

@ -16,6 +16,7 @@
#include "src/shaders/SkShaderBase.h"
#ifdef SK_GRAPHITE_ENABLED
#include "experimental/graphite/src/Texture.h"
#include "experimental/graphite/src/TextureProxy.h"
#include "experimental/graphite/src/UniformManager.h"
#include "src/gpu/Blend.h"
@ -386,7 +387,8 @@ void AddToKey(const SkKeyContext& keyContext,
#ifdef SK_GRAPHITE_ENABLED
if (builder->backend() == SkBackend::kGraphite) {
if (pipelineData && !imgData.fTextureProxy) {
// TODO: allow through lazy proxies
if (pipelineData && (!imgData.fTextureProxy || !imgData.fTextureProxy->refTexture())) {
// We're dropping the ImageShader here. This could be an instance of trying to draw
// a raster-backed image w/ a Graphite-backed canvas.
// TODO: At some point the pre-compile path should also be creating a texture