aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
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 /src/gpu/glsl
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>
Diffstat (limited to 'src/gpu/glsl')
-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
8 files changed, 61 insertions, 36 deletions
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,