Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "src/gpu/GrProgramInfo.h" |
| 9 | |
| 10 | |
| 11 | #ifdef SK_DEBUG |
| 12 | #include "src/gpu/GrTexturePriv.h" |
| 13 | |
| 14 | void GrProgramInfo::validate() const { |
| 15 | SkASSERT(!fPipeline.isBad()); |
| 16 | |
| 17 | if (this->hasDynamicPrimProcTextures()) { |
| 18 | SkASSERT(!this->hasFixedPrimProcTextures()); |
| 19 | SkASSERT(fPrimProc.numTextureSamplers()); |
| 20 | } else if (this->hasFixedPrimProcTextures()) { |
| 21 | SkASSERT(fPrimProc.numTextureSamplers()); |
| 22 | } else { |
| 23 | SkASSERT(!fPrimProc.numTextureSamplers()); |
| 24 | } |
| 25 | |
| 26 | SkASSERT(!fPipeline.isScissorEnabled() || this->hasFixedScissor() || |
| 27 | this->hasDynamicScissors()); |
| 28 | } |
| 29 | |
| 30 | void GrProgramInfo::checkAllInstantiated(int meshCount) const { |
| 31 | if (this->hasFixedPrimProcTextures()) { |
| 32 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 33 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 34 | SkASSERT(fixedPrimProcTextures[s]->isInstantiated()); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if (this->hasDynamicPrimProcTextures()) { |
| 39 | for (int m = 0; m < meshCount; ++m) { |
| 40 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 41 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 42 | SkASSERT(dynamicPrimProcTextures[s]->isInstantiated()); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // TODO: if GrProgramInfo had the mesh count we could do this in validate! |
| 47 | // Check that, for a given sampler, the properties of the dynamic textures remain |
| 48 | // the same for all the meshes |
| 49 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 50 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(0); |
| 51 | |
| 52 | const GrBackendFormat& format = dynamicPrimProcTextures[s]->backendFormat(); |
| 53 | GrTextureType type = dynamicPrimProcTextures[s]->textureType(); |
| 54 | GrPixelConfig config = dynamicPrimProcTextures[s]->config(); |
| 55 | |
| 56 | for (int m = 1; m < meshCount; ++m) { |
| 57 | dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 58 | |
| 59 | auto testProxy = dynamicPrimProcTextures[s]; |
| 60 | SkASSERT(testProxy->backendFormat() == format); |
| 61 | SkASSERT(testProxy->textureType() == type); |
| 62 | SkASSERT(testProxy->config() == config); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void GrProgramInfo::checkMSAAAndMIPSAreResolved(int meshCount) const { |
| 69 | |
| 70 | auto assertResolved = [](GrTexture* tex, const GrSamplerState& sampler) { |
| 71 | SkASSERT(tex); |
| 72 | |
| 73 | // Ensure mipmaps were all resolved ahead of time by the DAG. |
| 74 | if (GrSamplerState::Filter::kMipMap == sampler.filter() && |
| 75 | (tex->width() != 1 || tex->height() != 1)) { |
| 76 | // There are some cases where we might be given a non-mipmapped texture with a mipmap |
| 77 | // filter. See skbug.com/7094. |
| 78 | SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes || |
| 79 | !tex->texturePriv().mipMapsAreDirty()); |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | if (this->hasDynamicPrimProcTextures()) { |
| 84 | for (int m = 0; m < meshCount; ++m) { |
| 85 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 86 | |
| 87 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 88 | auto* tex = dynamicPrimProcTextures[s]->peekTexture(); |
| 89 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 90 | } |
| 91 | } |
| 92 | } else if (this->hasFixedPrimProcTextures()) { |
| 93 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 94 | |
| 95 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 96 | auto* tex = fixedPrimProcTextures[s]->peekTexture(); |
| 97 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | GrFragmentProcessor::Iter iter(this->pipeline()); |
| 102 | while (const GrFragmentProcessor* fp = iter.next()) { |
| 103 | for (int s = 0; s < fp->numTextureSamplers(); ++s) { |
| 104 | const auto& textureSampler = fp->textureSampler(s); |
| 105 | assertResolved(textureSampler.peekTexture(), textureSampler.samplerState()); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | #endif |