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(); |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 52 | GrTextureType type = dynamicPrimProcTextures[s]->backendFormat().textureType(); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 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]; |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 59 | SkASSERT(testProxy->asTextureProxy()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 60 | SkASSERT(testProxy->backendFormat() == format); |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 61 | SkASSERT(testProxy->backendFormat().textureType() == type); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 62 | SkASSERT(testProxy->config() == config); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 68 | void GrProgramInfo::checkAllInstantiated() const { |
| 69 | if (this->hasFixedPrimProcTextures()) { |
| 70 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 71 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 72 | SkASSERT(fixedPrimProcTextures[s]->isInstantiated()); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if (this->hasDynamicPrimProcTextures()) { |
| 77 | for (int m = 0; m < fNumDynamicStateArrays; ++m) { |
| 78 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 79 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 80 | SkASSERT(dynamicPrimProcTextures[s]->isInstantiated()); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | void GrProgramInfo::checkMSAAAndMIPSAreResolved() const { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 87 | |
| 88 | auto assertResolved = [](GrTexture* tex, const GrSamplerState& sampler) { |
| 89 | SkASSERT(tex); |
| 90 | |
| 91 | // Ensure mipmaps were all resolved ahead of time by the DAG. |
| 92 | if (GrSamplerState::Filter::kMipMap == sampler.filter() && |
| 93 | (tex->width() != 1 || tex->height() != 1)) { |
| 94 | // There are some cases where we might be given a non-mipmapped texture with a mipmap |
| 95 | // filter. See skbug.com/7094. |
| 96 | SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes || |
| 97 | !tex->texturePriv().mipMapsAreDirty()); |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | if (this->hasDynamicPrimProcTextures()) { |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 102 | for (int m = 0; m < fNumDynamicStateArrays; ++m) { |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 103 | auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m); |
| 104 | |
| 105 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 106 | auto* tex = dynamicPrimProcTextures[s]->peekTexture(); |
| 107 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 108 | } |
| 109 | } |
| 110 | } else if (this->hasFixedPrimProcTextures()) { |
| 111 | auto fixedPrimProcTextures = this->fixedPrimProcTextures(); |
| 112 | |
| 113 | for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) { |
| 114 | auto* tex = fixedPrimProcTextures[s]->peekTexture(); |
| 115 | assertResolved(tex, this->primProc().textureSampler(s).samplerState()); |
| 116 | } |
| 117 | } |
| 118 | |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 119 | for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) { |
| 120 | assertResolved(sampler.peekTexture(), sampler.samplerState()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 124 | void GrProgramInfo::compatibleWithMeshes(const GrMesh meshes[], int meshCount) const { |
| 125 | SkASSERT(!fNumDynamicStateArrays || meshCount == fNumDynamicStateArrays); |
| 126 | |
| 127 | for (int i = 0; i < meshCount; ++i) { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 128 | SkASSERT(fPrimProc->hasVertexAttributes() == meshes[i].hasVertexData()); |
| 129 | SkASSERT(fPrimProc->hasInstanceAttributes() == meshes[i].hasInstanceData()); |
Chris Dalton | ce425af | 2019-12-16 10:39:03 -0700 | [diff] [blame] | 130 | if (fPipeline->usesConservativeRaster()) { |
| 131 | // Conservative raster, by default, only supports triangles. Implementations can |
| 132 | // optionally indicate that they also support points and lines, but we don't currently |
| 133 | // query or track that info. |
| 134 | SkASSERT(GrIsPrimTypeTris(meshes[i].primitiveType())); |
| 135 | } |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 139 | #endif |