在结构中使用 Vulkan 唯一句柄会导致 "implicitly deleted" 错误
Using Vulkan unique handle in struct leads to "implicitly deleted" error
我的代码中有这个:
struct Buffer
{
vk::UniqueBuffer buffer;
vk::UniqueDeviceMemory memory;
unsigned int top{0};
};
struct Image
{
vk::UniqueImage textureImage;
vk::UniqueDeviceMemory textureImageMemory;
};
struct Texture
{
Image image;
vk::UniqueImageView imageView;
vk::UniqueSampler sampler;
};
struct SwapChainFrame
{
vk::Image image;
vk::UniqueImageView imageView;
vk::UniqueFramebuffer frameBuffer;
vk::UniqueCommandBuffer commandBuffer;
Buffer uniformVpMatrix;
vk::UniqueDescriptorSet descriptorSet;
};
在 Vulkan 中存储独特的句柄效果很好,直到我添加了图像和纹理句柄。现在我明白了:
In file included from .../gpuVulkan.h:50:16: note: ‘GpuVulkan::Texture::Texture(const GpuVulkan::Texture&)’ is implicitly deleted because the default definition would be ill-formed:
struct Texture
^~~~~~~
.../gpuVulkan.h:50:16: error: use of deleted function ‘GpuVulkan::Image::Image(const GpuVulkan::Image&)’
.../gpuVulkan.h:44:16: note: ‘GpuVulkan::Image::Image(const GpuVulkan::Image&)’ is implicitly deleted because the default definition would be ill-formed:
struct Image
^~~~~
.../gpuVulkan.h:44:16: error: use of deleted function ‘vk::UniqueHandle<Type, Dispatch>::UniqueHandle(const vk::UniqueHandle<Type, Dispatch>&) [with Type = vk::Image; Dispatch = vk::DispatchLoaderStatic]’
In file included from .../gpuVulkan.h:1,
from .../src/gpuVulkan.cpp:5:
/usr/include/vulkan/vulkan.hpp:392:5: note: declared here
UniqueHandle( UniqueHandle const& ) = delete;
^~~~~~~~~~~~
In file included from ...gpuVulkan.cpp:5:
.../gpuVulkan.h:44:16: error: use of deleted function ‘vk::UniqueHandle<Type, Dispatch>::UniqueHandle(const vk::UniqueHandle<Type, Dispatch>&) [with Type = vk::DeviceMemory; Dispatch = vk::DispatchLoaderStatic]’
struct Image
有什么问题吗? Buffer 和 SwapChainFrame 运行良好。似乎报告了类似的问题 here,但我不确定这是否是同一个问题。任何帮助将非常感激!谢谢
您的 Image
class 没有复制构造函数(因为 vk::UniqueImage
没有复制构造函数)。这意味着 Texture
也没有复制构造函数。
其他 classes 也没有复制构造函数,但没关系,除非您尝试复制它们。 (在这种情况下,通过创建 std::vector<Texture>
,从评论中获取。)
我的代码中有这个:
struct Buffer
{
vk::UniqueBuffer buffer;
vk::UniqueDeviceMemory memory;
unsigned int top{0};
};
struct Image
{
vk::UniqueImage textureImage;
vk::UniqueDeviceMemory textureImageMemory;
};
struct Texture
{
Image image;
vk::UniqueImageView imageView;
vk::UniqueSampler sampler;
};
struct SwapChainFrame
{
vk::Image image;
vk::UniqueImageView imageView;
vk::UniqueFramebuffer frameBuffer;
vk::UniqueCommandBuffer commandBuffer;
Buffer uniformVpMatrix;
vk::UniqueDescriptorSet descriptorSet;
};
在 Vulkan 中存储独特的句柄效果很好,直到我添加了图像和纹理句柄。现在我明白了:
In file included from .../gpuVulkan.h:50:16: note: ‘GpuVulkan::Texture::Texture(const GpuVulkan::Texture&)’ is implicitly deleted because the default definition would be ill-formed:
struct Texture
^~~~~~~
.../gpuVulkan.h:50:16: error: use of deleted function ‘GpuVulkan::Image::Image(const GpuVulkan::Image&)’
.../gpuVulkan.h:44:16: note: ‘GpuVulkan::Image::Image(const GpuVulkan::Image&)’ is implicitly deleted because the default definition would be ill-formed:
struct Image
^~~~~
.../gpuVulkan.h:44:16: error: use of deleted function ‘vk::UniqueHandle<Type, Dispatch>::UniqueHandle(const vk::UniqueHandle<Type, Dispatch>&) [with Type = vk::Image; Dispatch = vk::DispatchLoaderStatic]’
In file included from .../gpuVulkan.h:1,
from .../src/gpuVulkan.cpp:5:
/usr/include/vulkan/vulkan.hpp:392:5: note: declared here
UniqueHandle( UniqueHandle const& ) = delete;
^~~~~~~~~~~~
In file included from ...gpuVulkan.cpp:5:
.../gpuVulkan.h:44:16: error: use of deleted function ‘vk::UniqueHandle<Type, Dispatch>::UniqueHandle(const vk::UniqueHandle<Type, Dispatch>&) [with Type = vk::DeviceMemory; Dispatch = vk::DispatchLoaderStatic]’
struct Image
有什么问题吗? Buffer 和 SwapChainFrame 运行良好。似乎报告了类似的问题 here,但我不确定这是否是同一个问题。任何帮助将非常感激!谢谢
您的 Image
class 没有复制构造函数(因为 vk::UniqueImage
没有复制构造函数)。这意味着 Texture
也没有复制构造函数。
其他 classes 也没有复制构造函数,但没关系,除非您尝试复制它们。 (在这种情况下,通过创建 std::vector<Texture>
,从评论中获取。)