载入中...
搜索中...
未找到
ComputePass.cpp
浏览该文件的文档.
2
3namespace eve::graphics::vulkan {
4
6 if (this != &o) {
7 if (device_ && pipeline_) device_->instance.destroyPipeline(pipeline_);
8 device_ = o.device_;
9 pipeline_ = o.pipeline_;
10 o.device_ = nullptr;
11 o.pipeline_ = nullptr;
12 }
13 return *this;
14}
15
17 if (device_ && pipeline_) device_->instance.destroyPipeline(pipeline_);
18}
19
20bool ComputePass::create(vkb::Device &device, vk::PipelineLayout layout,
21 const std::vector<uint32_t> &spv) {
22 if (spv.empty() || !layout) return false;
23 if (pipeline_) {
24 device.instance.destroyPipeline(pipeline_);
25 pipeline_ = nullptr;
26 }
27
28 vk::ShaderModuleCreateInfo moduleInfo{};
29 moduleInfo.codeSize = spv.size() * sizeof(uint32_t);
30 moduleInfo.pCode = spv.data();
31 vk::ShaderModule module = device.instance.createShaderModule(moduleInfo);
32
33 // The vendored vulkan.hpp strips the vk::Device::createComputePipeline
34 // wrapper; call the core C entry point directly (same ABI).
35 VkComputePipelineCreateInfo info{};
36 info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
37 info.stage = VkPipelineShaderStageCreateInfo{
38 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
39 VK_SHADER_STAGE_COMPUTE_BIT, static_cast<VkShaderModule>(module), "main", nullptr};
40 info.layout = static_cast<VkPipelineLayout>(layout);
41 VkPipeline created = VK_NULL_HANDLE;
42 const VkResult r =
43 vkCreateComputePipelines(static_cast<VkDevice>(device.instance), VK_NULL_HANDLE, 1, &info,
44 nullptr, &created);
45 device.instance.destroyShaderModule(module);
46 if (r != VK_SUCCESS || !created) return false;
47
48 device_ = &device;
49 pipeline_ = created;
50 return true;
51}
52
53void ComputePass::record(vk::CommandBuffer cb, uint32_t groupsX, uint32_t groupsY,
54 uint32_t groupsZ) const {
55 if (!pipeline_) return;
56 cb.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline_);
57 cb.dispatch(groupsX, groupsY, groupsZ);
58}
59
60} // namespace eve::graphics::vulkan
std::string layout
vkb::Device & device
Minimal compute pipeline wrapper for in-frame compute sections.
Definition ComputePass.h:17
bool create(vkb::Device &device, vk::PipelineLayout layout, const std::vector< uint32_t > &spv)
Create from embedded SPIR-V words; layout must outlive the pass.
ComputePass & operator=(const ComputePass &)=delete
void record(vk::CommandBuffer cb, uint32_t groupsX, uint32_t groupsY=1, uint32_t groupsZ=1) const
Record one dispatch (local size baked into the shader).