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 |
| 25 | #include "src/gpu/GrTexturePriv.h" |
| 26 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 27 | void GrProgramInfo::validate(bool flushTime) const { |
| 28 | if (flushTime) { |
| 29 | SkASSERT(fPipeline->allProxiesInstantiated()); |
| 30 | } |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 31 | |
| 32 | if (this->hasDynamicPrimProcTextures()) { |
| 33 | SkASSERT(!this->hasFixedPrimProcTextures()); |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 34 | SkASSERT(fPrimProc->numTextureSamplers()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 35 | } else if (this->hasFixedPrimProcTextures()) { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 36 | SkASSERT(fPrimProc->numTextureSamplers()); |
Chris Dalton | 012f849 | 2020-03-05 11:49:15 -0700 | [diff] [blame] | 37 | // TODO: We will soon remove dynamic state from GrProgramInfo. But while migrating to the new |
| 38 | // bind/draw API on GrOpsRenderPass, some code will not set the dynamic state because it calls |
| 39 | // bindTextures() directly. Once dynamic state (including this validation code) is moved out of |
| 40 | // GrProgramInfo, we can restore this assert. |
| 41 | // } else { |
| 42 | // SkASSERT(!fPrimProc->numTextureSamplers()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 43 | } |
| 44 | |
Chris Dalton | 012f849 | 2020-03-05 11:49:15 -0700 | [diff] [blame] | 45 | |
| 46 | // TODO: We will soon remove dynamic state from GrProgramInfo. But while migrating to the new |
| 47 | // bind/draw API on GrOpsRenderPass, some code will not set the dynamic state because it calls |
| 48 | // setScissorRect() directly. Once dynamic state (including this validation code) is moved out |
| 49 | // of GrProgramInfo, we can restore this assert. |
| 50 | #if 0 |
| 51 | SkASSERT((fPipeline->isScissorTestEnabled()) == |
| 52 | (this->hasFixedScissor() || this->hasDynamicScissors())); |
| 53 | #else |
| 54 | if (!fPipeline->isScissorTestEnabled()) { |
| 55 | SkASSERT(!this->hasFixedScissor() && !this->hasDynamicScissors()); |
| 56 | } |
| 57 | #endif |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 58 | |
| 59 | if (this->hasDynamicPrimProcTextures()) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 60 | // Check that, for a given sampler, the properties of the dynamic textures remain |
| 61 | // the same for all the meshes |
| 62 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 63 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(0); |
| 64 | |
| 65 | const GrBackendFormat& format = dynamicPrimProcTextures[s]->backendFormat(); |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 66 | GrTextureType type = dynamicPrimProcTextures[s]->backendFormat().textureType(); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 67 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 68 | for (int m = 1; m < fNumDynamicStateArrays; ++m) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 69 | dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 70 | |
| 71 | auto testProxy = dynamicPrimProcTextures[s]; |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 72 | SkASSERT(testProxy->asTextureProxy()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 73 | SkASSERT(testProxy->backendFormat() == format); |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 74 | SkASSERT(testProxy->backendFormat().textureType() == type); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 80 | void GrProgramInfo::checkAllInstantiated() const { |
| 81 | if (this->hasFixedPrimProcTextures()) { |
| 82 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 83 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 84 | SkASSERT(fixedPrimProcTextures[s]->isInstantiated()); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (this->hasDynamicPrimProcTextures()) { |
| 89 | for (int m = 0; m < fNumDynamicStateArrays; ++m) { |
| 90 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 91 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 92 | SkASSERT(dynamicPrimProcTextures[s]->isInstantiated()); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void GrProgramInfo::checkMSAAAndMIPSAreResolved() const { |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 99 | auto assertResolved = [](GrTexture* tex, GrSamplerState sampler) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 100 | SkASSERT(tex); |
| 101 | |
| 102 | // Ensure mipmaps were all resolved ahead of time by the DAG. |
| 103 | if (GrSamplerState::Filter::kMipMap == sampler.filter() && |
| 104 | (tex->width() != 1 || tex->height() != 1)) { |
| 105 | // There are some cases where we might be given a non-mipmapped texture with a mipmap |
| 106 | // filter. See skbug.com/7094. |
| 107 | SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes || |
| 108 | !tex->texturePriv().mipMapsAreDirty()); |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | if (this->hasDynamicPrimProcTextures()) { |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 113 | for (int m = 0; m < fNumDynamicStateArrays; ++m) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 114 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 115 | |
| 116 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 117 | auto* tex = dynamicPrimProcTextures[s]->peekTexture(); |
| 118 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 119 | } |
| 120 | } |
| 121 | } else if (this->hasFixedPrimProcTextures()) { |
| 122 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 123 | |
| 124 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 125 | auto* tex = fixedPrimProcTextures[s]->peekTexture(); |
| 126 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 127 | } |
| 128 | } |
| 129 | |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 130 | for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) { |
| 131 | assertResolved(sampler.peekTexture(), sampler.samplerState()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 135 | #endif |