Fix a couple potential bugs when adding sampler info to a program key
Calling add32 can re-allocate the key storage, so it isn't safe to call
add32n and then keep writing into the returned pointer if an extra
sampler key is encountered.
Also fix the GP sampler key code to actually set the last bit, not the
16th bit.
Change-Id: I9c83435a164ab0391e2e6a9e1a9bdf6839490a15
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229278
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index f0212e5..b826125 100644
--- a/src/gpu/GrProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -63,21 +63,22 @@
if (!numTextureSamplers) {
return;
}
- uint32_t* k32 = b->add32n(numTextureSamplers);
for (int i = 0; i < numTextureSamplers; ++i) {
const GrFragmentProcessor::TextureSampler& sampler = fp.textureSampler(i);
const GrTexture* tex = sampler.peekTexture();
- k32[i] = sampler_key(tex->texturePriv().textureType(), sampler.swizzle(), tex->config(),
- caps);
+ uint32_t samplerKey = sampler_key(
+ tex->texturePriv().textureType(), sampler.swizzle(), tex->config(), caps);
uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram(
sampler.samplerState(), sampler.proxy()->backendFormat());
if (extraSamplerKey) {
SkASSERT(sampler.proxy()->textureType() == GrTextureType::kExternal);
// We first mark the normal sampler key with last bit to flag that it has an extra
- // sampler key. We then add all the extraSamplerKeys to the end of the normal ones.
- SkASSERT((k32[i] & (1 << 31)) == 0);
- k32[i] = k32[i] | (1 << 31);
+ // sampler key. We then add both keys.
+ SkASSERT((samplerKey & (1 << 31)) == 0);
+ b->add32(samplerKey | (1 << 31));
b->add32(extraSamplerKey);
+ } else {
+ b->add32(samplerKey);
}
}
}
@@ -88,18 +89,20 @@
if (!numTextureSamplers) {
return;
}
- uint32_t* k32 = b->add32n(numTextureSamplers);
for (int i = 0; i < numTextureSamplers; ++i) {
const GrPrimitiveProcessor::TextureSampler& sampler = pp.textureSampler(i);
- k32[i] = sampler_key(sampler.textureType(), sampler.swizzle(), sampler.config(), caps);
+ uint32_t samplerKey = sampler_key(
+ sampler.textureType(), sampler.swizzle(), sampler.config(), caps);
uint32_t extraSamplerKey = sampler.extraSamplerKey();
if (extraSamplerKey) {
SkASSERT(sampler.textureType() == GrTextureType::kExternal);
// We first mark the normal sampler key with last bit to flag that it has an extra
- // sampler key. We then add all the extraSamplerKeys to the end of the normal ones.
- SkASSERT((k32[i] & (1 << 15)) == 0);
- k32[i] = k32[i] | (1 << 15);
+ // sampler key. We then add both keys.
+ SkASSERT((samplerKey & (1 << 31)) == 0);
+ b->add32(samplerKey | (1 << 31));
b->add32(extraSamplerKey);
+ } else {
+ b->add32(samplerKey);
}
}
}