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 | |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrStencilSettings.h" |
| 11 | |
| 12 | GrStencilSettings GrProgramInfo::nonGLStencilSettings() const { |
| 13 | GrStencilSettings stencil; |
| 14 | |
| 15 | if (this->pipeline().isStencilEnabled()) { |
| 16 | stencil.reset(*this->pipeline().getUserStencil(), |
| 17 | this->pipeline().hasStencilClip(), |
| 18 | 8); |
| 19 | } |
| 20 | |
| 21 | return stencil; |
| 22 | } |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 23 | |
| 24 | #ifdef SK_DEBUG |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 25 | #include "src/gpu/GrMesh.h" |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 26 | #include "src/gpu/GrTexturePriv.h" |
| 27 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame^] | 28 | void GrProgramInfo::validate(bool flushTime) const { |
| 29 | if (flushTime) { |
| 30 | SkASSERT(fPipeline->allProxiesInstantiated()); |
| 31 | } |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 32 | |
| 33 | if (this->hasDynamicPrimProcTextures()) { |
| 34 | SkASSERT(!this->hasFixedPrimProcTextures()); |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 35 | SkASSERT(fPrimProc->numTextureSamplers()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 36 | } else if (this->hasFixedPrimProcTextures()) { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 37 | SkASSERT(fPrimProc->numTextureSamplers()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 38 | } else { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 39 | SkASSERT(!fPrimProc->numTextureSamplers()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 40 | } |
| 41 | |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 42 | SkASSERT(!fPipeline->isScissorEnabled() || this->hasFixedScissor() || |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 43 | this->hasDynamicScissors()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 44 | |
| 45 | if (this->hasDynamicPrimProcTextures()) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 46 | // Check that, for a given sampler, the properties of the dynamic textures remain |
| 47 | // the same for all the meshes |
| 48 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 49 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(0); |
| 50 | |
| 51 | const GrBackendFormat& format = dynamicPrimProcTextures[s]->backendFormat(); |
| 52 | GrTextureType type = dynamicPrimProcTextures[s]->textureType(); |
| 53 | GrPixelConfig config = dynamicPrimProcTextures[s]->config(); |
| 54 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 55 | for (int m = 1; m < fNumDynamicStateArrays; ++m) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 56 | dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 57 | |
| 58 | auto testProxy = dynamicPrimProcTextures[s]; |
| 59 | SkASSERT(testProxy->backendFormat() == format); |
| 60 | SkASSERT(testProxy->textureType() == type); |
| 61 | SkASSERT(testProxy->config() == config); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 67 | void GrProgramInfo::checkAllInstantiated() const { |
| 68 | if (this->hasFixedPrimProcTextures()) { |
| 69 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 70 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 71 | SkASSERT(fixedPrimProcTextures[s]->isInstantiated()); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if (this->hasDynamicPrimProcTextures()) { |
| 76 | for (int m = 0; m < fNumDynamicStateArrays; ++m) { |
| 77 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 78 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 79 | SkASSERT(dynamicPrimProcTextures[s]->isInstantiated()); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void GrProgramInfo::checkMSAAAndMIPSAreResolved() const { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 86 | |
| 87 | auto assertResolved = [](GrTexture* tex, const GrSamplerState& sampler) { |
| 88 | SkASSERT(tex); |
| 89 | |
| 90 | // Ensure mipmaps were all resolved ahead of time by the DAG. |
| 91 | if (GrSamplerState::Filter::kMipMap == sampler.filter() && |
| 92 | (tex->width() != 1 || tex->height() != 1)) { |
| 93 | // There are some cases where we might be given a non-mipmapped texture with a mipmap |
| 94 | // filter. See skbug.com/7094. |
| 95 | SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes || |
| 96 | !tex->texturePriv().mipMapsAreDirty()); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | if (this->hasDynamicPrimProcTextures()) { |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 101 | for (int m = 0; m < fNumDynamicStateArrays; ++m) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 102 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 103 | |
| 104 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 105 | auto* tex = dynamicPrimProcTextures[s]->peekTexture(); |
| 106 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 107 | } |
| 108 | } |
| 109 | } else if (this->hasFixedPrimProcTextures()) { |
| 110 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 111 | |
| 112 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 113 | auto* tex = fixedPrimProcTextures[s]->peekTexture(); |
| 114 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | GrFragmentProcessor::Iter iter(this->pipeline()); |
| 119 | while (const GrFragmentProcessor* fp = iter.next()) { |
| 120 | for (int s = 0; s < fp->numTextureSamplers(); ++s) { |
| 121 | const auto& textureSampler = fp->textureSampler(s); |
| 122 | assertResolved(textureSampler.peekTexture(), textureSampler.samplerState()); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 127 | void GrProgramInfo::compatibleWithMeshes(const GrMesh meshes[], int meshCount) const { |
| 128 | SkASSERT(!fNumDynamicStateArrays || meshCount == fNumDynamicStateArrays); |
| 129 | |
| 130 | for (int i = 0; i < meshCount; ++i) { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 131 | SkASSERT(fPrimProc->hasVertexAttributes() == meshes[i].hasVertexData()); |
| 132 | SkASSERT(fPrimProc->hasInstanceAttributes() == meshes[i].hasInstanceData()); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 136 | #endif |