Skip to content

Commit

Permalink
MAINT: rename method and fix move semantics.
Browse files Browse the repository at this point in the history
  • Loading branch information
Odd Kiva committed Dec 4, 2023
1 parent 3c9a925 commit 35a8e07
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 32 deletions.
45 changes: 40 additions & 5 deletions cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,45 @@ class VulkanImageRenderer : public kvk::GraphicsBackend


private: /* Methods to initialize objects for the graphics pipeline. */
auto init_device_and_queues() -> void override
{
// According to:
// https://stackoverflow.com/questions/61434615/in-vulkan-is-it-beneficial-for-the-graphics-queue-family-to-be-separate-from-th
//
// Using distinct queue families, namely one for the graphics operations
// and another for the present operations, does not result in better
// performance.
//
// This is because the hardware does not expose present-only queue
// families...
const auto graphics_queue_family_index =
kvk::find_graphics_queue_family_indices(_physical_device).front();
const auto present_queue_family_index =
kvk::find_present_queue_family_indices(_physical_device, _surface)
.front();

// Create a logical device.
auto device_extensions = std::vector{VK_KHR_SWAPCHAIN_EXTENSION_NAME};
if constexpr (compile_for_apple)
device_extensions.emplace_back("VK_KHR_portability_subset");
auto physical_device_features = VkPhysicalDeviceFeatures{};
physical_device_features.samplerAnisotropy = VK_TRUE;
_device = svk::Device::Builder{_physical_device}
.enable_device_extensions(device_extensions)
.enable_queue_families(
{graphics_queue_family_index, present_queue_family_index})
.enable_physical_device_features(physical_device_features)
.enable_validation_layers(_validation_layers)
.create();

SARA_DEBUG
<< "[VK] - Fetching the graphics queue from the logical device...\n";
_graphics_queue = svk::Queue{_device, graphics_queue_family_index};
SARA_DEBUG
<< "[VK] - Fetching the present queue from the logical device...\n";
_present_queue = svk::Queue{_device, present_queue_family_index};
}

auto init_graphics_pipeline(GLFWwindow* window, //
const std::filesystem::path& vertex_shader_path,
const std::filesystem::path& fragment_shader_path)
Expand Down Expand Up @@ -442,26 +481,22 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
svk::DeviceMemoryFactory{_physical_device, _device} //
.allocate_for_staging_buffer(_image_staging_buffer);
_image_staging_buffer.bind(_image_staging_dmem, 0);
fmt::print("Initializing staging buffer OK\n");

// Copy the image data from the host buffer to the staging device buffer.
_image_staging_dmem.copy_from(_image_host.data(), _image_host.size());
fmt::print("Copy from host to staging buffer OK\n");

// Image data as device image associated with a device memory.
_image =
svk::Image::Builder{_device}
.sizes(VkExtent2D{w, h})
.format(VK_FORMAT_B8G8R8A8_SRGB)
.format(VK_FORMAT_R8G8B8A8_SRGB)
.tiling(VK_IMAGE_TILING_OPTIMAL)
.usage(VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)
.create();
fmt::print("Initializing device image OK\n");
_image_dmem = svk::DeviceMemoryFactory{_physical_device, _device} //
.allocate_for_device_image(_image);
fmt::print("Initializing device image mem OK\n");
_image.bind(_image_dmem, 0);
fmt::print("Binding device image to device mem OK\n");
}

auto init_image_sampler() -> void
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/DO/Shakti/Vulkan/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ namespace DO::Shakti::Vulkan {
}

//! Bind the Vulkan device features we require.
auto enable_device_features(const VkPhysicalDeviceFeatures& features = {})
-> Builder&
auto enable_physical_device_features(
const VkPhysicalDeviceFeatures& features = {}) -> Builder&
{
_physical_device_features = features;
_create_info.pEnabledFeatures = &_physical_device_features;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/DO/Shakti/Vulkan/GraphicsBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ auto GraphicsBackend::init_device_and_queues() -> void
.enable_device_extensions(device_extensions)
.enable_queue_families(
{graphics_queue_family_index, present_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(_validation_layers)
.create();

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/DO/Shakti/Vulkan/GraphicsBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace DO::Kalpana::Vulkan {

auto init_physical_device() -> void;

auto init_device_and_queues() -> void;
virtual auto init_device_and_queues() -> void;

auto init_swapchain(GLFWwindow* window) -> void;

Expand Down
14 changes: 11 additions & 3 deletions cpp/src/DO/Shakti/Vulkan/Sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ namespace DO::Shakti::Vulkan {

Sampler(const Sampler&) = delete;

Sampler(Sampler&& other) = default;
Sampler(Sampler&& other)
{
swap(other);
}

~Sampler()
{
Expand All @@ -43,8 +46,7 @@ namespace DO::Shakti::Vulkan {

auto operator=(Sampler&& other) -> Sampler&
{
_device = std::move(other._device);
_handle = std::move(other._handle);
swap(other);
return *this;
}

Expand All @@ -58,6 +60,12 @@ namespace DO::Shakti::Vulkan {
return _handle;
}

auto swap(Sampler& other) -> void
{
std::swap(_device, other._device);
std::swap(_handle, other._handle);
}

private:
VkDevice _device = VK_NULL_HANDLE;
VkSampler _handle = VK_NULL_HANDLE;
Expand Down
10 changes: 5 additions & 5 deletions cpp/test/Shakti/Vulkan/test_vulkan_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(test_staging_buffer)
device_extensions.emplace_back("VK_KHR_portability_subset");
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_device_features({})
.enable_physical_device_features({})
.enable_queue_families({compute_queue_family_index})
.enable_validation_layers(validation_layers_required)
.create();
Expand Down Expand Up @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(test_device_buffer)
device_extensions.emplace_back("VK_KHR_portability_subset");
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_device_features({})
.enable_physical_device_features({})
.enable_queue_families({compute_queue_family_index})
.enable_validation_layers(validation_layers_required)
.create();
Expand Down Expand Up @@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE(test_staging_buffer_with_factory)
device_extensions.emplace_back("VK_KHR_portability_subset");
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_device_features({})
.enable_physical_device_features({})
.enable_queue_families({compute_queue_family_index})
.enable_validation_layers(validation_layers_required)
.create();
Expand Down Expand Up @@ -405,7 +405,7 @@ BOOST_AUTO_TEST_CASE(test_device_buffer_with_factory)
device_extensions.emplace_back("VK_KHR_portability_subset");
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_device_features({})
.enable_physical_device_features({})
.enable_queue_families({compute_queue_family_index})
.enable_validation_layers(validation_layers_required)
.create();
Expand Down Expand Up @@ -495,7 +495,7 @@ BOOST_AUTO_TEST_CASE(test_uniform_buffer_with_factory)
device_extensions.emplace_back("VK_KHR_portability_subset");
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_device_features({})
.enable_physical_device_features({})
.enable_queue_families({compute_queue_family_index})
.enable_validation_layers(validation_layers_required)
.create();
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_command_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(initialize_graphics_command_pool)
.enable_device_extensions(device_extensions)
.enable_queue_families({graphics_queue_family_index,
present_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_descriptor_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(test_device)
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_queue_families({compute_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(test_device)
.enable_device_extensions(device_extensions)
.enable_queue_families({graphics_queue_family_index,
present_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(test_fence)
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_queue_families({compute_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_graphics_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ BOOST_AUTO_TEST_CASE(test_graphics_pipeline_build)
.enable_device_extensions(device_extensions)
.enable_queue_families({graphics_queue_family_index,
present_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down
13 changes: 7 additions & 6 deletions cpp/test/Shakti/Vulkan/test_vulkan_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ BOOST_AUTO_TEST_CASE(test_image)
// Allow anisotropic sampling.
auto physical_device_features = VkPhysicalDeviceFeatures{};
physical_device_features.samplerAnisotropy = VK_TRUE;
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_queue_families({compute_queue_family_index})
.enable_device_features(physical_device_features)
.enable_validation_layers(validation_layers_required)
.create();
const auto device =
svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_queue_families({compute_queue_family_index})
.enable_physical_device_features(physical_device_features)
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != VK_NULL_HANDLE);


Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(test_render_pass_build)
.enable_device_extensions(device_extensions)
.enable_queue_families({graphics_queue_family_index,
present_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down
4 changes: 2 additions & 2 deletions cpp/test/Shakti/Vulkan/test_vulkan_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ BOOST_AUTO_TEST_CASE(test_vulkan_shader_module)


// Create a logical device.
auto device_extensions = std::vector<const char *>{};
auto device_extensions = std::vector<const char*>{};
if constexpr (compile_for_apple)
device_extensions.emplace_back("VK_KHR_portability_subset");
const auto device = svk::Device::Builder{physical_device}
.enable_device_extensions(device_extensions)
.enable_queue_families({compute_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(test_swapchain_build)
.enable_device_extensions(device_extensions)
.enable_queue_families({graphics_queue_family_index,
present_queue_family_index})
.enable_device_features({})
.enable_physical_device_features({})
.enable_validation_layers(validation_layers_required)
.create();
BOOST_CHECK(static_cast<VkDevice>(device) != nullptr);
Expand Down

0 comments on commit 35a8e07

Please sign in to comment.