Plumb GrTextureProxies down into emitSampler/addSampler
This is still pretty far away from this goal but, the goal here is to be able to create a program w/o requiring instantiated proxies.
Bug: skia:9455
Change-Id: I9526a3a737438c5331fef4a621be4786ef43c080
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247397
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrProgramInfo.h b/src/gpu/GrProgramInfo.h
index 671147a..a4c46e6 100644
--- a/src/gpu/GrProgramInfo.h
+++ b/src/gpu/GrProgramInfo.h
@@ -48,19 +48,6 @@
const GrPrimitiveProcessor& primProc() const { return fPrimProc; }
const GrPipeline::FixedDynamicState* fixedDynamicState() const { return fFixedDynamicState; }
- // TODO: can this be removed?
- const GrTextureProxy* const* primProcProxies() const {
- const GrTextureProxy* const* primProcProxies = nullptr;
- if (fDynamicStateArrays && fDynamicStateArrays->fPrimitiveProcessorTextures) {
- primProcProxies = fDynamicStateArrays->fPrimitiveProcessorTextures;
- } else if (fFixedDynamicState) {
- primProcProxies = fFixedDynamicState->fPrimitiveProcessorTextures;
- }
-
- SkASSERT(SkToBool(primProcProxies) == SkToBool(fPrimProc.numTextureSamplers()));
- return primProcProxies;
- }
-
bool hasDynamicScissors() const {
return fPipeline.isScissorEnabled() &&
fDynamicStateArrays && fDynamicStateArrays->fScissorRects;
diff --git a/src/gpu/dawn/GrDawnUniformHandler.cpp b/src/gpu/dawn/GrDawnUniformHandler.cpp
index 4226326..74fd1e3 100644
--- a/src/gpu/dawn/GrDawnUniformHandler.cpp
+++ b/src/gpu/dawn/GrDawnUniformHandler.cpp
@@ -237,7 +237,7 @@
fUniforms[u.toIndex()].fVisibility |= visibility;
}
-GrGLSLUniformHandler::SamplerHandle GrDawnUniformHandler::addSampler(const GrTexture* texture,
+GrGLSLUniformHandler::SamplerHandle GrDawnUniformHandler::addSampler(const GrTextureProxy*,
const GrSamplerState&,
const GrSwizzle& swizzle,
const char* name,
diff --git a/src/gpu/dawn/GrDawnUniformHandler.h b/src/gpu/dawn/GrDawnUniformHandler.h
index 223fb15..e5d9950 100644
--- a/src/gpu/dawn/GrDawnUniformHandler.h
+++ b/src/gpu/dawn/GrDawnUniformHandler.h
@@ -35,7 +35,7 @@
private:
explicit GrDawnUniformHandler(GrGLSLProgramBuilder* program);
- SamplerHandle addSampler(const GrTexture*, const GrSamplerState&, const GrSwizzle&,
+ SamplerHandle addSampler(const GrTextureProxy*, const GrSamplerState&, const GrSwizzle&,
const char* name, const GrShaderCaps*) override;
const char* samplerVariable(SamplerHandle handle) const override;
GrSwizzle samplerSwizzle(SamplerHandle handle) const override;
diff --git a/src/gpu/gl/GrGLUniformHandler.cpp b/src/gpu/gl/GrGLUniformHandler.cpp
index 551851c..56ed244 100644
--- a/src/gpu/gl/GrGLUniformHandler.cpp
+++ b/src/gpu/gl/GrGLUniformHandler.cpp
@@ -59,7 +59,7 @@
return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
}
-GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::addSampler(const GrTexture* texture,
+GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::addSampler(const GrTextureProxy* texture,
const GrSamplerState&,
const GrSwizzle& swizzle,
const char* name,
@@ -70,7 +70,7 @@
char prefix = 'u';
fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
- GrTextureType type = texture->texturePriv().textureType();
+ GrTextureType type = texture->textureType();
UniformInfo& sampler = fSamplers.push_back();
sampler.fVariable.setType(GrSLCombinedSamplerTypeForTextureType(type));
diff --git a/src/gpu/gl/GrGLUniformHandler.h b/src/gpu/gl/GrGLUniformHandler.h
index 817be54..f577755 100644
--- a/src/gpu/gl/GrGLUniformHandler.h
+++ b/src/gpu/gl/GrGLUniformHandler.h
@@ -42,7 +42,7 @@
fUniforms[u.toIndex()].fVisibility |= visibility;
}
- SamplerHandle addSampler(const GrTexture*, const GrSamplerState&, const GrSwizzle&,
+ SamplerHandle addSampler(const GrTextureProxy*, const GrSamplerState&, const GrSwizzle&,
const char* name, const GrShaderCaps*) override;
const char* samplerVariable(SamplerHandle handle) const override {
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 9621e14..e6125e3 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -64,7 +64,16 @@
void GrGLSLProgramBuilder::emitAndInstallPrimProc(SkString* outputColor,
SkString* outputCoverage) {
const GrPrimitiveProcessor& proc = this->primitiveProcessor();
- const GrTextureProxy* const* primProcProxies = this->primProcProxies();
+
+ // Because all the texture properties must be consistent between all the dynamic and fixed
+ // primProc proxies, we just deal w/ the first set of dynamic proxies or the set of fixed
+ // proxies here.
+ const GrTextureProxy* const* primProcProxies = nullptr;
+ if (fProgramInfo.hasDynamicPrimProcTextures()) {
+ primProcProxies = fProgramInfo.dynamicPrimProcTextures(0);
+ } else if (fProgramInfo.hasFixedPrimProcTextures()) {
+ primProcProxies = fProgramInfo.fixedPrimProcTextures();
+ }
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
@@ -99,9 +108,8 @@
SkString name;
name.printf("TextureSampler_%d", i);
const auto& sampler = proc.textureSampler(i);
- const GrTexture* texture = primProcProxies[i]->peekTexture();
- SkASSERT(sampler.textureType() == texture->texturePriv().textureType());
- texSamplers[i] = this->emitSampler(texture,
+ SkASSERT(sampler.textureType() == primProcProxies[i]->textureType());
+ texSamplers[i] = this->emitSampler(primProcProxies[i],
sampler.samplerState(),
sampler.swizzle(),
name.c_str());
@@ -184,7 +192,7 @@
SkString name;
name.printf("TextureSampler_%d", samplerIdx++);
const auto& sampler = subFP->textureSampler(i);
- texSamplers.emplace_back(this->emitSampler(sampler.peekTexture(),
+ texSamplers.emplace_back(this->emitSampler(sampler.proxy(),
sampler.samplerState(),
sampler.swizzle(),
name.c_str()));
@@ -240,14 +248,13 @@
SamplerHandle dstTextureSamplerHandle;
GrSurfaceOrigin dstTextureOrigin = kTopLeft_GrSurfaceOrigin;
- if (GrTexture* dstTexture = this->pipeline().peekDstTexture()) {
+ if (GrTextureProxy* dstTextureProxy = this->pipeline().dstTextureProxy()) {
// GrProcessor::TextureSampler sampler(dstTexture);
- SkASSERT(this->pipeline().dstTextureProxy());
- const GrSwizzle& swizzle = this->pipeline().dstTextureProxy()->textureSwizzle();
- dstTextureSamplerHandle =
- this->emitSampler(dstTexture, GrSamplerState(), swizzle, "DstTextureSampler");
- dstTextureOrigin = this->pipeline().dstTextureProxy()->origin();
- SkASSERT(dstTexture->texturePriv().textureType() != GrTextureType::kExternal);
+ const GrSwizzle& swizzle = dstTextureProxy->textureSwizzle();
+ dstTextureSamplerHandle = this->emitSampler(dstTextureProxy, GrSamplerState(),
+ swizzle, "DstTextureSampler");
+ dstTextureOrigin = dstTextureProxy->origin();
+ SkASSERT(dstTextureProxy->textureType() != GrTextureType::kExternal);
}
SkString finalInColor = colorIn.size() ? colorIn : SkString("float4(1)");
@@ -271,7 +278,7 @@
fFS.codeAppend("}");
}
-GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(const GrTexture* texture,
+GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(const GrTextureProxy* texture,
const GrSamplerState& state,
const GrSwizzle& swizzle,
const char* name) {
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index a710f0a..d470b69 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -41,7 +41,6 @@
GrSurfaceOrigin origin() const { return fProgramInfo.origin(); }
const GrPipeline& pipeline() const { return fProgramInfo.pipeline(); }
const GrPrimitiveProcessor& primitiveProcessor() const { return fProgramInfo.primProc(); }
- const GrTextureProxy* const* primProcProxies() const { return fProgramInfo.primProcProxies(); }
GrProcessor::CustomFeatures processorFeatures() const {
return fProgramInfo.requestedFeatures();
}
@@ -160,7 +159,7 @@
SkString output,
SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>*);
void emitAndInstallXferProc(const SkString& colorIn, const SkString& coverageIn);
- SamplerHandle emitSampler(const GrTexture*, const GrSamplerState&, const GrSwizzle&,
+ SamplerHandle emitSampler(const GrTextureProxy*, const GrSamplerState&, const GrSwizzle&,
const char* name);
bool checkSamplerCounts();
diff --git a/src/gpu/glsl/GrGLSLUniformHandler.h b/src/gpu/glsl/GrGLSLUniformHandler.h
index c3232cd..f27d961 100644
--- a/src/gpu/glsl/GrGLSLUniformHandler.h
+++ b/src/gpu/glsl/GrGLSLUniformHandler.h
@@ -17,7 +17,7 @@
class GrGLSLProgramBuilder;
class GrSamplerState;
-class GrTexture;
+class GrTextureProxy;
// Handles for program uniforms (other than per-effect uniforms)
struct GrGLSLBuiltinUniformHandles {
@@ -84,7 +84,7 @@
// Only called if GrShaderCaps(:textureSwizzleAppliedInShader() == true.
virtual GrSwizzle samplerSwizzle(SamplerHandle) const = 0;
- virtual SamplerHandle addSampler(const GrTexture*, const GrSamplerState&, const GrSwizzle&,
+ virtual SamplerHandle addSampler(const GrTextureProxy*, const GrSamplerState&, const GrSwizzle&,
const char* name, const GrShaderCaps*) = 0;
virtual UniformHandle internalAddUniformArray(uint32_t visibility,
diff --git a/src/gpu/mtl/GrMtlPipelineState.mm b/src/gpu/mtl/GrMtlPipelineState.mm
index e08ada7..c8c6955 100644
--- a/src/gpu/mtl/GrMtlPipelineState.mm
+++ b/src/gpu/mtl/GrMtlPipelineState.mm
@@ -61,7 +61,9 @@
const GrProgramInfo& programInfo) {
// Note: the Metal backend currently only supports fixed primProc textures
- const GrTextureProxy* const* primProcProxies = programInfo.primProcProxies();
+ SkASSERT(!programInfo.hasDynamicPrimProcTextures());
+ auto proxies = programInfo.hasFixedPrimProcTextures() ? programInfo.fixedPrimProcTextures()
+ : nullptr;
this->setRenderTargetState(renderTarget, programInfo.origin());
fGeometryProcessor->setData(fDataManager, programInfo.primProc(),
@@ -69,7 +71,7 @@
fSamplerBindings.reset();
for (int i = 0; i < programInfo.primProc().numTextureSamplers(); ++i) {
const auto& sampler = programInfo.primProc().textureSampler(i);
- auto texture = static_cast<GrMtlTexture*>(primProcProxies[i]->peekTexture());
+ auto texture = static_cast<GrMtlTexture*>(proxies[i]->peekTexture());
fSamplerBindings.emplace_back(sampler.samplerState(), texture, fGpu);
}
diff --git a/src/gpu/mtl/GrMtlUniformHandler.h b/src/gpu/mtl/GrMtlUniformHandler.h
index 9c789ff..bcf15a0 100644
--- a/src/gpu/mtl/GrMtlUniformHandler.h
+++ b/src/gpu/mtl/GrMtlUniformHandler.h
@@ -61,7 +61,7 @@
fUniforms[u.toIndex()].fVisibility |= visibility;
}
- SamplerHandle addSampler(const GrTexture*,
+ SamplerHandle addSampler(const GrTextureProxy*,
const GrSamplerState&,
const GrSwizzle&,
const char* name,
diff --git a/src/gpu/mtl/GrMtlUniformHandler.mm b/src/gpu/mtl/GrMtlUniformHandler.mm
index c123c57..89e1263 100644
--- a/src/gpu/mtl/GrMtlUniformHandler.mm
+++ b/src/gpu/mtl/GrMtlUniformHandler.mm
@@ -242,7 +242,7 @@
return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
}
-GrGLSLUniformHandler::SamplerHandle GrMtlUniformHandler::addSampler(const GrTexture* texture,
+GrGLSLUniformHandler::SamplerHandle GrMtlUniformHandler::addSampler(const GrTextureProxy* texture,
const GrSamplerState&,
const GrSwizzle& swizzle,
const char* name,
@@ -252,7 +252,7 @@
char prefix = 'u';
fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
- GrTextureType type = texture->texturePriv().textureType();
+ GrTextureType type = texture->textureType();
UniformInfo& info = fSamplers.push_back();
info.fVariable.setType(GrSLCombinedSamplerTypeForTextureType(type));
diff --git a/src/gpu/vk/GrVkUniformHandler.cpp b/src/gpu/vk/GrVkUniformHandler.cpp
index cb41ae2..6df62ce 100644
--- a/src/gpu/vk/GrVkUniformHandler.cpp
+++ b/src/gpu/vk/GrVkUniformHandler.cpp
@@ -254,7 +254,7 @@
return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
}
-GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(const GrTexture* texture,
+GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(const GrTextureProxy* texture,
const GrSamplerState& state,
const GrSwizzle& swizzle,
const char* name,
@@ -264,7 +264,7 @@
char prefix = 'u';
fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
- GrTextureType type = texture->texturePriv().textureType();
+ GrTextureType type = texture->textureType();
UniformInfo& info = fSamplers.push_back();
info.fVariable.setType(GrSLCombinedSamplerTypeForTextureType(type));
@@ -277,11 +277,11 @@
info.fUBOffset = 0;
// Check if we are dealing with an external texture and store the needed information if so.
- const GrVkTexture* vkTexture = static_cast<const GrVkTexture*>(texture);
- if (vkTexture->ycbcrConversionInfo().isValid()) {
+ auto ycbcrInfo = texture->backendFormat().getVkYcbcrConversionInfo();
+ if (ycbcrInfo && ycbcrInfo->isValid()) {
GrVkGpu* gpu = static_cast<GrVkPipelineStateBuilder*>(fProgramBuilder)->gpu();
info.fImmutableSampler = gpu->resourceProvider().findOrCreateCompatibleSampler(
- state, vkTexture->ycbcrConversionInfo());
+ state, *ycbcrInfo);
SkASSERT(info.fImmutableSampler);
}
diff --git a/src/gpu/vk/GrVkUniformHandler.h b/src/gpu/vk/GrVkUniformHandler.h
index de6a3e4..76f82f0 100644
--- a/src/gpu/vk/GrVkUniformHandler.h
+++ b/src/gpu/vk/GrVkUniformHandler.h
@@ -77,7 +77,7 @@
fUniforms[u.toIndex()].fVisibility |= visibility;
}
- SamplerHandle addSampler(const GrTexture* texture,
+ SamplerHandle addSampler(const GrTextureProxy*,
const GrSamplerState&,
const GrSwizzle&,
const char* name,