| 225 | } |
| 226 | |
| 227 | void |
| 228 | Algorithm::createPipeline() |
| 229 | { |
| 230 | KP_LOG_DEBUG("Kompute Algorithm calling create Pipeline"); |
| 231 | |
| 232 | vk::PipelineLayoutCreateInfo pipelineLayoutInfo( |
| 233 | vk::PipelineLayoutCreateFlags(), |
| 234 | 1, // Set layout count |
| 235 | this->mDescriptorSetLayout.get()); |
| 236 | |
| 237 | vk::PushConstantRange pushConstantRange; |
| 238 | if (this->mPushConstantsSize) { |
| 239 | pushConstantRange.setStageFlags(vk::ShaderStageFlagBits::eCompute); |
| 240 | pushConstantRange.setOffset(0); |
| 241 | pushConstantRange.setSize(this->mPushConstantsDataTypeMemorySize * |
| 242 | this->mPushConstantsSize); |
| 243 | |
| 244 | pipelineLayoutInfo.setPushConstantRangeCount(1); |
| 245 | pipelineLayoutInfo.setPPushConstantRanges(&pushConstantRange); |
| 246 | } |
| 247 | |
| 248 | this->mPipelineLayout = std::make_shared<vk::PipelineLayout>(); |
| 249 | this->mDevice->createPipelineLayout( |
| 250 | &pipelineLayoutInfo, nullptr, this->mPipelineLayout.get()); |
| 251 | this->mFreePipelineLayout = true; |
| 252 | |
| 253 | std::vector<vk::SpecializationMapEntry> specializationEntries; |
| 254 | |
| 255 | for (uint32_t i = 0; i < this->mSpecializationConstantsSize; i++) { |
| 256 | vk::SpecializationMapEntry specializationEntry( |
| 257 | static_cast<uint32_t>(i), |
| 258 | static_cast<uint32_t>( |
| 259 | this->mSpecializationConstantsDataTypeMemorySize * i), |
| 260 | this->mSpecializationConstantsDataTypeMemorySize); |
| 261 | |
| 262 | specializationEntries.push_back(specializationEntry); |
| 263 | } |
| 264 | |
| 265 | // This passes ownership of the memory so we remove ownership from |
| 266 | // specialization container by using "transferDataOwnership" |
| 267 | vk::SpecializationInfo specializationInfo( |
| 268 | static_cast<uint32_t>(specializationEntries.size()), |
| 269 | specializationEntries.data(), |
| 270 | this->mSpecializationConstantsDataTypeMemorySize * |
| 271 | this->mSpecializationConstantsSize, |
| 272 | this->mSpecializationConstantsData); |
| 273 | |
| 274 | vk::PipelineShaderStageCreateInfo shaderStage( |
| 275 | vk::PipelineShaderStageCreateFlags(), |
| 276 | vk::ShaderStageFlagBits::eCompute, |
| 277 | *this->mShaderModule, |
| 278 | "main", |
| 279 | &specializationInfo); |
| 280 | |
| 281 | vk::ComputePipelineCreateInfo pipelineInfo(vk::PipelineCreateFlags(), |
| 282 | shaderStage, |
| 283 | *this->mPipelineLayout, |
| 284 | vk::Pipeline(), |