aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-05-05 10:28:42 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-05 15:04:13 +0000
commitbc5d4d769098a4fb46685c0e59034dc8e12318a2 (patch)
tree1a3ff07875fb27d058f3d2369b30b9b62f7d6324
parent288d041c64322fafc77cfaf23907180ebad933a1 (diff)
Split tracking of TexelBuffers from normal samplers
This is precursor CL to add support for texel buffers in Vulkan. This change as includes fixes to the ordering of assigning locations and texture units so that they match in GrGLProgramDataManager and GrGLProgram. Bug: skia: Change-Id: I30c9578fb7dcb187256f744e07651e8564f93a6b Reviewed-on: https://skia-review.googlesource.com/15225 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
-rw-r--r--src/gpu/gl/GrGLProgram.cpp46
-rw-r--r--src/gpu/gl/GrGLProgram.h13
-rw-r--r--src/gpu/gl/GrGLProgramDataManager.cpp5
-rw-r--r--src/gpu/gl/GrGLProgramDataManager.h5
-rw-r--r--src/gpu/gl/GrGLUniformHandler.cpp39
-rw-r--r--src/gpu/gl/GrGLUniformHandler.h17
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp1
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.cpp4
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.h9
-rw-r--r--src/gpu/glsl/GrGLSLPrimitiveProcessor.h7
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.cpp42
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.h11
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp14
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.h5
-rw-r--r--src/gpu/glsl/GrGLSLUniformHandler.h5
-rw-r--r--src/gpu/instanced/InstanceProcessor.cpp6
-rw-r--r--src/gpu/vk/GrVkUniformHandler.h9
17 files changed, 173 insertions, 65 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index e208e7447e..ec08bf4634 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -30,7 +30,8 @@ GrGLProgram::GrGLProgram(GrGLGpu* gpu,
const BuiltinUniformHandles& builtinUniforms,
GrGLuint programID,
const UniformInfoArray& uniforms,
- const UniformInfoArray& samplers,
+ const UniformInfoArray& textureSamplers,
+ const UniformInfoArray& texelBuffers,
const UniformInfoArray& imageStorages,
const VaryingInfoArray& pathProcVaryings,
GrGLSLPrimitiveProcessor* geometryProcessor,
@@ -43,10 +44,13 @@ GrGLProgram::GrGLProgram(GrGLGpu* gpu,
, fFragmentProcessors(fragmentProcessors)
, fDesc(desc)
, fGpu(gpu)
- , fProgramDataManager(gpu, programID, uniforms, pathProcVaryings) {
+ , fProgramDataManager(gpu, programID, uniforms, pathProcVaryings)
+ , fNumTextureSamplers(textureSamplers.count())
+ , fNumTexelBuffers(texelBuffers.count()) {
// Assign texture units to sampler uniforms one time up front.
GL_CALL(UseProgram(fProgramID));
- fProgramDataManager.setSamplers(samplers);
+ fProgramDataManager.setSamplerUniforms(textureSamplers, 0);
+ fProgramDataManager.setSamplerUniforms(texelBuffers, fNumTextureSamplers);
fProgramDataManager.setImageStorages(imageStorages);
}
@@ -70,21 +74,32 @@ void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline
// we set the textures, and uniforms for installed processors in a generic way, but subclasses
// of GLProgram determine how to set coord transforms
- int nextSamplerIdx = 0;
+
+ // We must bind to texture units in the same order in which we set the uniforms in
+ // GrGLProgramDataManager. That is first all texture samplers and then texel buffers.
+ // ImageStorages are bound to their own image units so they are tracked separately.
+ // Within each group we will bind them in primProc, fragProcs, XP order.
+ int nextTexSamplerIdx = 0;
+ int nextTexelBufferIdx = fNumTextureSamplers;
+ int nextImageStorageIdx = 0;
fGeometryProcessor->setData(fProgramDataManager, primProc,
GrFragmentProcessor::CoordTransformIter(pipeline));
- this->bindTextures(primProc, pipeline.getAllowSRGBInputs(), &nextSamplerIdx);
+ this->bindTextures(primProc, pipeline.getAllowSRGBInputs(), &nextTexSamplerIdx,
+ &nextTexelBufferIdx, &nextImageStorageIdx);
- this->setFragmentData(primProc, pipeline, &nextSamplerIdx);
+ this->setFragmentData(primProc, pipeline, &nextTexSamplerIdx, &nextTexelBufferIdx,
+ &nextImageStorageIdx);
const GrXferProcessor& xp = pipeline.getXferProcessor();
SkIPoint offset;
GrTexture* dstTexture = pipeline.dstTexture(&offset);
fXferProcessor->setData(fProgramDataManager, xp, dstTexture, offset);
if (dstTexture) {
- fGpu->bindTexture(nextSamplerIdx++, GrSamplerParams::ClampNoFilter(), true,
+ fGpu->bindTexture(nextTexSamplerIdx++, GrSamplerParams::ClampNoFilter(), true,
static_cast<GrGLTexture*>(dstTexture));
}
+ SkASSERT(nextTexSamplerIdx == fNumTextureSamplers);
+ SkASSERT(nextTexelBufferIdx == fNumTextureSamplers + fNumTexelBuffers);
}
void GrGLProgram::generateMipmaps(const GrPrimitiveProcessor& primProc,
@@ -99,7 +114,9 @@ void GrGLProgram::generateMipmaps(const GrPrimitiveProcessor& primProc,
void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc,
const GrPipeline& pipeline,
- int* nextSamplerIdx) {
+ int* nextTexSamplerIdx,
+ int* nextTexelBufferIdx,
+ int* nextImageStorageIdx) {
GrFragmentProcessor::Iter iter(pipeline);
GrGLSLFragmentProcessor::Iter glslIter(fFragmentProcessors.begin(),
fFragmentProcessors.count());
@@ -107,7 +124,8 @@ void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc,
GrGLSLFragmentProcessor* glslFP = glslIter.next();
while (fp && glslFP) {
glslFP->setData(fProgramDataManager, *fp);
- this->bindTextures(*fp, pipeline.getAllowSRGBInputs(), nextSamplerIdx);
+ this->bindTextures(*fp, pipeline.getAllowSRGBInputs(), nextTexSamplerIdx,
+ nextTexelBufferIdx, nextImageStorageIdx);
fp = iter.next();
glslFP = glslIter.next();
}
@@ -146,20 +164,22 @@ void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc,
void GrGLProgram::bindTextures(const GrResourceIOProcessor& processor,
bool allowSRGBInputs,
- int* nextSamplerIdx) {
+ int* nextTexSamplerIdx,
+ int* nextTexelBufferIdx,
+ int* nextImageStorageIdx) {
for (int i = 0; i < processor.numTextureSamplers(); ++i) {
const GrResourceIOProcessor::TextureSampler& sampler = processor.textureSampler(i);
- fGpu->bindTexture((*nextSamplerIdx)++, sampler.params(),
+ fGpu->bindTexture((*nextTexSamplerIdx)++, sampler.params(),
allowSRGBInputs, static_cast<GrGLTexture*>(sampler.texture()));
}
for (int i = 0; i < processor.numBuffers(); ++i) {
const GrResourceIOProcessor::BufferAccess& access = processor.bufferAccess(i);
- fGpu->bindTexelBuffer((*nextSamplerIdx)++, access.texelConfig(),
+ fGpu->bindTexelBuffer((*nextTexelBufferIdx)++, access.texelConfig(),
static_cast<GrGLBuffer*>(access.buffer()));
}
for (int i = 0; i < processor.numImageStorages(); ++i) {
const GrResourceIOProcessor::ImageStorageAccess& access = processor.imageStorageAccess(i);
- fGpu->bindImageStorage((*nextSamplerIdx)++, access.ioType(),
+ fGpu->bindImageStorage((*nextImageStorageIdx)++, access.ioType(),
static_cast<GrGLTexture *>(access.texture()));
}
}
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index f9b84d8031..d6bde9a094 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -111,7 +111,8 @@ protected:
const BuiltinUniformHandles&,
GrGLuint programID,
const UniformInfoArray& uniforms,
- const UniformInfoArray& samplers,
+ const UniformInfoArray& textureSamplers,
+ const UniformInfoArray& texelBuffers,
const UniformInfoArray& imageStorages,
const VaryingInfoArray&, // used for NVPR only currently
GrGLSLPrimitiveProcessor* geometryProcessor,
@@ -119,13 +120,15 @@ protected:
const GrGLSLFragProcs& fragmentProcessors);
// A helper to loop over effects, set the transforms (via subclass) and bind textures
- void setFragmentData(const GrPrimitiveProcessor&, const GrPipeline&, int* nextSamplerIdx);
+ void setFragmentData(const GrPrimitiveProcessor&, const GrPipeline&, int* nextTexSamplerIdx,
+ int* nextTexelBufferIdx, int* nextImageStorageIdx);
// Helper for setData() that sets the view matrix and loads the render target height uniform
void setRenderTargetState(const GrPrimitiveProcessor&, const GrRenderTarget*);
// Helper for setData() that binds textures and texel buffers to the appropriate texture units
- void bindTextures(const GrResourceIOProcessor&, bool allowSRGBInputs, int* nextSamplerIdx);
+ void bindTextures(const GrResourceIOProcessor&, bool allowSRGBInputs, int* nextSamplerIdx,
+ int* nextTexelBufferIdx, int* nextImageStorageIdx);
// Helper for generateMipmaps() that ensures mipmaps are up to date
void generateMipmaps(const GrResourceIOProcessor&, bool allowSRGBInputs);
@@ -144,6 +147,10 @@ protected:
GrGLGpu* fGpu;
GrGLProgramDataManager fProgramDataManager;
+ int fNumTextureSamplers;
+ int fNumTexelBuffers;
+ int fNumImageStorages;
+
friend class GrGLProgramBuilder;
typedef SkRefCnt INHERITED;
diff --git a/src/gpu/gl/GrGLProgramDataManager.cpp b/src/gpu/gl/GrGLProgramDataManager.cpp
index 2a3422e308..3414abac44 100644
--- a/src/gpu/gl/GrGLProgramDataManager.cpp
+++ b/src/gpu/gl/GrGLProgramDataManager.cpp
@@ -50,12 +50,13 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID,
}
}
-void GrGLProgramDataManager::setSamplers(const UniformInfoArray& samplers) const {
+void GrGLProgramDataManager::setSamplerUniforms(const UniformInfoArray& samplers,
+ int startUnit) const {
for (int i = 0; i < samplers.count(); ++i) {
const UniformInfo& sampler = samplers[i];
SkASSERT(sampler.fVisibility);
if (kUnusedUniform != sampler.fLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform1i(sampler.fLocation, i));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1i(sampler.fLocation, i + startUnit));
}
}
}
diff --git a/src/gpu/gl/GrGLProgramDataManager.h b/src/gpu/gl/GrGLProgramDataManager.h
index 42e0656915..6b4e4d99bb 100644
--- a/src/gpu/gl/GrGLProgramDataManager.h
+++ b/src/gpu/gl/GrGLProgramDataManager.h
@@ -45,9 +45,8 @@ public:
GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
const VaryingInfoArray&);
-
- void setSamplers(const UniformInfoArray& samplers) const;
- void setImageStorages(const UniformInfoArray &images) const;
+ void setSamplerUniforms(const UniformInfoArray& samplers, int startUnit) const;
+ void setImageStorages(const UniformInfoArray& images) const;
/** Functions for uploading uniform values. The varities ending in v can be used to upload to an
* array of uniforms. arrayCount must be <= the array count of the uniform.
diff --git a/src/gpu/gl/GrGLUniformHandler.cpp b/src/gpu/gl/GrGLUniformHandler.cpp
index b00779bf5d..4d718a0e4a 100644
--- a/src/gpu/gl/GrGLUniformHandler.cpp
+++ b/src/gpu/gl/GrGLUniformHandler.cpp
@@ -76,6 +76,26 @@ GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::addSampler(uint32_t visi
return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
}
+GrGLSLUniformHandler::TexelBufferHandle GrGLUniformHandler::addTexelBuffer(uint32_t visibility,
+ GrSLPrecision precision,
+ const char* name) {
+ SkASSERT(name && strlen(name));
+ SkASSERT(0 != visibility);
+
+ SkString mangleName;
+ char prefix = 'u';
+ fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
+
+ UniformInfo& texelBuffer = fTexelBuffers.push_back();
+ texelBuffer.fVariable.setType(kBufferSampler_GrSLType);
+ texelBuffer.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
+ texelBuffer.fVariable.setPrecision(precision);
+ texelBuffer.fVariable.setName(mangleName);
+ texelBuffer.fLocation = -1;
+ texelBuffer.fVisibility = visibility;
+ return GrGLSLUniformHandler::TexelBufferHandle(fTexelBuffers.count() - 1);
+}
+
GrGLSLUniformHandler::ImageStorageHandle GrGLUniformHandler::addImageStorage(
uint32_t visibility, GrSLType type, GrImageStorageFormat format, GrSLMemoryModel model,
GrSLRestrict restrict, GrIOType ioType, const char* name) {
@@ -114,6 +134,12 @@ void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out->append(";\n");
}
}
+ for (int i = 0; i < fTexelBuffers.count(); ++i) {
+ if (fTexelBuffers[i].fVisibility & visibility) {
+ fTexelBuffers[i].fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
+ out->append(";\n");
+ }
+ }
for (int i = 0; i < fImageStorages.count(); ++i) {
if (fImageStorages[i].fVisibility & visibility) {
fImageStorages[i].fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
@@ -133,7 +159,12 @@ void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps
GL_CALL(BindUniformLocation(programID, currUniform, fSamplers[i].fVariable.c_str()));
fSamplers[i].fLocation = currUniform;
}
- for (int i = 0; i < fImageStorages.count(); ++i) {
+ for (int i = 0; i < fTexelBuffers.count(); ++i, ++currUniform) {
+ GL_CALL(BindUniformLocation(programID, currUniform,
+ fTexelBuffers[i].fVariable.c_str()));
+ fTexelBuffers[i].fLocation = currUniform;
+ }
+ for (int i = 0; i < fImageStorages.count(); ++i, ++currUniform) {
GL_CALL(BindUniformLocation(programID, currUniform,
fImageStorages[i].fVariable.c_str()));
fImageStorages[i].fLocation = currUniform;
@@ -154,6 +185,12 @@ void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps&
GL_CALL_RET(location, GetUniformLocation(programID, fSamplers[i].fVariable.c_str()));
fSamplers[i].fLocation = location;
}
+ for (int i = 0; i < fTexelBuffers.count(); ++i) {
+ GrGLint location;
+ GL_CALL_RET(location, GetUniformLocation(programID,
+ fTexelBuffers[i].fVariable.c_str()));
+ fTexelBuffers[i].fLocation = location;
+ }
for (int i = 0; i < fImageStorages.count(); ++i) {
GrGLint location;
GL_CALL_RET(location, GetUniformLocation(programID,
diff --git a/src/gpu/gl/GrGLUniformHandler.h b/src/gpu/gl/GrGLUniformHandler.h
index da7b13c4f5..d029691b84 100644
--- a/src/gpu/gl/GrGLUniformHandler.h
+++ b/src/gpu/gl/GrGLUniformHandler.h
@@ -30,6 +30,7 @@ private:
: INHERITED(program)
, fUniforms(kUniformsPerBlock)
, fSamplers(kUniformsPerBlock)
+ , fTexelBuffers(kUniformsPerBlock)
, fImageStorages(kUniformsPerBlock) {}
UniformHandle internalAddUniformArray(uint32_t visibility,
@@ -47,14 +48,21 @@ private:
return fSamplers[handle.toIndex()].fVariable;
}
- ImageStorageHandle addImageStorage(uint32_t visibility, GrSLType, GrImageStorageFormat,
- GrSLMemoryModel, GrSLRestrict, GrIOType,
- const char* name) override;
-
GrSwizzle samplerSwizzle(SamplerHandle handle) const override {
return fSamplerSwizzles[handle.toIndex()];
}
+ TexelBufferHandle addTexelBuffer(uint32_t visibility, GrSLPrecision,
+ const char* name) override;
+
+ const GrShaderVar& texelBufferVariable(TexelBufferHandle handle) const override {
+ return fTexelBuffers[handle.toIndex()].fVariable;
+ }
+
+ ImageStorageHandle addImageStorage(uint32_t visibility, GrSLType, GrImageStorageFormat,
+ GrSLMemoryModel, GrSLRestrict, GrIOType,
+ const char* name) override;
+
const GrShaderVar& imageStorageVariable(ImageStorageHandle handle) const override {
return fImageStorages[handle.toIndex()].fVariable;
}
@@ -75,6 +83,7 @@ private:
UniformInfoArray fUniforms;
UniformInfoArray fSamplers;
SkTArray<GrSwizzle> fSamplerSwizzles;
+ UniformInfoArray fTexelBuffers;
UniformInfoArray fImageStorages;
friend class GrGLProgramBuilder;
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index a82bccb867..8e662b971c 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -259,6 +259,7 @@ GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
programID,
fUniformHandler.fUniforms,
fUniformHandler.fSamplers,
+ fUniformHandler.fTexelBuffers,
fUniformHandler.fImageStorages,
fVaryingHandler.fPathProcVaryingInfos,
fGeometryProcessor,
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
index a779accab2..a4459d23f6 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
@@ -48,7 +48,7 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu
fragBuilder->getMangleString().c_str(), childProc.name());
TransformedCoordVars coordVars = args.fTransformedCoords.childInputs(childIndex);
TextureSamplers textureSamplers = args.fTexSamplers.childInputs(childIndex);
- BufferSamplers bufferSamplers = args.fBufferSamplers.childInputs(childIndex);
+ TexelBuffers texelBuffers = args.fTexelBuffers.childInputs(childIndex);
ImageStorages imageStorages = args.fImageStorages.childInputs(childIndex);
EmitArgs childArgs(fragBuilder,
args.fUniformHandler,
@@ -58,7 +58,7 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu
inputColor,
coordVars,
textureSamplers,
- bufferSamplers,
+ texelBuffers,
imageStorages,
args.fGpImplementsDistanceVector);
this->childProcessor(childIndex)->emitCode(childArgs);
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 1cf0d1d000..0d53196da8 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -30,6 +30,7 @@ public:
using UniformHandle = GrGLSLUniformHandler::UniformHandle;
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle;
+ using TexelBufferHandle = GrGLSLUniformHandler::TexelBufferHandle;
using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle;
private:
@@ -72,7 +73,7 @@ public:
&GrFragmentProcessor::numCoordTransforms>;
using TextureSamplers = BuilderInputProvider<SamplerHandle, GrResourceIOProcessor,
&GrResourceIOProcessor::numTextureSamplers>;
- using BufferSamplers = BuilderInputProvider<SamplerHandle, GrResourceIOProcessor,
+ using TexelBuffers = BuilderInputProvider<TexelBufferHandle, GrResourceIOProcessor,
&GrResourceIOProcessor::numBuffers>;
using ImageStorages = BuilderInputProvider<ImageStorageHandle, GrResourceIOProcessor,
&GrResourceIOProcessor::numImageStorages>;
@@ -117,7 +118,7 @@ public:
const char* inputColor,
const TransformedCoordVars& transformedCoordVars,
const TextureSamplers& textureSamplers,
- const BufferSamplers& bufferSamplers,
+ const TexelBuffers& texelBuffers,
const ImageStorages& imageStorages,
bool gpImplementsDistanceVector)
: fFragBuilder(fragBuilder)
@@ -128,7 +129,7 @@ public:
, fInputColor(inputColor)
, fTransformedCoords(transformedCoordVars)
, fTexSamplers(textureSamplers)
- , fBufferSamplers(bufferSamplers)
+ , fTexelBuffers(texelBuffers)
, fImageStorages(imageStorages)
, fGpImplementsDistanceVector(gpImplementsDistanceVector) {}
GrGLSLFPFragmentBuilder* fFragBuilder;
@@ -139,7 +140,7 @@ public:
const char* fInputColor;
const TransformedCoordVars& fTransformedCoords;
const TextureSamplers& fTexSamplers;
- const BufferSamplers& fBufferSamplers;
+ const TexelBuffers& fTexelBuffers;
const ImageStorages& fImageStorages;
bool fGpImplementsDistanceVector;
};
diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
index 5fbf9bd42f..2443f4745e 100644
--- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
+++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
@@ -29,6 +29,7 @@ public:
using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle;
+ using TexelBufferHandle = GrGLSLUniformHandler::TexelBufferHandle;
using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle;
/**
@@ -77,7 +78,7 @@ public:
const char* distanceVectorName,
const char* rtAdjustName,
const SamplerHandle* texSamplers,
- const SamplerHandle* bufferSamplers,
+ const TexelBufferHandle* texelBuffers,
const ImageStorageHandle* imageStorages,
FPCoordTransformHandler* transformHandler)
: fVertBuilder(vertBuilder)
@@ -92,7 +93,7 @@ public:
, fDistanceVectorName(distanceVectorName)
, fRTAdjustName(rtAdjustName)
, fTexSamplers(texSamplers)
- , fBufferSamplers(bufferSamplers)
+ , fTexelBuffers(texelBuffers)
, fImageStorages(imageStorages)
, fFPCoordTransformHandler(transformHandler) {}
GrGLSLVertexBuilder* fVertBuilder;
@@ -107,7 +108,7 @@ public:
const char* fDistanceVectorName;
const char* fRTAdjustName;
const SamplerHandle* fTexSamplers;
- const SamplerHandle* fBufferSamplers;
+ const TexelBufferHandle* fTexelBuffers;
const ImageStorageHandle* fImageStorages;
FPCoordTransformHandler* fFPCoordTransformHandler;
};
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 12e7ca2c1d..7a8cbad3a0 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -109,9 +109,9 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
fGeometryProcessor = proc.createGLSLInstance(*this->shaderCaps());
SkSTArray<4, SamplerHandle> texSamplers(proc.numTextureSamplers());
- SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers());
+ SkSTArray<2, TexelBufferHandle> texelBuffers(proc.numBuffers());
SkSTArray<2, ImageStorageHandle> imageStorages(proc.numImageStorages());
- this->emitSamplersAndImageStorages(proc, &texSamplers, &bufferSamplers, &imageStorages);
+ this->emitSamplersAndImageStorages(proc, &texSamplers, &texelBuffers, &imageStorages);
GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(fPipeline,
&fTransformedCoordVars);
@@ -127,7 +127,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
distanceVectorName,
rtAdjustName,
texSamplers.begin(),
- bufferSamplers.begin(),
+ texelBuffers.begin(),
imageStorages.begin(),
&transformHandler);
fGeometryProcessor->emitCode(args);
@@ -176,18 +176,18 @@ void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
SkSTArray<4, SamplerHandle> textureSamplerArray(fp.numTextureSamplers());
- SkSTArray<2, SamplerHandle> bufferSamplerArray(fp.numBuffers());
+ SkSTArray<2, TexelBufferHandle> texelBufferArray(fp.numBuffers());
SkSTArray<2, ImageStorageHandle> imageStorageArray(fp.numImageStorages());
GrFragmentProcessor::Iter iter(&fp);
while (const GrFragmentProcessor* subFP = iter.next()) {
- this->emitSamplersAndImageStorages(*subFP, &textureSamplerArray, &bufferSamplerArray,
+ this->emitSamplersAndImageStorages(*subFP, &textureSamplerArray, &texelBufferArray,
&imageStorageArray);
}
const GrShaderVar* coordVars = fTransformedCoordVars.begin() + transformedCoordVarsIdx;
GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars);
GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, textureSamplerArray.begin());
- GrGLSLFragmentProcessor::BufferSamplers bufferSamplers(&fp, bufferSamplerArray.begin());
+ GrGLSLFragmentProcessor::TexelBuffers texelBuffers(&fp, texelBufferArray.begin());
GrGLSLFragmentProcessor::ImageStorages imageStorages(&fp, imageStorageArray.begin());
GrGLSLFragmentProcessor::EmitArgs args(&fFS,
this->uniformHandler(),
@@ -197,7 +197,7 @@ void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
input.isOnes() ? nullptr : input.c_str(),
coords,
textureSamplers,
- bufferSamplers,
+ texelBuffers,
imageStorages,
this->primitiveProcessor().implementsDistanceVector());
@@ -266,7 +266,7 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrGLSLExpr4& colorIn,
void GrGLSLProgramBuilder::emitSamplersAndImageStorages(
const GrResourceIOProcessor& processor,
SkTArray<SamplerHandle>* outTexSamplerHandles,
- SkTArray<SamplerHandle>* outBufferSamplerHandles,
+ SkTArray<TexelBufferHandle>* outTexelBufferHandles,
SkTArray<ImageStorageHandle>* outImageStorageHandles) {
SkString name;
int numTextureSamplers = processor.numTextureSamplers();
@@ -292,10 +292,9 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages(
for (int b = 0; b < numBuffers; ++b) {
const GrResourceIOProcessor::BufferAccess& access = processor.bufferAccess(b);
- name.printf("BufferSampler_%d", outBufferSamplerHandles->count());
- outBufferSamplerHandles->emplace_back(
- this->emitSampler(kBufferSampler_GrSLType, access.texelConfig(), name.c_str(),
- access.visibility()));
+ name.printf("TexelBuffer_%d", outTexelBufferHandles->count());
+ outTexelBufferHandles->emplace_back(
+ this->emitTexelBuffer(access.texelConfig(), name.c_str(), access.visibility()));
texelBufferVisibility |= access.visibility();
}
@@ -315,10 +314,7 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages(
}
}
-GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(GrSLType samplerType,
- GrPixelConfig config,
- const char* name,
- GrShaderFlags visibility) {
+void GrGLSLProgramBuilder::updateSamplerCounts(GrShaderFlags visibility) {
if (visibility & kVertex_GrShaderFlag) {
++fNumVertexSamplers;
}
@@ -329,11 +325,25 @@ GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(GrSLType s
if (visibility & kFragment_GrShaderFlag) {
++fNumFragmentSamplers;
}
+}
+
+GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(GrSLType samplerType,
+ GrPixelConfig config,
+ const char* name,
+ GrShaderFlags visibility) {
+ this->updateSamplerCounts(visibility);
GrSLPrecision precision = this->shaderCaps()->samplerPrecision(config, visibility);
GrSwizzle swizzle = this->shaderCaps()->configTextureSwizzle(config);
return this->uniformHandler()->addSampler(visibility, swizzle, samplerType, precision, name);
}
+GrGLSLProgramBuilder::TexelBufferHandle GrGLSLProgramBuilder::emitTexelBuffer(
+ GrPixelConfig config, const char* name, GrShaderFlags visibility) {
+ this->updateSamplerCounts(visibility);
+ GrSLPrecision precision = this->shaderCaps()->samplerPrecision(config, visibility);
+ return this->uniformHandler()->addTexelBuffer(visibility, precision, name);
+}
+
GrGLSLProgramBuilder::ImageStorageHandle GrGLSLProgramBuilder::emitImageStorage(
const GrResourceIOProcessor::ImageStorageAccess& access, const char* name) {
if (access.visibility() & kVertex_GrShaderFlag) {
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index 147eb98c98..f12ba5e925 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -31,6 +31,7 @@ class GrGLSLProgramBuilder {
public:
using UniformHandle = GrGLSLUniformHandler::UniformHandle;
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle;
+ using TexelBufferHandle = GrGLSLUniformHandler::TexelBufferHandle;
using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle;
virtual ~GrGLSLProgramBuilder() {}
@@ -53,6 +54,10 @@ public:
return this->uniformHandler()->samplerSwizzle(handle);
}
+ const GrShaderVar& texelBufferVariable(TexelBufferHandle handle) const {
+ return this->uniformHandler()->texelBufferVariable(handle);
+ }
+
const GrShaderVar& imageStorageVariable(ImageStorageHandle handle) const {
return this->uniformHandler()->imageStorageVariable(handle);
}
@@ -155,13 +160,15 @@ private:
void emitAndInstallXferProc(const GrGLSLExpr4& colorIn, const GrGLSLExpr4& coverageIn);
void emitSamplersAndImageStorages(const GrResourceIOProcessor& processor,
SkTArray<SamplerHandle>* outTexSamplerHandles,
- SkTArray<SamplerHandle>* outBufferSamplerHandles,
+ SkTArray<TexelBufferHandle>* outTexelBufferHandles,
SkTArray<ImageStorageHandle>* outImageStorageHandles);
SamplerHandle emitSampler(GrSLType samplerType, GrPixelConfig, const char* name,
GrShaderFlags visibility);
+ TexelBufferHandle emitTexelBuffer(GrPixelConfig, const char* name, GrShaderFlags visibility);
ImageStorageHandle emitImageStorage(const GrResourceIOProcessor::ImageStorageAccess&,
const char* name);
void emitFSOutputSwizzle(bool hasSecondaryOutput);
+ void updateSamplerCounts(GrShaderFlags visibility);
bool checkSamplerCounts();
bool checkImageStorageCounts();
@@ -171,6 +178,8 @@ private:
void verify(const GrFragmentProcessor&);
#endif
+ // These are used to check that we don't excede the allowable number of resources in a shader.
+ // The sampler counts include both normal texure samplers as well as texel buffers.
int fNumVertexSamplers;
int fNumGeometrySamplers;
int fNumFragmentSamplers;
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 2c7e5e476d..de7b326917 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -143,19 +143,17 @@ void GrGLSLShaderBuilder::appendColorGamutXform(const char* srcColor,
}
void GrGLSLShaderBuilder::appendTexelFetch(SkString* out,
- SamplerHandle samplerHandle,
+ TexelBufferHandle texelBufferHandle,
const char* coordExpr) const {
- const GrShaderVar& sampler = fProgramBuilder->samplerVariable(samplerHandle);
+ const GrShaderVar& texelBuffer = fProgramBuilder->texelBufferVariable(texelBufferHandle);
SkASSERT(fProgramBuilder->shaderCaps()->texelFetchSupport());
- SkASSERT(GrSLTypeIsCombinedSamplerType(sampler.getType()));
-
- out->appendf("texelFetch(%s, %s)", sampler.c_str(), coordExpr);
- append_texture_swizzle(out, fProgramBuilder->samplerSwizzle(samplerHandle));
+ out->appendf("texelFetch(%s, %s)", texelBuffer.c_str(), coordExpr);
}
-void GrGLSLShaderBuilder::appendTexelFetch(SamplerHandle samplerHandle, const char* coordExpr) {
- this->appendTexelFetch(&this->code(), samplerHandle, coordExpr);
+void GrGLSLShaderBuilder::appendTexelFetch(TexelBufferHandle texelBufferHandle,
+ const char* coordExpr) {
+ this->appendTexelFetch(&this->code(), texelBufferHandle, coordExpr);
}
void GrGLSLShaderBuilder::appendImageStorageLoad(SkString* out, ImageStorageHandle handle,
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.h b/src/gpu/glsl/GrGLSLShaderBuilder.h
index 2d6aaf08fa..16e5b8606c 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.h
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.h
@@ -26,6 +26,7 @@ public:
virtual ~GrGLSLShaderBuilder() {}
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle;
+ using TexelBufferHandle = GrGLSLUniformHandler::TexelBufferHandle;
using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle;
/** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or
@@ -68,10 +69,10 @@ public:
/** Fetches an unfiltered texel from a sampler at integer coordinates. coordExpr must match the
dimensionality of the sampler and must be within the sampler's range. coordExpr is emitted
exactly once, so expressions like "idx++" are acceptable. */
- void appendTexelFetch(SkString* out, SamplerHandle, const char* coordExpr) const;
+ void appendTexelFetch(SkString* out, TexelBufferHandle, const char* coordExpr) const;
/** Version of above that appends the result to the shader code instead.*/
- void appendTexelFetch(SamplerHandle, const char* coordExpr);
+ void appendTexelFetch(TexelBufferHandle, const char* coordExpr);
/** Creates a string of shader code that performs an image load. */
void appendImageStorageLoad(SkString* out, ImageStorageHandle, const char* coordExpr);
diff --git a/src/gpu/glsl/GrGLSLUniformHandler.h b/src/gpu/glsl/GrGLSLUniformHandler.h
index 3d21c1cc4b..cf80c3ff0a 100644
--- a/src/gpu/glsl/GrGLSLUniformHandler.h
+++ b/src/gpu/glsl/GrGLSLUniformHandler.h
@@ -20,6 +20,7 @@ public:
using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
GR_DEFINE_RESOURCE_HANDLE_CLASS(SamplerHandle);
+ GR_DEFINE_RESOURCE_HANDLE_CLASS(TexelBufferHandle);
GR_DEFINE_RESOURCE_HANDLE_CLASS(ImageStorageHandle);
/** Add a uniform variable to the current program, that has visibility in one or more shaders.
@@ -68,6 +69,10 @@ private:
virtual SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision,
const char* name) = 0;
+ virtual const GrShaderVar& texelBufferVariable(TexelBufferHandle) const = 0;
+ virtual TexelBufferHandle addTexelBuffer(uint32_t visibility, GrSLPrecision,
+ const char* name) = 0;
+
virtual const GrShaderVar& imageStorageVariable(ImageStorageHandle) const = 0;
virtual ImageStorageHandle addImageStorage(uint32_t visibility, GrSLType type,
GrImageStorageFormat, GrSLMemoryModel, GrSLRestrict,
diff --git a/src/gpu/instanced/InstanceProcessor.cpp b/src/gpu/instanced/InstanceProcessor.cpp
index efbf8251c4..32ab712c8c 100644
--- a/src/gpu/instanced/InstanceProcessor.cpp
+++ b/src/gpu/instanced/InstanceProcessor.cpp
@@ -104,7 +104,7 @@ public:
fVertexBuilder(vertexBuilder) {
}
- void initParams(const SamplerHandle paramsBuffer) {
+ void initParams(const TexelBufferHandle paramsBuffer) {
fParamsBuffer = paramsBuffer;
fVertexBuilder->codeAppendf("highp int paramsIdx = int(%s & 0x%x);",
this->attr(Attrib::kInstanceInfo),
@@ -146,7 +146,7 @@ public:
private:
const InstanceProcessor& fInstProc;
GrGLSLVertexBuilder* fVertexBuilder;
- SamplerHandle fParamsBuffer;
+ TexelBufferHandle fParamsBuffer;
};
class GLSLInstanceProcessor::Backend {
@@ -229,7 +229,7 @@ void GLSLInstanceProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
VertexInputs inputs(ip, v);
if (ip.opInfo().fHasParams) {
SkASSERT(1 == ip.numBuffers());
- inputs.initParams(args.fBufferSamplers[0]);
+ inputs.initParams(args.fTexelBuffers[0]);
}
if (!ip.opInfo().fHasPerspective) {
diff --git a/src/gpu/vk/GrVkUniformHandler.h b/src/gpu/vk/GrVkUniformHandler.h
index cc7aaa3689..66aff61679 100644
--- a/src/gpu/vk/GrVkUniformHandler.h
+++ b/src/gpu/vk/GrVkUniformHandler.h
@@ -78,7 +78,16 @@ private:
return fSamplers[handle.toIndex()].fVisibility;
}
+ TexelBufferHandle addTexelBuffer(uint32_t visibility, GrSLPrecision,
+ const char* name) override {
+ SkFAIL("Texel buffers not implemented for Vulkan.");
+ return 0;
+ }
+
int numTexelBuffers() const { return fTexelBuffers.count(); }
+ const GrShaderVar& texelBufferVariable(TexelBufferHandle handle) const override {
+ return fTexelBuffers[handle.toIndex()].fVariable;
+ }
uint32_t texelBufferVisibility(SamplerHandle handle) const {
return fTexelBuffers[handle.toIndex()].fVisibility;
}