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 "vk/GrVkPipelineStateBuilder.h" | 8 #include "vk/GrVkPipelineStateBuilder.h" |
9 | 9 |
10 #include "vk/GrVkGpu.h" | 10 #include "vk/GrVkGpu.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 GrVkPipelineState* GrVkPipelineStateBuilder::finalize(GrPrimitiveType primitiveT
ype, | 157 GrVkPipelineState* GrVkPipelineStateBuilder::finalize(GrPrimitiveType primitiveT
ype, |
158 const GrVkRenderPass& rend
erPass, | 158 const GrVkRenderPass& rend
erPass, |
159 const GrVkPipelineState::D
esc& desc) { | 159 const GrVkPipelineState::D
esc& desc) { |
160 VkDescriptorSetLayout dsLayout[2]; | 160 VkDescriptorSetLayout dsLayout[2]; |
161 VkPipelineLayout pipelineLayout; | 161 VkPipelineLayout pipelineLayout; |
162 VkShaderModule vertShaderModule; | 162 VkShaderModule vertShaderModule; |
163 VkShaderModule fragShaderModule; | 163 VkShaderModule fragShaderModule; |
164 | 164 |
165 uint32_t numSamplers = fSamplerUniforms.count(); | 165 uint32_t numSamplers = (uint32_t)fUniformHandler.numSamplers(); |
166 | 166 |
167 SkAutoTDeleteArray<VkDescriptorSetLayoutBinding> dsSamplerBindings( | 167 SkAutoTDeleteArray<VkDescriptorSetLayoutBinding> dsSamplerBindings( |
168 new VkDescriptorSetLayoutBi
nding[numSamplers]); | 168 new VkDescriptorSetLayoutBi
nding[numSamplers]); |
169 for (uint32_t i = 0; i < numSamplers; ++i) { | 169 for (uint32_t i = 0; i < numSamplers; ++i) { |
170 UniformHandle uniHandle = fSamplerUniforms[i]; | 170 const GrVkGLSLSampler& sampler = |
171 GrVkUniformHandler::UniformInfo uniformInfo = fUniformHandler.getUniform
Info(uniHandle); | 171 static_cast<const GrVkGLSLSampler&>(fUniformHandler.getSampler(i)); |
172 SkASSERT(kSampler2D_GrSLType == uniformInfo.fVariable.getType()); | 172 SkASSERT(sampler.binding() == i); |
173 SkASSERT(GrVkUniformHandler::kSamplerDescSet == uniformInfo.fSetNumber); | 173 dsSamplerBindings[i].binding = sampler.binding(); |
174 SkASSERT(uniformInfo.fBinding == i); | |
175 dsSamplerBindings[i].binding = uniformInfo.fBinding; | |
176 dsSamplerBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_
SAMPLER; | 174 dsSamplerBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_
SAMPLER; |
177 dsSamplerBindings[i].descriptorCount = 1; | 175 dsSamplerBindings[i].descriptorCount = 1; |
178 dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(uniformIn
fo.fVisibility); | 176 dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(sampler.v
isibility()); |
179 dsSamplerBindings[i].pImmutableSamplers = nullptr; | 177 dsSamplerBindings[i].pImmutableSamplers = nullptr; |
180 } | 178 } |
181 | 179 |
182 VkDescriptorSetLayoutCreateInfo dsSamplerLayoutCreateInfo; | 180 VkDescriptorSetLayoutCreateInfo dsSamplerLayoutCreateInfo; |
183 memset(&dsSamplerLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo
)); | 181 memset(&dsSamplerLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo
)); |
184 dsSamplerLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CR
EATE_INFO; | 182 dsSamplerLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CR
EATE_INFO; |
185 dsSamplerLayoutCreateInfo.pNext = nullptr; | 183 dsSamplerLayoutCreateInfo.pNext = nullptr; |
186 dsSamplerLayoutCreateInfo.flags = 0; | 184 dsSamplerLayoutCreateInfo.flags = 0; |
187 dsSamplerLayoutCreateInfo.bindingCount = fSamplerUniforms.count(); | 185 dsSamplerLayoutCreateInfo.bindingCount = numSamplers; |
188 // Setting to nullptr fixes an error in the param checker validation layer.
Even though | 186 // Setting to nullptr fixes an error in the param checker validation layer.
Even though |
189 // bindingCount is 0 (which is valid), it still tries to validate pBindings
unless it is null. | 187 // bindingCount is 0 (which is valid), it still tries to validate pBindings
unless it is null. |
190 dsSamplerLayoutCreateInfo.pBindings = fSamplerUniforms.count() ? dsSamplerBi
ndings.get() : | 188 dsSamplerLayoutCreateInfo.pBindings = numSamplers ? dsSamplerBindings.get()
: nullptr; |
191 nullptr; | |
192 | 189 |
193 GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), | 190 GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), |
194 CreateDescriptorSetLayout(fGpu->device(), | 191 CreateDescriptorSetLayout(fGpu->device(), |
195 &dsSamplerLayoutCreateInfo, | 192 &dsSamplerLayoutCreateInfo, |
196 nullptr, | 193 nullptr, |
197 &dsLayout[GrVkUniformHandler::
kSamplerDescSet])); | 194 &dsLayout[GrVkUniformHandler::
kSamplerDescSet])); |
198 | 195 |
199 // Create Uniform Buffer Descriptor | 196 // Create Uniform Buffer Descriptor |
200 // We always attach uniform buffers to descriptor set 1. The vertex uniform
buffer will have | 197 // We always attach uniform buffers to descriptor set 1. The vertex uniform
buffer will have |
201 // binding 0 and the fragment binding 1. | 198 // binding 0 and the fragment binding 1. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 dsLayout, | 292 dsLayout, |
296 fUniformHandles, | 293 fUniformHandles, |
297 fUniformHandler.fUniforms, | 294 fUniformHandler.fUniforms, |
298 fUniformHandler.fCurrentVertexUBOOffset, | 295 fUniformHandler.fCurrentVertexUBOOffset, |
299 fUniformHandler.fCurrentFragmentUBOOffset, | 296 fUniformHandler.fCurrentFragmentUBOOffset, |
300 numSamplers, | 297 numSamplers, |
301 fGeometryProcessor, | 298 fGeometryProcessor, |
302 fXferProcessor, | 299 fXferProcessor, |
303 fFragmentProcessors); | 300 fFragmentProcessors); |
304 } | 301 } |
OLD | NEW |