| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrVkResourceProvider.h" | 8 #include "GrVkResourceProvider.h" |
| 9 | 9 |
| 10 #include "GrVkGpu.h" | 10 #include "GrVkGpu.h" |
| 11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
| 12 #include "GrRenderTargetPriv.h" // TODO: remove once refPipelineState gets passe
d stencil settings. |
| 12 #include "GrVkPipelineState.h" | 13 #include "GrVkPipelineState.h" |
| 13 #include "GrVkPipelineStateBuilder.h" | 14 #include "GrVkPipelineStateBuilder.h" |
| 14 #include "SkOpts.h" | 15 #include "SkOpts.h" |
| 15 #include "glsl/GrGLSLFragmentProcessor.h" | 16 #include "glsl/GrGLSLFragmentProcessor.h" |
| 16 #include "glsl/GrGLSLProgramDataManager.h" | 17 #include "glsl/GrGLSLProgramDataManager.h" |
| 17 | 18 |
| 18 #ifdef GR_PIPELINE_STATE_CACHE_STATS | 19 #ifdef GR_PIPELINE_STATE_CACHE_STATS |
| 19 // Display pipeline state cache usage | 20 // Display pipeline state cache usage |
| 20 static const bool c_DisplayVkPipelineCache{false}; | 21 static const bool c_DisplayVkPipelineCache{false}; |
| 21 #endif | 22 #endif |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 91 } |
| 91 | 92 |
| 92 sk_sp<GrVkPipelineState> GrVkResourceProvider::PipelineStateCache::refPipelineSt
ate( | 93 sk_sp<GrVkPipelineState> GrVkResourceProvider::PipelineStateCache::refPipelineSt
ate( |
| 93 const GrPipeline&
pipeline, | 94 const GrPipeline&
pipeline, |
| 94 const GrPrimitive
Processor& primProc, | 95 const GrPrimitive
Processor& primProc, |
| 95 GrPrimitiveType p
rimitiveType, | 96 GrPrimitiveType p
rimitiveType, |
| 96 const GrVkRenderP
ass& renderPass) { | 97 const GrVkRenderP
ass& renderPass) { |
| 97 #ifdef GR_PIPELINE_STATE_CACHE_STATS | 98 #ifdef GR_PIPELINE_STATE_CACHE_STATS |
| 98 ++fTotalRequests; | 99 ++fTotalRequests; |
| 99 #endif | 100 #endif |
| 101 GrStencilSettings stencil; |
| 102 if (pipeline.isStencilEnabled()) { |
| 103 GrRenderTarget* rt = pipeline.getRenderTarget(); |
| 104 // TODO: attach stencil and create settings during render target flush. |
| 105 SkASSERT(rt->renderTargetPriv().getStencilAttachment()); |
| 106 stencil.reset(*pipeline.getUserStencil(), pipeline.hasStencilClip(), |
| 107 rt->renderTargetPriv().numStencilBits()); |
| 108 } |
| 109 |
| 100 // Get GrVkProgramDesc | 110 // Get GrVkProgramDesc |
| 101 GrVkPipelineState::Desc desc; | 111 GrVkPipelineState::Desc desc; |
| 102 if (!GrVkPipelineState::Desc::Build(&desc, primProc, pipeline, primitiveType
, | 112 if (!GrVkPipelineState::Desc::Build(&desc, primProc, pipeline, stencil, |
| 103 *fGpu->vkCaps().glslCaps())) { | 113 primitiveType, *fGpu->vkCaps().glslCaps(
))) { |
| 104 GrCapsDebugf(fGpu->caps(), "Failed to build vk program descriptor!\n"); | 114 GrCapsDebugf(fGpu->caps(), "Failed to build vk program descriptor!\n"); |
| 105 return nullptr; | 115 return nullptr; |
| 106 } | 116 } |
| 107 desc.finalize(); | 117 desc.finalize(); |
| 108 | 118 |
| 109 Entry* entry = nullptr; | 119 Entry* entry = nullptr; |
| 110 if (Entry** entryptr = fHashTable.find(desc)) { | 120 if (Entry** entryptr = fHashTable.find(desc)) { |
| 111 SkASSERT(*entryptr); | 121 SkASSERT(*entryptr); |
| 112 entry = *entryptr; | 122 entry = *entryptr; |
| 113 } | 123 } |
| 114 if (!entry) { | 124 if (!entry) { |
| 115 #ifdef GR_PIPELINE_STATE_CACHE_STATS | 125 #ifdef GR_PIPELINE_STATE_CACHE_STATS |
| 116 ++fCacheMisses; | 126 ++fCacheMisses; |
| 117 #endif | 127 #endif |
| 118 sk_sp<GrVkPipelineState> pipelineState( | 128 sk_sp<GrVkPipelineState> pipelineState( |
| 119 GrVkPipelineStateBuilder::CreatePipelineState(fGpu, | 129 GrVkPipelineStateBuilder::CreatePipelineState(fGpu, |
| 120 pipeline, | 130 pipeline, |
| 131 stencil, |
| 121 primProc, | 132 primProc, |
| 122 primitiveType, | 133 primitiveType, |
| 123 desc, | 134 desc, |
| 124 renderPass)); | 135 renderPass)); |
| 125 if (nullptr == pipelineState) { | 136 if (nullptr == pipelineState) { |
| 126 return nullptr; | 137 return nullptr; |
| 127 } | 138 } |
| 128 if (fCount < kMaxEntries) { | 139 if (fCount < kMaxEntries) { |
| 129 entry = new Entry; | 140 entry = new Entry; |
| 130 fCount++; | 141 fCount++; |
| 131 } else { | 142 } else { |
| 132 SkASSERT(fCount == kMaxEntries); | 143 SkASSERT(fCount == kMaxEntries); |
| 133 entry = fLRUList.head(); | 144 entry = fLRUList.head(); |
| 134 fLRUList.remove(entry); | 145 fLRUList.remove(entry); |
| 135 entry->fPipelineState->freeGPUResources(fGpu); | 146 entry->fPipelineState->freeGPUResources(fGpu); |
| 136 fHashTable.remove(entry->fPipelineState->getDesc()); | 147 fHashTable.remove(entry->fPipelineState->getDesc()); |
| 137 } | 148 } |
| 138 entry->fPipelineState = std::move(pipelineState); | 149 entry->fPipelineState = std::move(pipelineState); |
| 139 fHashTable.set(entry); | 150 fHashTable.set(entry); |
| 140 fLRUList.addToTail(entry); | 151 fLRUList.addToTail(entry); |
| 141 return entry->fPipelineState; | 152 return entry->fPipelineState; |
| 142 } else { | 153 } else { |
| 143 fLRUList.remove(entry); | 154 fLRUList.remove(entry); |
| 144 fLRUList.addToTail(entry); | 155 fLRUList.addToTail(entry); |
| 145 } | 156 } |
| 146 return entry->fPipelineState; | 157 return entry->fPipelineState; |
| 147 } | 158 } |
| OLD | NEW |