jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 1 | /* |
Greg Daniel | c10bb6a | 2019-10-29 09:50:32 -0400 | [diff] [blame] | 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 7 | |
Greg Daniel | 9d02a4c | 2020-07-15 14:26:08 -0400 | [diff] [blame] | 8 | #include "src/gpu/vk/GrVkPipelineState.h" |
| 9 | |
Mike Reed | 13711eb | 2020-07-14 17:16:32 -0400 | [diff] [blame] | 10 | #include "src/core/SkMipmap.h" |
Brian Salomon | 4895946 | 2021-08-11 13:01:06 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrFragmentProcessor.h" |
| 12 | #include "src/gpu/GrGeometryProcessor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrPipeline.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrRenderTarget.h" |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrTexture.h" |
Brian Salomon | 4895946 | 2021-08-11 13:01:06 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrXferProcessor.h" |
Robert Phillips | 550de7f | 2021-07-06 16:28:52 -0400 | [diff] [blame] | 17 | #include "src/gpu/effects/GrTextureEffect.h" |
Greg Daniel | af1d193 | 2021-02-08 13:55:26 -0500 | [diff] [blame] | 18 | #include "src/gpu/vk/GrVkBuffer.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/vk/GrVkCommandBuffer.h" |
| 20 | #include "src/gpu/vk/GrVkDescriptorPool.h" |
| 21 | #include "src/gpu/vk/GrVkDescriptorSet.h" |
| 22 | #include "src/gpu/vk/GrVkGpu.h" |
| 23 | #include "src/gpu/vk/GrVkImageView.h" |
| 24 | #include "src/gpu/vk/GrVkMemory.h" |
| 25 | #include "src/gpu/vk/GrVkPipeline.h" |
Greg Daniel | 37fd658 | 2020-09-14 12:36:09 -0400 | [diff] [blame] | 26 | #include "src/gpu/vk/GrVkRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/vk/GrVkSampler.h" |
| 28 | #include "src/gpu/vk/GrVkTexture.h" |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 29 | |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 30 | GrVkPipelineState::GrVkPipelineState( |
Brian Salomon | f95940b | 2021-08-09 15:56:24 -0400 | [diff] [blame] | 31 | GrVkGpu* gpu, |
| 32 | sk_sp<const GrVkPipeline> pipeline, |
| 33 | const GrVkDescriptorSetManager::Handle& samplerDSHandle, |
| 34 | const GrGLSLBuiltinUniformHandles& builtinUniformHandles, |
| 35 | const UniformInfoArray& uniforms, |
| 36 | uint32_t uniformSize, |
| 37 | bool usePushConstants, |
| 38 | const UniformInfoArray& samplers, |
| 39 | std::unique_ptr<GrGeometryProcessor::ProgramImpl> gpImpl, |
Brian Salomon | d89d445 | 2021-08-09 16:42:36 -0400 | [diff] [blame] | 40 | std::unique_ptr<GrXferProcessor::ProgramImpl> xpImpl, |
Brian Salomon | f95940b | 2021-08-09 15:56:24 -0400 | [diff] [blame] | 41 | std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fpImpls) |
Greg Daniel | 3ef052c | 2021-01-05 12:20:27 -0500 | [diff] [blame] | 42 | : fPipeline(std::move(pipeline)) |
Brian Salomon | 4d3f517 | 2018-06-07 14:42:52 -0400 | [diff] [blame] | 43 | , fSamplerDSHandle(samplerDSHandle) |
Brian Salomon | 4d3f517 | 2018-06-07 14:42:52 -0400 | [diff] [blame] | 44 | , fBuiltinUniformHandles(builtinUniformHandles) |
Brian Salomon | f95940b | 2021-08-09 15:56:24 -0400 | [diff] [blame] | 45 | , fGPImpl(std::move(gpImpl)) |
Brian Salomon | d89d445 | 2021-08-09 16:42:36 -0400 | [diff] [blame] | 46 | , fXPImpl(std::move(xpImpl)) |
Brian Salomon | 17f95b1 | 2021-02-23 09:35:08 -0500 | [diff] [blame] | 47 | , fFPImpls(std::move(fpImpls)) |
Jim Van Verth | 14a9b08 | 2021-09-20 14:09:52 +0000 | [diff] [blame] | 48 | , fDataManager(uniforms, uniformSize, usePushConstants) { |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 49 | fNumSamplers = samplers.count(); |
Michael Ludwig | 4519134 | 2020-03-24 12:29:39 -0400 | [diff] [blame] | 50 | for (const auto& sampler : samplers.items()) { |
Greg Daniel | 20bb83f | 2021-03-18 13:06:00 -0400 | [diff] [blame] | 51 | // We store the immutable samplers here and take a ref on the sampler. Once we switch to |
| 52 | // using sk_sps here we should just move the immutable samplers to save the extra ref/unref. |
| 53 | if (sampler.fImmutableSampler) { |
| 54 | sampler.fImmutableSampler->ref(); |
| 55 | } |
Michael Ludwig | 4519134 | 2020-03-24 12:29:39 -0400 | [diff] [blame] | 56 | fImmutableSamplers.push_back(sampler.fImmutableSampler); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 57 | } |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 58 | } |
| 59 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 60 | GrVkPipelineState::~GrVkPipelineState() { |
Ethan Nicholas | 87f340e | 2017-01-03 14:32:01 -0500 | [diff] [blame] | 61 | // Must have freed all GPU resources before this is destroyed |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 62 | SkASSERT(!fPipeline); |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Greg Daniel | 9d02a4c | 2020-07-15 14:26:08 -0400 | [diff] [blame] | 65 | void GrVkPipelineState::freeGPUResources(GrVkGpu* gpu) { |
Greg Daniel | 3ef052c | 2021-01-05 12:20:27 -0500 | [diff] [blame] | 66 | fPipeline.reset(); |
Greg Daniel | 8eb119a | 2021-02-04 09:41:19 -0500 | [diff] [blame] | 67 | fDataManager.releaseData(); |
Greg Daniel | 20bb83f | 2021-03-18 13:06:00 -0400 | [diff] [blame] | 68 | for (int i = 0; i < fImmutableSamplers.count(); ++i) { |
| 69 | if (fImmutableSamplers[i]) { |
| 70 | fImmutableSamplers[i]->unref(); |
| 71 | fImmutableSamplers[i] = nullptr; |
| 72 | } |
| 73 | } |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Greg Daniel | 95f0b16 | 2019-11-11 13:42:30 -0500 | [diff] [blame] | 76 | bool GrVkPipelineState::setAndBindUniforms(GrVkGpu* gpu, |
Greg Daniel | a36cb40 | 2021-04-20 12:42:11 -0400 | [diff] [blame] | 77 | SkISize colorAttachmentDimensions, |
Robert Phillips | 835cbda | 2019-10-09 15:41:50 -0400 | [diff] [blame] | 78 | const GrProgramInfo& programInfo, |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 79 | GrVkCommandBuffer* commandBuffer) { |
Greg Daniel | a36cb40 | 2021-04-20 12:42:11 -0400 | [diff] [blame] | 80 | this->setRenderTargetState(colorAttachmentDimensions, programInfo.origin()); |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 81 | |
Brian Salomon | f95940b | 2021-08-09 15:56:24 -0400 | [diff] [blame] | 82 | fGPImpl->setData(fDataManager, *gpu->caps()->shaderCaps(), programInfo.geomProc()); |
Brian Salomon | 9139803 | 2021-08-05 10:02:08 -0400 | [diff] [blame] | 83 | |
Brian Salomon | 61a70fb | 2020-07-08 19:02:54 -0400 | [diff] [blame] | 84 | for (int i = 0; i < programInfo.pipeline().numFragmentProcessors(); ++i) { |
Brian Salomon | 9139803 | 2021-08-05 10:02:08 -0400 | [diff] [blame] | 85 | const auto& fp = programInfo.pipeline().getFragmentProcessor(i); |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 86 | fp.visitWithImpls([&](const GrFragmentProcessor& fp, |
| 87 | GrFragmentProcessor::ProgramImpl& impl) { |
Brian Salomon | 17f95b1 | 2021-02-23 09:35:08 -0500 | [diff] [blame] | 88 | impl.setData(fDataManager, fp); |
Brian Salomon | 9139803 | 2021-08-05 10:02:08 -0400 | [diff] [blame] | 89 | }, *fFPImpls[i]); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 90 | } |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 91 | |
John Stiles | 010d088 | 2021-06-03 20:28:41 -0400 | [diff] [blame] | 92 | programInfo.pipeline().setDstTextureUniforms(fDataManager, &fBuiltinUniformHandles); |
Brian Salomon | d89d445 | 2021-08-09 16:42:36 -0400 | [diff] [blame] | 93 | fXPImpl->setData(fDataManager, programInfo.pipeline().getXferProcessor()); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 94 | |
Jim Van Verth | 205e99a | 2021-02-08 18:02:41 -0500 | [diff] [blame] | 95 | // Upload uniform data and bind descriptor set. |
| 96 | auto [uniformBuffer, success] = fDataManager.uploadUniforms(gpu, fPipeline->layout(), |
| 97 | commandBuffer); |
Greg Daniel | 8eb119a | 2021-02-04 09:41:19 -0500 | [diff] [blame] | 98 | if (!success) { |
| 99 | return false; |
| 100 | } |
| 101 | if (uniformBuffer) { |
Greg Daniel | af1d193 | 2021-02-08 13:55:26 -0500 | [diff] [blame] | 102 | const GrVkBuffer* vkBuffer = static_cast<GrVkBuffer*>(uniformBuffer.get()); |
Greg Daniel | c10bb6a | 2019-10-29 09:50:32 -0400 | [diff] [blame] | 103 | static const int kUniformDSIdx = GrVkUniformHandler::kUniformBufferDescSet; |
Greg Daniel | 1cf4bc7 | 2020-11-24 10:41:04 -0500 | [diff] [blame] | 104 | commandBuffer->bindDescriptorSets(gpu, fPipeline->layout(), kUniformDSIdx, /*setCount=*/1, |
Greg Daniel | 8eb119a | 2021-02-04 09:41:19 -0500 | [diff] [blame] | 105 | vkBuffer->uniformDescriptorSet(), |
| 106 | /*dynamicOffsetCount=*/0, /*dynamicOffsets=*/nullptr); |
| 107 | commandBuffer->addGrBuffer(std::move(uniformBuffer)); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 108 | } |
Greg Daniel | 95f0b16 | 2019-11-11 13:42:30 -0500 | [diff] [blame] | 109 | return true; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Greg Daniel | 95f0b16 | 2019-11-11 13:42:30 -0500 | [diff] [blame] | 112 | bool GrVkPipelineState::setAndBindTextures(GrVkGpu* gpu, |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 113 | const GrGeometryProcessor& geomProc, |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 114 | const GrPipeline& pipeline, |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 115 | const GrSurfaceProxy* const geomProcTextures[], |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 116 | GrVkCommandBuffer* commandBuffer) { |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 117 | SkASSERT(geomProcTextures || !geomProc.numTextureSamplers()); |
Greg Daniel | 4a58bde | 2021-05-06 11:49:13 -0400 | [diff] [blame] | 118 | if (!fNumSamplers) { |
| 119 | return true; |
egdaniel | b4aa362 | 2016-04-06 13:47:08 -0700 | [diff] [blame] | 120 | } |
Greg Daniel | 4a58bde | 2021-05-06 11:49:13 -0400 | [diff] [blame] | 121 | struct SamplerBindings { |
| 122 | GrSamplerState fState; |
| 123 | GrVkTexture* fTexture; |
| 124 | }; |
| 125 | SkAutoSTArray<8, SamplerBindings> samplerBindings(fNumSamplers); |
| 126 | int currTextureBinding = 0; |
| 127 | |
| 128 | for (int i = 0; i < geomProc.numTextureSamplers(); ++i) { |
| 129 | SkASSERT(geomProcTextures[i]->asTextureProxy()); |
| 130 | const auto& sampler = geomProc.textureSampler(i); |
| 131 | auto texture = static_cast<GrVkTexture*>(geomProcTextures[i]->peekTexture()); |
| 132 | samplerBindings[currTextureBinding++] = {sampler.samplerState(), texture}; |
| 133 | } |
| 134 | |
Greg Daniel | 4a58bde | 2021-05-06 11:49:13 -0400 | [diff] [blame] | 135 | |
| 136 | if (GrTexture* dstTexture = pipeline.peekDstTexture()) { |
| 137 | samplerBindings[currTextureBinding++] = {GrSamplerState::Filter::kNearest, |
| 138 | static_cast<GrVkTexture*>(dstTexture)}; |
| 139 | } |
| 140 | |
John Stiles | 03e7830 | 2021-06-02 17:34:21 -0400 | [diff] [blame] | 141 | pipeline.visitTextureEffects([&](const GrTextureEffect& te) { |
| 142 | GrSamplerState samplerState = te.samplerState(); |
| 143 | auto* texture = static_cast<GrVkTexture*>(te.texture()); |
| 144 | samplerBindings[currTextureBinding++] = {samplerState, texture}; |
| 145 | }); |
| 146 | |
Greg Daniel | 4a58bde | 2021-05-06 11:49:13 -0400 | [diff] [blame] | 147 | // Get new descriptor set |
| 148 | SkASSERT(fNumSamplers == currTextureBinding); |
| 149 | static const int kSamplerDSIdx = GrVkUniformHandler::kSamplerDescSet; |
| 150 | |
| 151 | if (fNumSamplers == 1) { |
| 152 | auto texture = samplerBindings[0].fTexture; |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame] | 153 | auto texAttachment = texture->textureImage(); |
Greg Daniel | 4a58bde | 2021-05-06 11:49:13 -0400 | [diff] [blame] | 154 | const auto& samplerState = samplerBindings[0].fState; |
| 155 | const GrVkDescriptorSet* descriptorSet = texture->cachedSingleDescSet(samplerState); |
| 156 | if (descriptorSet) { |
| 157 | commandBuffer->addGrSurface(sk_ref_sp<const GrSurface>(texture)); |
| 158 | commandBuffer->addResource(texAttachment->textureView()); |
| 159 | commandBuffer->addResource(texAttachment->resource()); |
| 160 | commandBuffer->addRecycledResource(descriptorSet); |
| 161 | commandBuffer->bindDescriptorSets(gpu, fPipeline->layout(), kSamplerDSIdx, |
| 162 | /*setCount=*/1, descriptorSet->descriptorSet(), |
| 163 | /*dynamicOffsetCount=*/0, |
| 164 | /*dynamicOffsets=*/nullptr); |
| 165 | return true; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | const GrVkDescriptorSet* descriptorSet = |
| 170 | gpu->resourceProvider().getSamplerDescriptorSet(fSamplerDSHandle); |
| 171 | if (!descriptorSet) { |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | for (int i = 0; i < fNumSamplers; ++i) { |
| 176 | GrSamplerState state = samplerBindings[i].fState; |
| 177 | GrVkTexture* texture = samplerBindings[i].fTexture; |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame] | 178 | auto texAttachment = texture->textureImage(); |
Greg Daniel | 4a58bde | 2021-05-06 11:49:13 -0400 | [diff] [blame] | 179 | |
| 180 | const GrVkImageView* textureView = texAttachment->textureView(); |
| 181 | const GrVkSampler* sampler = nullptr; |
| 182 | if (fImmutableSamplers[i]) { |
| 183 | sampler = fImmutableSamplers[i]; |
| 184 | } else { |
| 185 | sampler = gpu->resourceProvider().findOrCreateCompatibleSampler( |
| 186 | state, texAttachment->ycbcrConversionInfo()); |
| 187 | if (!sampler) { |
| 188 | descriptorSet->recycle(); |
| 189 | return false; |
| 190 | } |
| 191 | } |
| 192 | SkASSERT(sampler); |
| 193 | |
| 194 | VkDescriptorImageInfo imageInfo; |
| 195 | memset(&imageInfo, 0, sizeof(VkDescriptorImageInfo)); |
| 196 | imageInfo.sampler = fImmutableSamplers[i] ? VK_NULL_HANDLE : sampler->sampler(); |
| 197 | imageInfo.imageView = textureView->imageView(); |
| 198 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 199 | |
| 200 | VkWriteDescriptorSet writeInfo; |
| 201 | memset(&writeInfo, 0, sizeof(VkWriteDescriptorSet)); |
| 202 | writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 203 | writeInfo.pNext = nullptr; |
| 204 | writeInfo.dstSet = *descriptorSet->descriptorSet(); |
| 205 | writeInfo.dstBinding = i; |
| 206 | writeInfo.dstArrayElement = 0; |
| 207 | writeInfo.descriptorCount = 1; |
| 208 | writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 209 | writeInfo.pImageInfo = &imageInfo; |
| 210 | writeInfo.pBufferInfo = nullptr; |
| 211 | writeInfo.pTexelBufferView = nullptr; |
| 212 | |
| 213 | GR_VK_CALL(gpu->vkInterface(), |
| 214 | UpdateDescriptorSets(gpu->device(), 1, &writeInfo, 0, nullptr)); |
| 215 | commandBuffer->addResource(sampler); |
| 216 | if (!fImmutableSamplers[i]) { |
| 217 | sampler->unref(); |
| 218 | } |
| 219 | commandBuffer->addResource(textureView); |
| 220 | commandBuffer->addResource(texAttachment->resource()); |
| 221 | } |
| 222 | if (fNumSamplers == 1) { |
| 223 | GrSamplerState state = samplerBindings[0].fState; |
| 224 | GrVkTexture* texture = samplerBindings[0].fTexture; |
| 225 | texture->addDescriptorSetToCache(descriptorSet, state); |
| 226 | } |
| 227 | |
| 228 | commandBuffer->bindDescriptorSets(gpu, fPipeline->layout(), kSamplerDSIdx, /*setCount=*/1, |
| 229 | descriptorSet->descriptorSet(), |
| 230 | /*dynamicOffsetCount=*/0, /*dynamicOffsets=*/nullptr); |
| 231 | commandBuffer->addRecycledResource(descriptorSet); |
| 232 | descriptorSet->recycle(); |
Greg Daniel | 95f0b16 | 2019-11-11 13:42:30 -0500 | [diff] [blame] | 233 | return true; |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Greg Daniel | 37fd658 | 2020-09-14 12:36:09 -0400 | [diff] [blame] | 236 | bool GrVkPipelineState::setAndBindInputAttachment(GrVkGpu* gpu, |
Greg Daniel | 1034425 | 2021-04-22 09:52:25 -0400 | [diff] [blame] | 237 | gr_rp<const GrVkDescriptorSet> inputDescSet, |
Greg Daniel | 37fd658 | 2020-09-14 12:36:09 -0400 | [diff] [blame] | 238 | GrVkCommandBuffer* commandBuffer) { |
Greg Daniel | 1034425 | 2021-04-22 09:52:25 -0400 | [diff] [blame] | 239 | SkASSERT(inputDescSet); |
Greg Daniel | 1cf4bc7 | 2020-11-24 10:41:04 -0500 | [diff] [blame] | 240 | commandBuffer->bindDescriptorSets(gpu, fPipeline->layout(), GrVkUniformHandler::kInputDescSet, |
Greg Daniel | 1034425 | 2021-04-22 09:52:25 -0400 | [diff] [blame] | 241 | /*setCount=*/1, inputDescSet->descriptorSet(), |
Greg Daniel | 8cc5f19 | 2020-10-02 10:45:43 -0400 | [diff] [blame] | 242 | /*dynamicOffsetCount=*/0, /*dynamicOffsets=*/nullptr); |
| 243 | // We don't add the input resource to the command buffer to track since the input will be |
| 244 | // the same as the color attachment which is already tracked on the command buffer. |
Greg Daniel | 1034425 | 2021-04-22 09:52:25 -0400 | [diff] [blame] | 245 | commandBuffer->addRecycledResource(std::move(inputDescSet)); |
Greg Daniel | 37fd658 | 2020-09-14 12:36:09 -0400 | [diff] [blame] | 246 | return true; |
| 247 | } |
| 248 | |
Greg Daniel | a36cb40 | 2021-04-20 12:42:11 -0400 | [diff] [blame] | 249 | void GrVkPipelineState::setRenderTargetState(SkISize colorAttachmentDimensions, |
| 250 | GrSurfaceOrigin origin) { |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 251 | // Set RT adjustment and RT flip |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 252 | SkASSERT(fBuiltinUniformHandles.fRTAdjustmentUni.isValid()); |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 253 | if (fRenderTargetState.fRenderTargetOrigin != origin || |
Greg Daniel | a36cb40 | 2021-04-20 12:42:11 -0400 | [diff] [blame] | 254 | fRenderTargetState.fRenderTargetSize != colorAttachmentDimensions) { |
| 255 | fRenderTargetState.fRenderTargetSize = colorAttachmentDimensions; |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 256 | fRenderTargetState.fRenderTargetOrigin = origin; |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 257 | |
Brian Salomon | 3e2fe2b | 2021-06-02 09:16:30 -0400 | [diff] [blame] | 258 | // The client will mark a swap buffer as kTopLeft when making a SkSurface because |
| 259 | // Vulkan's framebuffer space has (0, 0) at the top left. This agrees with Skia's device |
| 260 | // coords and with Vulkan's NDC that has (-1, -1) in the top left. So a flip is needed when |
| 261 | // surface origin is kBottomLeft rather than kTopLeft. |
| 262 | bool flip = (origin == kBottomLeft_GrSurfaceOrigin); |
| 263 | std::array<float, 4> v = SkSL::Compiler::GetRTAdjustVector(colorAttachmentDimensions, flip); |
| 264 | fDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, v.data()); |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 265 | if (fBuiltinUniformHandles.fRTFlipUni.isValid()) { |
| 266 | std::array<float, 2> d = |
| 267 | SkSL::Compiler::GetRTFlipVector(colorAttachmentDimensions.height(), flip); |
| 268 | fDataManager.set2fv(fBuiltinUniformHandles.fRTFlipUni, 1, d.data()); |
| 269 | } |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 273 | void GrVkPipelineState::bindPipeline(const GrVkGpu* gpu, GrVkCommandBuffer* commandBuffer) { |
jvanverth | 992ad36 | 2016-02-26 09:21:02 -0800 | [diff] [blame] | 274 | commandBuffer->bindPipeline(gpu, fPipeline); |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 275 | } |