Skip to content

Commit 47d9b80

Browse files
authored
Unify vkb::Device and vkb::core::HPPDevice into vkb::core::Device<bindingType> (KhronosGroup#1364)
* Unify vkb::Device and vkb::core::HPPDevice into vkb::core::Device<bindingType> * Rebasing from main
1 parent ff4cc28 commit 47d9b80

File tree

161 files changed

+1645
-1960
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+1645
-1960
lines changed

framework/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ set(CORE_FILES
251251
core/hpp_descriptor_pool.h
252252
core/hpp_descriptor_set.h
253253
core/hpp_descriptor_set_layout.h
254-
core/hpp_device.h
255254
core/hpp_framebuffer.h
256255
core/hpp_image.h
257256
core/hpp_image_view.h
@@ -270,7 +269,6 @@ set(CORE_FILES
270269
core/command_pool_base.cpp
271270
core/instance.cpp
272271
core/physical_device.cpp
273-
core/device.cpp
274272
core/debug.cpp
275273
core/image_core.cpp
276274
core/shader_module.cpp
@@ -292,7 +290,6 @@ set(CORE_FILES
292290
core/query_pool.cpp
293291
core/acceleration_structure.cpp
294292
core/hpp_debug.cpp
295-
core/hpp_device.cpp
296293
core/hpp_image_core.cpp
297294
core/hpp_image_view.cpp
298295
core/hpp_instance.cpp

framework/api_vulkan_sample.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool ApiVulkanSample::prepare(const vkb::ApplicationOptions &options)
5555
submit_info.signalSemaphoreCount = 1;
5656
submit_info.pSignalSemaphores = &semaphores.render_complete;
5757

58-
queue = get_device().get_suitable_graphics_queue().get_handle();
58+
queue = get_device().get_queue_by_flags(VK_QUEUE_GRAPHICS_BIT, 0).get_handle();
5959

6060
create_swapchain_buffers();
6161
create_command_pool();
@@ -529,7 +529,7 @@ void ApiVulkanSample::submit_frame()
529529
present_info.pImageIndices = &current_buffer;
530530

531531
VkDisplayPresentInfoKHR disp_present_info{};
532-
if (get_device().is_extension_supported(VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME) &&
532+
if (get_device().get_gpu().is_extension_supported(VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME) &&
533533
window->get_display_present_info(&disp_present_info, width, height))
534534
{
535535
// Add display present info if supported and wanted
@@ -664,7 +664,7 @@ void ApiVulkanSample::setup_depth_stencil()
664664
VkMemoryAllocateInfo memory_allocation{};
665665
memory_allocation.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
666666
memory_allocation.allocationSize = memReqs.size;
667-
memory_allocation.memoryTypeIndex = get_device().get_memory_type(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
667+
memory_allocation.memoryTypeIndex = get_device().get_gpu().get_memory_type(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
668668
VK_CHECK(vkAllocateMemory(get_device().get_handle(), &memory_allocation, nullptr, &depth_stencil.mem));
669669
VK_CHECK(vkBindImageMemory(get_device().get_handle(), depth_stencil.image, depth_stencil.mem, 0));
670670

@@ -1332,11 +1332,11 @@ void ApiVulkanSample::with_command_buffer(const std::function<void(VkCommandBuff
13321332

13331333
void ApiVulkanSample::with_vkb_command_buffer(const std::function<void(vkb::core::CommandBufferC &command_buffer)> &f)
13341334
{
1335-
auto cmd = get_device().request_command_buffer();
1335+
auto cmd = get_device().get_command_pool().request_command_buffer();
13361336
cmd->begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, VK_NULL_HANDLE);
13371337
f(*cmd);
13381338
cmd->end();
13391339
auto &queue = get_device().get_queue_by_flags(VK_QUEUE_GRAPHICS_BIT, 0);
1340-
queue.submit(*cmd, get_device().request_fence());
1340+
queue.submit(*cmd, get_device().get_fence_pool().request_fence());
13411341
get_device().get_fence_pool().wait();
13421342
}

framework/buffer_pool.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "common/helpers.h"
2222
#include "core/buffer.h"
23-
#include "core/hpp_physical_device.h"
23+
#include "core/device.h"
2424

2525
namespace vkb
2626
{
@@ -152,16 +152,14 @@ class BufferBlock
152152
using BufferUsageFlagsType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::BufferUsageFlags, VkBufferUsageFlags>::type;
153153
using DeviceSizeType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceSize, VkDeviceSize>::type;
154154

155-
using DeviceType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::core::HPPDevice, vkb::Device>::type;
156-
157155
public:
158156
BufferBlock() = delete;
159157
BufferBlock(BufferBlock const &rhs) = delete;
160158
BufferBlock(BufferBlock &&rhs) = default;
161159
BufferBlock &operator=(BufferBlock const &rhs) = delete;
162160
BufferBlock &operator=(BufferBlock &&rhs) = default;
163161

164-
BufferBlock(DeviceType &device, DeviceSizeType size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage);
162+
BufferBlock(vkb::core::Device<bindingType> &device, DeviceSizeType size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage);
165163

166164
/**
167165
* @return An usable view on a portion of the underlying buffer
@@ -196,7 +194,7 @@ using BufferBlockC = BufferBlock<vkb::BindingType::C>;
196194
using BufferBlockCpp = BufferBlock<vkb::BindingType::Cpp>;
197195

198196
template <vkb::BindingType bindingType>
199-
BufferBlock<bindingType>::BufferBlock(DeviceType &device, DeviceSizeType size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage) :
197+
BufferBlock<bindingType>::BufferBlock(vkb::core::Device<bindingType> &device, DeviceSizeType size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage) :
200198
buffer{device, size, usage, memory_usage}
201199
{
202200
if constexpr (bindingType == BindingType::Cpp)
@@ -307,17 +305,16 @@ class BufferPool
307305
using BufferUsageFlagsType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::BufferUsageFlags, VkBufferUsageFlags>::type;
308306
using DeviceSizeType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceSize, VkDeviceSize>::type;
309307

310-
using DeviceType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::core::HPPDevice, vkb::Device>::type;
311-
312308
public:
313-
BufferPool(DeviceType &device, DeviceSizeType block_size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU);
309+
BufferPool(
310+
vkb::core::Device<bindingType> &device, DeviceSizeType block_size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU);
314311

315312
BufferBlock<bindingType> &request_buffer_block(DeviceSizeType minimum_size, bool minimal = false);
316313

317314
void reset();
318315

319316
private:
320-
vkb::core::HPPDevice &device;
317+
vkb::core::DeviceCpp &device;
321318
std::vector<std::unique_ptr<BufferBlockCpp>> buffer_blocks; /// List of blocks requested (need to be pointers in order to keep their address constant on vector resizing)
322319
vk::DeviceSize block_size = 0; /// Minimum size of the blocks
323320
vk::BufferUsageFlags usage;
@@ -328,8 +325,11 @@ using BufferPoolC = BufferPool<vkb::BindingType::C>;
328325
using BufferPoolCpp = BufferPool<vkb::BindingType::Cpp>;
329326

330327
template <vkb::BindingType bindingType>
331-
BufferPool<bindingType>::BufferPool(DeviceType &device, DeviceSizeType block_size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage) :
332-
device{reinterpret_cast<vkb::core::HPPDevice &>(device)}, block_size{block_size}, usage{usage}, memory_usage{memory_usage}
328+
BufferPool<bindingType>::BufferPool(vkb::core::Device<bindingType> &device,
329+
DeviceSizeType block_size,
330+
BufferUsageFlagsType usage,
331+
VmaMemoryUsage memory_usage) :
332+
device{reinterpret_cast<vkb::core::DeviceCpp &>(device)}, block_size{block_size}, usage{usage}, memory_usage{memory_usage}
333333
{
334334
}
335335

framework/common/hpp_resource_caching.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ struct HPPRecordHelper<vkb::core::HPPGraphicsPipeline, A...>
358358
} // namespace
359359

360360
template <class T, class... A>
361-
T &request_resource(vkb::core::HPPDevice &device, vkb::HPPResourceRecord *recorder, std::unordered_map<size_t, T> &resources, A &...args)
361+
T &request_resource(vkb::core::DeviceCpp &device, vkb::HPPResourceRecord *recorder, std::unordered_map<size_t, T> &resources, A &...args)
362362
{
363363
HPPRecordHelper<T, A...> record_helper;
364364

framework/common/hpp_vk_common.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,5 +389,45 @@ inline void submit_and_wait(vk::Device device, vk::Queue queue, std::vector<vk::
389389
device.destroyFence(fence);
390390
}
391391

392+
inline uint32_t get_queue_family_index(std::vector<vk::QueueFamilyProperties> const &queue_family_properties, vk::QueueFlagBits queue_flag)
393+
{
394+
// Dedicated queue for compute
395+
// Try to find a queue family index that supports compute but not graphics
396+
if (queue_flag & vk::QueueFlagBits::eCompute)
397+
{
398+
auto propertyIt = std::ranges::find_if(queue_family_properties,
399+
[queue_flag](const vk::QueueFamilyProperties &property) { return (property.queueFlags & queue_flag) && !(property.queueFlags & vk::QueueFlagBits::eGraphics); });
400+
if (propertyIt != queue_family_properties.end())
401+
{
402+
return static_cast<uint32_t>(std::distance(queue_family_properties.begin(), propertyIt));
403+
}
404+
}
405+
406+
// Dedicated queue for transfer
407+
// Try to find a queue family index that supports transfer but not graphics and compute
408+
if (queue_flag & vk::QueueFlagBits::eTransfer)
409+
{
410+
auto propertyIt = std::ranges::find_if(queue_family_properties,
411+
[queue_flag](const vk::QueueFamilyProperties &property) {
412+
return (property.queueFlags & queue_flag) && !(property.queueFlags & vk::QueueFlagBits::eGraphics) &&
413+
!(property.queueFlags & vk::QueueFlagBits::eCompute);
414+
});
415+
if (propertyIt != queue_family_properties.end())
416+
{
417+
return static_cast<uint32_t>(std::distance(queue_family_properties.begin(), propertyIt));
418+
}
419+
}
420+
421+
// For other queue types or if no separate compute queue is present, return the first one to support the requested flags
422+
auto propertyIt = std::ranges::find_if(
423+
queue_family_properties, [queue_flag](const vk::QueueFamilyProperties &property) { return (property.queueFlags & queue_flag) == queue_flag; });
424+
if (propertyIt != queue_family_properties.end())
425+
{
426+
return static_cast<uint32_t>(std::distance(queue_family_properties.begin(), propertyIt));
427+
}
428+
429+
throw std::runtime_error("Could not find a matching queue family index");
430+
}
431+
392432
} // namespace common
393433
} // namespace vkb

framework/common/resource_caching.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018-2021, Arm Limited and Contributors
1+
/* Copyright (c) 2018-2025, Arm Limited and Contributors
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -21,6 +21,7 @@
2121
#include "core/descriptor_set.h"
2222
#include "core/descriptor_set_layout.h"
2323
#include "core/framebuffer.h"
24+
#include "core/image.h"
2425
#include "core/pipeline.h"
2526
#include "rendering/pipeline_state.h"
2627
#include "rendering/render_target.h"
@@ -491,7 +492,7 @@ struct hash<vkb::PipelineState>
491492
vkb::hash_combine(result, pipeline_state.get_input_assembly_state().primitive_restart_enable);
492493
vkb::hash_combine(result, static_cast<std::underlying_type<VkPrimitiveTopology>::type>(pipeline_state.get_input_assembly_state().topology));
493494

494-
//VkPipelineViewportStateCreateInfo
495+
// VkPipelineViewportStateCreateInfo
495496
vkb::hash_combine(result, pipeline_state.get_viewport_state().viewport_count);
496497
vkb::hash_combine(result, pipeline_state.get_viewport_state().scissor_count);
497498

@@ -551,15 +552,15 @@ inline void hash_param(size_t & /*seed*/, const VkPipelineCache & /*value*/)
551552

552553
template <>
553554
inline void hash_param<std::vector<uint8_t>>(
554-
size_t & seed,
555+
size_t &seed,
555556
const std::vector<uint8_t> &value)
556557
{
557558
hash_combine(seed, std::string{value.begin(), value.end()});
558559
}
559560

560561
template <>
561562
inline void hash_param<std::vector<Attachment>>(
562-
size_t & seed,
563+
size_t &seed,
563564
const std::vector<Attachment> &value)
564565
{
565566
for (auto &attachment : value)
@@ -570,7 +571,7 @@ inline void hash_param<std::vector<Attachment>>(
570571

571572
template <>
572573
inline void hash_param<std::vector<LoadStoreInfo>>(
573-
size_t & seed,
574+
size_t &seed,
574575
const std::vector<LoadStoreInfo> &value)
575576
{
576577
for (auto &load_store_info : value)
@@ -581,7 +582,7 @@ inline void hash_param<std::vector<LoadStoreInfo>>(
581582

582583
template <>
583584
inline void hash_param<std::vector<SubpassInfo>>(
584-
size_t & seed,
585+
size_t &seed,
585586
const std::vector<SubpassInfo> &value)
586587
{
587588
for (auto &subpass_info : value)
@@ -592,7 +593,7 @@ inline void hash_param<std::vector<SubpassInfo>>(
592593

593594
template <>
594595
inline void hash_param<std::vector<ShaderModule *>>(
595-
size_t & seed,
596+
size_t &seed,
596597
const std::vector<ShaderModule *> &value)
597598
{
598599
for (auto &shader_module : value)
@@ -603,7 +604,7 @@ inline void hash_param<std::vector<ShaderModule *>>(
603604

604605
template <>
605606
inline void hash_param<std::vector<ShaderResource>>(
606-
size_t & seed,
607+
size_t &seed,
607608
const std::vector<ShaderResource> &value)
608609
{
609610
for (auto &resource : value)
@@ -614,7 +615,7 @@ inline void hash_param<std::vector<ShaderResource>>(
614615

615616
template <>
616617
inline void hash_param<std::map<uint32_t, std::map<uint32_t, VkDescriptorBufferInfo>>>(
617-
size_t & seed,
618+
size_t &seed,
618619
const std::map<uint32_t, std::map<uint32_t, VkDescriptorBufferInfo>> &value)
619620
{
620621
for (auto &binding_set : value)
@@ -631,7 +632,7 @@ inline void hash_param<std::map<uint32_t, std::map<uint32_t, VkDescriptorBufferI
631632

632633
template <>
633634
inline void hash_param<std::map<uint32_t, std::map<uint32_t, VkDescriptorImageInfo>>>(
634-
size_t & seed,
635+
size_t &seed,
635636
const std::map<uint32_t, std::map<uint32_t, VkDescriptorImageInfo>> &value)
636637
{
637638
for (auto &binding_set : value)
@@ -647,7 +648,7 @@ inline void hash_param<std::map<uint32_t, std::map<uint32_t, VkDescriptorImageIn
647648
}
648649

649650
template <typename T, typename... Args>
650-
inline void hash_param(size_t &seed, const T &first_arg, const Args &... args)
651+
inline void hash_param(size_t &seed, const T &first_arg, const Args &...args)
651652
{
652653
hash_param(seed, first_arg);
653654

@@ -657,7 +658,7 @@ inline void hash_param(size_t &seed, const T &first_arg, const Args &... args)
657658
template <class T, class... A>
658659
struct RecordHelper
659660
{
660-
size_t record(ResourceRecord & /*recorder*/, A &... /*args*/)
661+
size_t record(ResourceRecord & /*recorder*/, A &.../*args*/)
661662
{
662663
return 0;
663664
}
@@ -670,7 +671,7 @@ struct RecordHelper
670671
template <class... A>
671672
struct RecordHelper<ShaderModule, A...>
672673
{
673-
size_t record(ResourceRecord &recorder, A &... args)
674+
size_t record(ResourceRecord &recorder, A &...args)
674675
{
675676
return recorder.register_shader_module(args...);
676677
}
@@ -684,7 +685,7 @@ struct RecordHelper<ShaderModule, A...>
684685
template <class... A>
685686
struct RecordHelper<PipelineLayout, A...>
686687
{
687-
size_t record(ResourceRecord &recorder, A &... args)
688+
size_t record(ResourceRecord &recorder, A &...args)
688689
{
689690
return recorder.register_pipeline_layout(args...);
690691
}
@@ -698,7 +699,7 @@ struct RecordHelper<PipelineLayout, A...>
698699
template <class... A>
699700
struct RecordHelper<RenderPass, A...>
700701
{
701-
size_t record(ResourceRecord &recorder, A &... args)
702+
size_t record(ResourceRecord &recorder, A &...args)
702703
{
703704
return recorder.register_render_pass(args...);
704705
}
@@ -712,7 +713,7 @@ struct RecordHelper<RenderPass, A...>
712713
template <class... A>
713714
struct RecordHelper<GraphicsPipeline, A...>
714715
{
715-
size_t record(ResourceRecord &recorder, A &... args)
716+
size_t record(ResourceRecord &recorder, A &...args)
716717
{
717718
return recorder.register_graphics_pipeline(args...);
718719
}
@@ -725,7 +726,7 @@ struct RecordHelper<GraphicsPipeline, A...>
725726
} // namespace
726727

727728
template <class T, class... A>
728-
T &request_resource(Device &device, ResourceRecord *recorder, std::unordered_map<std::size_t, T> &resources, A &... args)
729+
T &request_resource(vkb::core::DeviceC &device, ResourceRecord *recorder, std::unordered_map<std::size_t, T> &resources, A &...args)
729730
{
730731
RecordHelper<T, A...> record_helper;
731732

framework/common/utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void screenshot(RenderContext &render_context, const std::string &filename)
6464

6565
const auto &queue = render_context.get_device().get_queue_by_flags(VK_QUEUE_GRAPHICS_BIT, 0);
6666

67-
auto cmd_buf = render_context.get_device().request_command_buffer();
67+
auto cmd_buf = render_context.get_device().get_command_pool().request_command_buffer();
6868

6969
cmd_buf->begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
7070

0 commit comments

Comments
 (0)