diff --git a/README.md b/README.md index 8bca643..99323b1 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,45 @@ # Vulkan-CPP -Modern abstraction layer for Vulkan using C++23 to simplify and modernize development for graphical applications. +Custom Vulkan abstraction layer with native C++20 modules support using LLVM. -![NOTE] -> vulkan-cpp assumes you have some knowledge of computer graphics and API's such as with OpenGL or Direct3D +> [!TIP] +> vulkan-cpp assumes you have some knowledge of graphics APIs such as OpenGL or Direct3D -# Why another abstraction around Vulkan? +## Getting Started -I chose to make this vulkan abstraction for developing graphics applications using Vulkan much simpler. This involved providing ways for specifying operations that had quite a bit of boilerplate being done in raw Vulkan. +Before buidling the demos, make sure to check the [getting started](https://engine3d-dev.github.io/0.1/getting_started) page beforehand. -Examples of these are renderpass attachments and setting up descriptor set handles. These take up extroadinary amount of code to implement. Though there are not always a one size fit all situation. +## Building Demos +These demos are isolated and attempt at following the Vulkan tutorial, specifically to using the vulkan-cpp APIs. Building the demo is quite easy, assuming you already setup the development environment from the getting started page linked above. -## How to Build +Here is how to build any of the demos: -For building our projects we use Conan, the C++ package manager to manage our dependencies and build vulkan-cpp demos. +> [!NOTE] +> `-s build_type=Debug` to build in debug mode -Required to start at the [getting started](https://engine3d-dev.github.io/0.1/getting_started) page for setting up the development environment. +```bash +conan atlas build demos/ -s build_type=Debug +``` -## Example Demos +Example for building demo 6: -The demos are meant to reflect closely enough to the Vulkan tutorial documentation site. Where they show you how to learn how to use Vulkan. +```bash +conan atlas build demos/6-graphics-pipeline -s build_type=Debug +``` -These demos are supposed to enable you in learning more about how vulkan-cpp works, and how you can effectively build a renderer using the current API's of vulkan-cpp. +## Running the Demos -## Shader Samples +The build directory will be located in the demo that you built. -These are shader samples used by the specific demos that you see referenced below. Which demo utilizes those specific shader samples. +Executable path will be as the following: -* sample 1 -- used by demo 6 and 7 -* sample 2 -- used by demo 8 -* sample 3 -- used by demo 9 (descriptors + camera uniforms) -* sample 4 -- used by demo 10 (textures) \ No newline at end of file +```bash +./demo//build/Debug/ +``` + +For demo 6 this is where the executable is located: + +```bash +./demo/6-graphics-pipeline/build/Debug/graphics-pipeline +``` \ No newline at end of file diff --git a/demos/1-instance/conanfile.py b/demos/1-instance/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/1-instance/conanfile.py +++ b/demos/1-instance/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/10-textures/application.cpp b/demos/10-textures/application.cpp index 83e6538..cc720db 100644 --- a/demos/10-textures/application.cpp +++ b/demos/10-textures/application.cpp @@ -141,7 +141,7 @@ main() { // We provide a selection of format support that we want to check is // supported on current hardware device. VkFormat depth_format = - vk::select_depth_format(physical_device, format_support); + physical_device.request_depth_format(format_support); vk::queue_indices queue_indices = physical_device.family_indices(); std::println("Graphics Queue Family Index = {}", queue_indices.graphics); @@ -170,7 +170,7 @@ main() { std::println("Starting implementation of the swapchain!!!"); vk::surface_params surface_properties = - vk::enumerate_surface(physical_device, window_surface); + physical_device.request_surface(window_surface); if (surface_properties.format.format != VK_FORMAT_UNDEFINED) { std::println("Surface Format.format is not undefined!!!"); @@ -206,11 +206,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = surface_properties.format.format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::color_bit, .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties(), }; swapchain_images[i] = @@ -221,11 +222,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = depth_format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::depth_bit, .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties(), }; swapchain_depth_images[i] = vk::sample_image(logical_device, image_config); @@ -446,69 +448,100 @@ main() { .normals = { 0.f, 0.f, 0.f }, .uv = { 1.0f, 1.0f } } }; - vk::vertex_params vertex_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .vertices = vertices, + //! @brief Creating vertex/index buffers with host visibility flags + const auto property_flags = + static_cast(vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit); + + vk::buffer_parameters vertex_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = vk::memory_property::device_local_bit, + .usage = static_cast(vk::buffer_usage::transfer_dst_bit) | + static_cast(vk::buffer_usage::vertex_buffer_bit), }; - vk::vertex_buffer test_vbo(logical_device, vertex_info); - std::println("vertex_buffer.alive() = {}", test_vbo.alive()); + vk::vertex_buffer test_vbo(logical_device, vertices, vertex_params); std::array indices = { 0, 1, 2, 2, 3, 0 }; - vk::index_params index_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .indices = indices, + vk::buffer_parameters index_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit), + .usage = static_cast(vk::buffer_usage::index_buffer_bit), }; - vk::index_buffer test_ibo(logical_device, index_info); - std::println("index_buffer.alive() = {}", test_ibo.alive()); + vk::index_buffer test_ibo(logical_device, indices, index_params); // Setting up descriptor sets for handling uniforms - vk::uniform_params test_ubo_info = { .phsyical_memory_properties = - physical_device.memory_properties(), - .size_bytes = sizeof(global_uniform) }; - vk::uniform_buffer test_ubo = - vk::uniform_buffer(logical_device, test_ubo_info); - - std::array uniforms0 = { vk::write_buffer{ - .buffer = test_ubo, .offset = 0, .range = test_ubo.size_bytes() } }; + vk::buffer_parameters uniform_params = { + .memory_mask = + physical_device.memory_properties(static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit)), + .usage = static_cast(vk::buffer_usage::uniform_buffer_bit), + }; + vk::uniform_buffer test_ubo = vk::uniform_buffer( + logical_device, sizeof(global_uniform), uniform_params); + + std::array uniforms0 = { + vk::write_buffer{ + .buffer = test_ubo, + .offset = 0, + .range = static_cast(test_ubo.size_bytes()), + }, + }; std::array uniforms = { vk::write_buffer_descriptor{ .dst_binding = 0, .uniforms = uniforms0 } }; // Loading a texture -- for testing - vk::texture_info config_texture = { - .phsyical_memory_properties = physical_device.memory_properties(), - .filepath = - std::filesystem::path("asset_samples/container_diffuse.png"), + vk::texture_params config_texture = { + .memory_mask = + physical_device.memory_properties(static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit)), }; - vk::texture texture1(logical_device, config_texture); + vk::texture texture1( + logical_device, + std::filesystem::path("asset_samples/container_diffuse.png"), + config_texture); std::println("texture1.valid = {}", texture1.loaded()); // Moving update call here because now we add textures to set0 - vk::uniform_params material_ubfo_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .size_bytes = sizeof(material_uniform) + vk::buffer_parameters material_ubfo_info = { + .memory_mask = + physical_device.memory_properties(static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit)), + .usage = static_cast(vk::buffer_usage::uniform_buffer_bit), + }; + vk::uniform_buffer material_ubo = vk::uniform_buffer( + logical_device, sizeof(material_uniform), material_ubfo_info); + + std::array set1_uniforms0 = { + vk::write_buffer{ + .buffer = material_ubo, + .offset = 0, + .range = static_cast(material_ubo.size_bytes()), + }, }; - vk::uniform_buffer material_ubo = - vk::uniform_buffer(logical_device, material_ubfo_info); - - std::array set1_uniforms0 = { vk::write_buffer{ - .buffer = material_ubo, - .offset = 0, - .range = material_ubo.size_bytes() } }; std::array uniforms_set1 = { - vk::write_buffer_descriptor{ .dst_binding = 0, - .uniforms = set1_uniforms0 } + vk::write_buffer_descriptor{ + .dst_binding = 0, + .uniforms = set1_uniforms0, + }, }; - std::array set1_samplers = { vk::write_image{ - .sampler = texture1.image().sampler(), - .view = texture1.image().image_view(), - .layout = vk::image_layout::shader_read_only_optimal, - } }; + std::array set1_samplers = { + vk::write_image{ + .sampler = texture1.image().sampler(), + .view = texture1.image().image_view(), + .layout = vk::image_layout::shader_read_only_optimal, + }, + }; std::array sample_images = { vk::write_image_descriptor{ .dst_binding = 1, @@ -527,21 +560,27 @@ main() { // renderpass begin/end must be within a recording command buffer vk::renderpass_begin_params begin_renderpass = { - .current_command = current, .extent = swapchain_extent, .current_framebuffer = swapchain_framebuffers[current_frame], .color = color, .subpass = vk::subpass_contents::inline_bit }; - main_renderpass.begin(begin_renderpass); + main_renderpass.begin(current, begin_renderpass); // Binding a graphics pipeline -- before drawing stuff // Inside of this graphics pipeline bind, is where you want to do the // drawing stuff to main_graphics_pipeline.bind(current); - test_vbo.bind(current); - test_ibo.bind(current); + // test_vbo.bind(current); + // test_ibo.bind(current); + const VkBuffer vertex = test_vbo; + uint64_t offset = 0; + current.bind_vertex_buffers(std::span(&vertex, 1), + std::span(&offset, 1)); + if (!indices.empty()) { + current.bind_index_buffers32(test_ibo); + } static auto start_time = std::chrono::high_resolution_clock::now(); @@ -565,16 +604,19 @@ main() { 10.0f) }; ubo.proj[1][1] *= -1; - test_ubo.update(&ubo); - - // Before we can send stuff to the GPU, since we already updated the - // descriptor set 0 beforehand, we must bind that descriptor resource - // before making any of the draw calls Something to note: You cannot - // update descriptor sets in the process of a current-recording command - // buffers or else that becomes undefined behavior - set0_resource.bind(current, main_graphics_pipeline.layout()); + + test_ubo.transfer( + std::span(&ubo, 1)); + + std::array descriptors = { + set0_resource, + }; + + current.bind_descriptors(main_graphics_pipeline.layout(), + VK_PIPELINE_BIND_POINT_GRAPHICS, + descriptors); + // Drawing-call to render actual triangle to the screen - // vkCmdDraw(current, 3, 1, 0, 0); vkCmdDrawIndexed( current, static_cast(indices.size()), 1, 0, 0, 0); diff --git a/demos/10-textures/conanfile.py b/demos/10-textures/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/10-textures/conanfile.py +++ b/demos/10-textures/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/11-depth-buffering/application.cpp b/demos/11-depth-buffering/application.cpp index 30887b8..aff27f7 100644 --- a/demos/11-depth-buffering/application.cpp +++ b/demos/11-depth-buffering/application.cpp @@ -135,7 +135,7 @@ main() { // We provide a selection of format support that we want to check is // supported on current hardware device. VkFormat depth_format = - vk::select_depth_format(physical_device, format_support); + physical_device.request_depth_format(format_support); vk::queue_indices queue_indices = physical_device.family_indices(); std::println("Graphics Queue Family Index = {}", queue_indices.graphics); @@ -164,15 +164,15 @@ main() { std::println("Starting implementation of the swapchain!!!"); vk::surface_params surface_properties = - vk::enumerate_surface(physical_device, window_surface); + physical_device.request_surface(window_surface); if (surface_properties.format.format != VK_FORMAT_UNDEFINED) { std::println("Surface Format.format is not undefined!!!"); } vk::swapchain_params enumerate_swapchain_settings = { - .width = (uint32_t)width, - .height = (uint32_t)height, + .width = static_cast(width), + .height = static_cast(height), .present_index = physical_device.family_indices() .graphics, // presentation index just uses the graphics index @@ -198,12 +198,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = surface_properties.format.format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::color_bit, .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - // .physical_device = physical_device - .phsyical_memory_properties = physical_device.memory_properties(), }; swapchain_images[i] = @@ -214,11 +214,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = depth_format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::depth_bit, .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties(), }; swapchain_depth_images[i] = vk::sample_image(logical_device, image_config); @@ -454,38 +455,50 @@ main() { .normals = { 0.0f, 1.0f, 0.f }, .uv = { 1.0f, 1.0f } } }; - vk::vertex_params vertex_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .vertices = vertices, + + //! @brief Setting host visibility property flags + const auto property_flags = + static_cast(vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit); + + // Creating vertex buffers + vk::buffer_parameters vertex_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = vk::memory_property::device_local_bit, + .usage = static_cast(vk::buffer_usage::transfer_dst_bit) | + static_cast(vk::buffer_usage::vertex_buffer_bit), }; - vk::vertex_buffer test_vbo(logical_device, vertex_info); - std::println("vertex_buffer.alive() = {}", test_vbo.alive()); + vk::vertex_buffer test_vbo(logical_device, vertices, vertex_params); + // Creating index buffers std::array indices = { 0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4 }; + vk::buffer_parameters index_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit), + .usage = static_cast(vk::buffer_usage::index_buffer_bit), + }; + vk::index_buffer test_ibo(logical_device, indices, index_params); + + vk::buffer_parameters uniform_params = { + .memory_mask = + physical_device.memory_properties(static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit)), + .usage = static_cast(vk::buffer_usage::uniform_buffer_bit), + }; - vk::index_params index_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .indices = indices, + vk::uniform_buffer test_ubo = vk::uniform_buffer( + logical_device, sizeof(global_uniform), uniform_params); + + std::array uniforms0 = { + vk::write_buffer{ + .buffer = test_ubo, + .offset = 0, + .range = static_cast(test_ubo.size_bytes()), + }, }; - vk::index_buffer test_ibo(logical_device, index_info); - std::println("index_buffer.alive() = {}", test_ibo.alive()); - - // Dummy uniform struct just for testing if update works when mapping some - // data camera_ubo global_ubo = {}; test_ubo.update(&global_ubo); - - // Setting up descriptor sets for handling uniforms - vk::uniform_params test_ubo_info = { .phsyical_memory_properties = - physical_device.memory_properties(), - .size_bytes = sizeof(global_uniform) }; - vk::uniform_buffer test_ubo = - vk::uniform_buffer(logical_device, test_ubo_info); - std::println("uniform_buffer.alive() = {}", test_ubo.alive()); - - std::array uniforms0 = { vk::write_buffer{ - .buffer = test_ubo, - .offset = 0, - .range = test_ubo.size_bytes(), - } }; std::array uniforms = { vk::write_buffer_descriptor{ @@ -495,12 +508,16 @@ main() { }; // Loading a texture -- for testing - vk::texture_info config_texture = { - .phsyical_memory_properties = physical_device.memory_properties(), - .filepath = - std::filesystem::path("asset_samples/container_diffuse.png") + vk::texture_params config_texture = { + .memory_mask = + physical_device.memory_properties(static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit)), }; - vk::texture texture1(logical_device, config_texture); + vk::texture texture1( + logical_device, + std::filesystem::path("asset_samples/container_diffuse.png"), + config_texture); std::println("texture1.valid = {}", texture1.loaded()); @@ -527,21 +544,30 @@ main() { // renderpass begin/end must be within a recording command buffer vk::renderpass_begin_params begin_renderpass = { - .current_command = current, .extent = swapchain_extent, .current_framebuffer = swapchain_framebuffers[current_frame], .color = color, .subpass = vk::subpass_contents::inline_bit }; - main_renderpass.begin(begin_renderpass); + main_renderpass.begin(current, begin_renderpass); // Binding a graphics pipeline -- before drawing stuff // Inside of this graphics pipeline bind, is where you want to do the // drawing stuff to main_graphics_pipeline.bind(current); - test_vbo.bind(current); - test_ibo.bind(current); + const VkBuffer vertex = test_vbo; + uint64_t offset = 0; + + current.bind_vertex_buffers(std::span(&vertex, 1), + std::span(&offset, 1)); + + if (!indices.empty()) { + current.bind_index_buffers32(test_ibo); + } + + // test_vbo.bind(current); + // test_ibo.bind(current); static auto start_time = std::chrono::high_resolution_clock::now(); @@ -565,14 +591,22 @@ main() { 10.0f) }; ubo.proj[1][1] *= -1; - test_ubo.update(&ubo); + // test_ubo.update(&ubo); + test_ubo.transfer( + std::span(&ubo, 1)); // Before we can send stuff to the GPU, since we already updated the // descriptor set 0 beforehand, we must bind that descriptor resource // before making any of the draw calls Something to note: You cannot // update descriptor sets in the process of a current-recording command // buffers or else that becomes undefined behavior - set0_resource.bind(current, main_graphics_pipeline.layout()); + // set0_resource.bind(current, main_graphics_pipeline.layout()); + std::array descriptors = { + set0_resource, + }; + current.bind_descriptors(main_graphics_pipeline.layout(), + VK_PIPELINE_BIND_POINT_GRAPHICS, + descriptors); // Drawing-call to render actual triangle to the screen // vkCmdDraw(current, 3, 1, 0, 0); diff --git a/demos/11-depth-buffering/conanfile.py b/demos/11-depth-buffering/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/11-depth-buffering/conanfile.py +++ b/demos/11-depth-buffering/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/14-imgui/application.cpp b/demos/14-imgui/application.cpp index a4e7d8f..21c07c8 100644 --- a/demos/14-imgui/application.cpp +++ b/demos/14-imgui/application.cpp @@ -326,7 +326,7 @@ main() { std::println("Starting implementation of the swapchain!!!"); vk::surface_params surface_properties = - vk::enumerate_surface(physical_device, window_surface); + physical_device.request_surface(window_surface); if (surface_properties.format.format != VK_FORMAT_UNDEFINED) { std::println("Surface Format.format is not undefined!!!"); diff --git a/demos/2-physical-device/conanfile.py b/demos/2-physical-device/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/2-physical-device/conanfile.py +++ b/demos/2-physical-device/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/3-logical-device/application.cpp b/demos/3-logical-device/application.cpp index 1631dff..92d9f27 100644 --- a/demos/3-logical-device/application.cpp +++ b/demos/3-logical-device/application.cpp @@ -109,22 +109,6 @@ main() { }; vk::physical_device physical_device(api_instance, enumerate_devices); - // selecting depth format - std::array format_support = { - vk::format::d32_sfloat, - vk::format::d32_sfloat_s8_uint, - vk::format::d24_unorm_s8_uint - }; - - // We provide a selection of format support that we want to check is - // supported on current hardware device. - VkFormat depth_format = - vk::select_depth_format(physical_device, format_support); - - if (depth_format != VK_FORMAT_UNDEFINED) { - std::println("Depth format specifically was able to be found!!!"); - } - vk::queue_indices queue_indices = physical_device.family_indices(); std::println("Graphics Queue Family Index = {}", (int)queue_indices.graphics); diff --git a/demos/3-logical-device/conanfile.py b/demos/3-logical-device/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/3-logical-device/conanfile.py +++ b/demos/3-logical-device/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/4-surface/application.cpp b/demos/4-surface/application.cpp index 3188b74..d09934a 100644 --- a/demos/4-surface/application.cpp +++ b/demos/4-surface/application.cpp @@ -109,18 +109,6 @@ main() { }; vk::physical_device physical_device(api_instance, enumerate_devices); - // selecting depth format - std::array format_support = { - vk::format::d32_sfloat, - vk::format::d32_sfloat_s8_uint, - vk::format::d24_unorm_s8_uint - }; - - // We provide a selection of format support that we want to check is - // supported on current hardware device. - VkFormat depth_format = - vk::select_depth_format(physical_device, format_support); - vk::queue_indices queue_indices = physical_device.family_indices(); // setting up logical device diff --git a/demos/4-surface/conanfile.py b/demos/4-surface/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/4-surface/conanfile.py +++ b/demos/4-surface/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/5-swapchain/application.cpp b/demos/5-swapchain/application.cpp index be6d9a9..a91b567 100644 --- a/demos/5-swapchain/application.cpp +++ b/demos/5-swapchain/application.cpp @@ -113,13 +113,6 @@ main() { }; vk::physical_device physical_device(api_instance, enumerate_devices); - // selecting depth format - std::array format_support = { - vk::format::d32_sfloat, - vk::format::d32_sfloat_s8_uint, - vk::format::d24_unorm_s8_uint - }; - vk::queue_indices queue_indices = physical_device.family_indices(); // setting up logical device @@ -143,7 +136,7 @@ main() { vk::surface window_surface(api_instance, window); vk::surface_params surface_properties = - vk::enumerate_surface(physical_device, window_surface); + physical_device.request_surface(window_surface); vk::swapchain_params enumerate_swapchain_settings = { .width = static_cast(width), @@ -174,11 +167,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = surface_properties.format.format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::color_bit, .usage = vk::image_usage::color_attachment_bit, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties(), }; swapchain_images[i] = @@ -230,9 +224,6 @@ main() { vk::framebuffer(logical_device, framebuffer_info); } - std::println("Created VkFramebuffer's with size = {}", - swapchain_framebuffers.size()); - // setting up presentation queue to display commands to the screen vk::queue_params enumerate_present_queue{ .family = 0, @@ -254,13 +245,12 @@ main() { // renderpass begin/end must be within a recording command buffer vk::renderpass_begin_params begin_renderpass = { - .current_command = current, .extent = swapchain_extent, .current_framebuffer = swapchain_framebuffers[current_frame], .color = color, .subpass = vk::subpass_contents::inline_bit }; - main_renderpass.begin(begin_renderpass); + main_renderpass.begin(current, begin_renderpass); main_renderpass.end(current); current.end(); diff --git a/demos/5-swapchain/conanfile.py b/demos/5-swapchain/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/5-swapchain/conanfile.py +++ b/demos/5-swapchain/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/7-vertex-buffer/application.cpp b/demos/7-vertex-buffer/application.cpp index 7fccc00..8d8a681 100644 --- a/demos/7-vertex-buffer/application.cpp +++ b/demos/7-vertex-buffer/application.cpp @@ -138,7 +138,7 @@ main() { // We provide a selection of format support that we want to check is // supported on current hardware device. VkFormat depth_format = - vk::select_depth_format(physical_device, format_support); + physical_device.request_depth_format(format_support); vk::queue_indices queue_indices = physical_device.family_indices(); std::println("Graphics Queue Family Index = {}", queue_indices.graphics); @@ -167,15 +167,15 @@ main() { std::println("Starting implementation of the swapchain!!!"); vk::surface_params surface_properties = - vk::enumerate_surface(physical_device, window_surface); + physical_device.request_surface(window_surface); if (surface_properties.format.format != VK_FORMAT_UNDEFINED) { std::println("Surface Format.format is not undefined!!!"); } vk::swapchain_params enumerate_swapchain_settings = { - .width = (uint32_t)width, - .height = (uint32_t)height, + .width = static_cast(width), + .height = static_cast(height), .present_index = physical_device.family_indices() .graphics, // presentation index just uses the graphics index @@ -203,11 +203,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = surface_properties.format.format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::color_bit, .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties() }; swapchain_images[i] = @@ -217,11 +218,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = depth_format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::depth_bit, .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties() }; swapchain_depth_images[i] = vk::sample_image(logical_device, image_config); @@ -270,10 +272,7 @@ main() { vk::renderpass main_renderpass(logical_device, renderpass_attachments); - std::println("renderpass created!!!"); - // Setting up swapchain framebuffers - std::vector swapchain_framebuffers(image_count); for (uint32_t i = 0; i < swapchain_framebuffers.size(); i++) { // image_view_attachments.push_back(swapchain_images[i].view); @@ -297,9 +296,6 @@ main() { vk::framebuffer(logical_device, framebuffer_info); } - std::println("Created VkFramebuffer's with size = {}", - swapchain_framebuffers.size()); - // setting up presentation queue to display commands to the screen vk::queue_params enumerate_present_queue{ .family = 0, @@ -311,15 +307,17 @@ main() { // gets set with the renderpass std::array color = { 0.f, 0.5f, 0.5f, 1.f }; - std::println("Start implementing graphics pipeline!!!"); - // Now creating a vulkan graphics pipeline for the shader loading // We are using sample1 shaders which is just showing a triangle std::array shader_sources = { - vk::shader_source{ .filename = "shader_samples/sample1/test.vert.spv", - .stage = vk::shader_stage::vertex }, - vk::shader_source{ .filename = "shader_samples/sample1/test.frag.spv", - .stage = vk::shader_stage::fragment }, + vk::shader_source{ + .filename = "shader_samples/sample1/test.vert.spv", + .stage = vk::shader_stage::vertex, + }, + vk::shader_source{ + .filename = "shader_samples/sample1/test.frag.spv", + .stage = vk::shader_stage::fragment, + }, }; // To render triangle, we do not need to set any vertex attributes @@ -330,10 +328,6 @@ main() { }; vk::shader_resource geometry_resource(logical_device, shader_info); - if (geometry_resource.is_valid()) { - std::println("geometry resource is valid!"); - } - std::array color_blend_attachments = { vk::color_blend_attachment_state{}, }; @@ -375,15 +369,17 @@ main() { .uv = { 1.f, 1.f }, } }; - vk::vertex_params vertex_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .vertices = vertices, - }; - vk::vertex_buffer test_vbo(logical_device, vertex_info); - if (test_vbo.alive()) { - std::println("Vertex Buffer Successfully is valid and working!!!"); - } + const auto property_flags = + static_cast(vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit); + vk::buffer_parameters vertex_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = vk::memory_property::device_local_bit, + .usage = static_cast(vk::buffer_usage::transfer_dst_bit) | + static_cast(vk::buffer_usage::vertex_buffer_bit), + }; + vk::vertex_buffer test_vbo(logical_device, vertices, vertex_params); while (!glfwWindowShouldClose(window)) { glfwPollEvents(); @@ -395,13 +391,12 @@ main() { // renderpass begin/end must be within a recording command buffer vk::renderpass_begin_params begin_renderpass = { - .current_command = current, .extent = swapchain_extent, .current_framebuffer = swapchain_framebuffers[current_frame], .color = color, .subpass = vk::subpass_contents::inline_bit }; - main_renderpass.begin(begin_renderpass); + main_renderpass.begin(current, begin_renderpass); // Binding a graphics pipeline -- before drawing stuff // Inside of this graphics pipeline bind, is where you want to do the diff --git a/demos/7-vertex-buffer/conanfile.py b/demos/7-vertex-buffer/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/7-vertex-buffer/conanfile.py +++ b/demos/7-vertex-buffer/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/8-index-uniform-buffers/application.cpp b/demos/8-index-uniform-buffers/application.cpp index a73f189..3884ca5 100644 --- a/demos/8-index-uniform-buffers/application.cpp +++ b/demos/8-index-uniform-buffers/application.cpp @@ -11,6 +11,7 @@ #endif #include +#include #include #include import vk; @@ -135,7 +136,7 @@ main() { // We provide a selection of format support that we want to check is // supported on current hardware device. VkFormat depth_format = - vk::select_depth_format(physical_device, format_support); + physical_device.request_depth_format(format_support); vk::queue_indices queue_indices = physical_device.family_indices(); std::println("Graphics Queue Family Index = {}", queue_indices.graphics); @@ -164,7 +165,7 @@ main() { std::println("Starting implementation of the swapchain!!!"); vk::surface_params surface_properties = - vk::enumerate_surface(physical_device, window_surface); + physical_device.request_surface(window_surface); if (surface_properties.format.format != VK_FORMAT_UNDEFINED) { std::println("Surface Format.format is not undefined!!!"); @@ -200,11 +201,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = surface_properties.format.format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::color_bit, .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties() }; swapchain_images[i] = @@ -215,12 +217,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = depth_format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::depth_bit, .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - // .physical_device = physical_device - .phsyical_memory_properties = physical_device.memory_properties() }; swapchain_depth_images[i] = vk::sample_image(logical_device, image_config); @@ -269,15 +271,9 @@ main() { vk::renderpass main_renderpass(logical_device, renderpass_attachments); - std::println("renderpass created!!!"); - // Setting up swapchain framebuffers - std::vector swapchain_framebuffers(image_count); for (uint32_t i = 0; i < swapchain_framebuffers.size(); i++) { - // image_view_attachments.push_back(swapchain_images[i].view); - // image_view_attachments.push_back(swapchain_depth_images[i].view); - // NOTE: This must match the amount of attachments the renderpass also // has to match the image_view attachment for per-framebuffers as well // I just set the size to whatever the renderpass attachment size are to @@ -356,14 +352,6 @@ main() { std::println("geometry resource is valid!"); } - /* - // This get_pipeline_configuration can work as an easy way for - specfying the vulkan configurations as an ease of setting things up - // TODO: Probably provide a shorthand - which could work as this: - vk::pipeline_settings pipeline_configuration = - vk::get_pipeline_configuration(main_renderpass, geometry_resource); - */ - std::array color_blend_attachments = { vk::color_blend_attachment_state{}, }; @@ -391,20 +379,6 @@ main() { } // Setting up vertex buffer - // std::array vertices = { - // vk::vertex_input{ - // {1.f, 1.f, 1.f}, - // {1.f, 1.f, 1.f}, - // {1.f, 1.f, 1.f}, - // {1.f, 1.f}, - // }, - // vk::vertex_input{ - // {1.f, 1.f, 1.f}, - // {1.f, 1.f, 1.f}, - // {1.f, 1.f, 1.f}, - // {1.f, 1.f}, - // } - // }; std::array vertices = { vk::vertex_input{ .position = { -0.5f, -0.5f, 0.f }, .color = { 1.0f, 0.0f, 0.0f } }, @@ -415,32 +389,41 @@ main() { vk::vertex_input{ .position = { -0.5f, 0.5f, 0.f }, .color = { 1.0f, 1.0f, 1.0f } } }; - // vk::vertex_buffer_info vertex_info = { - // .physical_handle = physical_device, - // .vertices = vertices, - // }; - - vk::vertex_params vertex_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .vertices = vertices, + + const auto property_flags = + static_cast(vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit); + + // Creating vertex buffers + vk::buffer_parameters vertex_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = vk::memory_property::device_local_bit, + .usage = static_cast(vk::buffer_usage::transfer_dst_bit) | + static_cast(vk::buffer_usage::vertex_buffer_bit), }; - vk::vertex_buffer test_vbo(logical_device, vertex_info); + vk::vertex_buffer test_vbo(logical_device, vertices, vertex_params); std::println("vertex_buffer.alive() = {}", test_vbo.alive()); + // Creating index buffer std::array indices = { 0, 1, 2, 2, 3, 0 }; - - vk::index_params index_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .indices = indices, + vk::buffer_parameters index_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit), + .usage = static_cast(vk::buffer_usage::index_buffer_bit), }; - vk::index_buffer test_ibo(logical_device, index_info); - std::println("index_buffer.alive() = {}", test_ibo.alive()); - - vk::uniform_params ubo_info = { .phsyical_memory_properties = - physical_device.memory_properties(), - .size_bytes = sizeof(vk::vertex_input) }; - vk::uniform_buffer test_ubo(logical_device, ubo_info); - std::println("uniform_buffer.alive() = {}", test_ubo.alive()); + vk::index_buffer test_ibo(logical_device, indices, index_params); + + vk::buffer_parameters uniform_params = { + .memory_mask = + physical_device.memory_properties(static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit)), + .usage = static_cast(vk::buffer_usage::uniform_buffer_bit), + }; + vk::uniform_buffer test_ubo( + logical_device, sizeof(vk::vertex_input), uniform_params); while (!glfwWindowShouldClose(window)) { glfwPollEvents(); @@ -452,24 +435,27 @@ main() { // renderpass begin/end must be within a recording command buffer vk::renderpass_begin_params begin_renderpass = { - .current_command = current, .extent = swapchain_extent, .current_framebuffer = swapchain_framebuffers[current_frame], .color = color, .subpass = vk::subpass_contents::inline_bit }; - main_renderpass.begin(begin_renderpass); + main_renderpass.begin(current, begin_renderpass); // Binding a graphics pipeline -- before drawing stuff // Inside of this graphics pipeline bind, is where you want to do the // drawing stuff to main_graphics_pipeline.bind(current); - test_vbo.bind(current); - test_ibo.bind(current); + const VkBuffer vertex = test_vbo; + uint64_t offset = 0; + current.bind_vertex_buffers(std::span(&vertex, 1), + std::span(&offset, 1)); + + if (!indices.empty()) { + current.bind_index_buffers32(test_ibo); + } - // Drawing-call to render actual triangle to the screen - // vkCmdDraw(current, 3, 1, 0, 0); vkCmdDrawIndexed( current, static_cast(indices.size()), 1, 0, 0, 0); diff --git a/demos/8-index-uniform-buffers/conanfile.py b/demos/8-index-uniform-buffers/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/8-index-uniform-buffers/conanfile.py +++ b/demos/8-index-uniform-buffers/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self) diff --git a/demos/9-uniforms/application.cpp b/demos/9-uniforms/application.cpp index cb8de36..535aff8 100644 --- a/demos/9-uniforms/application.cpp +++ b/demos/9-uniforms/application.cpp @@ -134,7 +134,7 @@ main() { // We provide a selection of format support that we want to check is // supported on current hardware device. VkFormat depth_format = - vk::select_depth_format(physical_device, format_support); + physical_device.request_depth_format(format_support); vk::queue_indices queue_indices = physical_device.family_indices(); std::println("Graphics Queue Family Index = {}", queue_indices.graphics); @@ -163,15 +163,15 @@ main() { std::println("Starting implementation of the swapchain!!!"); vk::surface_params surface_properties = - vk::enumerate_surface(physical_device, window_surface); + physical_device.request_surface(window_surface); if (surface_properties.format.format != VK_FORMAT_UNDEFINED) { std::println("Surface Format.format is not undefined!!!"); } vk::swapchain_params enumerate_swapchain_settings = { - .width = (uint32_t)width, - .height = (uint32_t)height, + .width = static_cast(width), + .height = static_cast(height), .present_index = physical_device.family_indices() .graphics, // presentation index just uses the graphics index @@ -199,12 +199,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = surface_properties.format.format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::color_bit, .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - // .physical_device = physical_device - .phsyical_memory_properties = physical_device.memory_properties() }; swapchain_images[i] = @@ -214,11 +214,12 @@ main() { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, .format = depth_format, + .memory_mask = physical_device.memory_properties( + vk::memory_property::device_local_bit), .aspect = vk::image_aspect_flags::depth_bit, .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - .phsyical_memory_properties = physical_device.memory_properties() }; swapchain_depth_images[i] = vk::sample_image(logical_device, image_config); @@ -318,14 +319,16 @@ main() { // Setting up vertex attributes in the test shaders std::array attribute_entries = { - vk::vertex_attribute_entry{ .location = 0, - .format = vk::format::rg32_sfloat, - .stride = - offsetof(vk::vertex_input, position) }, - vk::vertex_attribute_entry{ .location = 1, - .format = vk::format::rgb32_sfloat, - .stride = - offsetof(vk::vertex_input, color) } + vk::vertex_attribute_entry{ + .location = 0, + .format = vk::format::rg32_sfloat, + .stride = offsetof(vk::vertex_input, position), + }, + vk::vertex_attribute_entry{ + .location = 1, + .format = vk::format::rgb32_sfloat, + .stride = offsetof(vk::vertex_input, color), + }, }; std::array attributes = { @@ -371,22 +374,10 @@ main() { .max_sets = image_count, // max of descriptor sets able to allocate .entries = entries, // specifies pool sizes and descriptor layout }; - - // Setting up the actual descriptor set 0 and array to pass into the - // graphics pipeline since graphics pipeline requires the descriptor layouts - // to be known upfront vk::descriptor_resource set0_resource(logical_device, set0_layout); - // Array of descriptor layouts to give the graphics pipeline std::array layouts = { set0_resource.layout() }; - /* - This get_pipeline_configuration can work as an easy way for specfying - the vulkan configurations as an ease of setting things up - // TODO: Probably provide a shorthand - which could work as this: - vk::pipeline_settings pipeline_configuration = - vk::get_pipeline_configuration(main_renderpass, geometry_resource); - */ std::array color_blend_attachments = { vk::color_blend_attachment_state{}, }; @@ -409,11 +400,6 @@ main() { }; vk::pipeline main_graphics_pipeline(logical_device, pipeline_configuration); - if (main_graphics_pipeline.alive()) { - std::println("Main graphics pipeline alive() = {}", - main_graphics_pipeline.alive()); - } - // Setting up vertex buffer std::array vertices = { vk::vertex_input{ .position = { -0.5f, -0.5f, 0.f }, @@ -425,40 +411,49 @@ main() { vk::vertex_input{ .position = { -0.5f, 0.5f, 0.f }, .color = { 1.0f, 1.0f, 1.0f } } }; - vk::vertex_params vertex_info = { - // .physical_handle = physical_device, - .phsyical_memory_properties = physical_device.memory_properties(), - .vertices = vertices, + const auto property_flags = + static_cast(vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit); + + // Creating vertex buffer + vk::buffer_parameters vertex_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = vk::memory_property::device_local_bit, + .usage = static_cast(vk::buffer_usage::transfer_dst_bit) | + static_cast(vk::buffer_usage::vertex_buffer_bit), }; - vk::vertex_buffer test_vbo(logical_device, vertex_info); - std::println("vertex_buffer.alive() = {}", test_vbo.alive()); + vk::vertex_buffer test_vbo(logical_device, vertices, vertex_params); + // Creating index buffer std::array indices = { 0, 1, 2, 2, 3, 0 }; - - vk::index_params index_info = { - .phsyical_memory_properties = physical_device.memory_properties(), - .indices = indices, + vk::buffer_parameters index_params = { + .memory_mask = physical_device.memory_properties(property_flags), + .property_flags = static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit), + .usage = static_cast(vk::buffer_usage::index_buffer_bit), }; - vk::index_buffer test_ibo(logical_device, index_info); - std::println("index_buffer.alive() = {}", test_ibo.alive()); - - // Setting up our uniformss specifications and updating descriptor set 0 -- - // with our global uniform data before we bind This has to be done before we - // bind so the shader resource knows how to look up our data layout and see - // if they match Will get validation layer error messages if the data layout - // does not match (meaning size_bytes doesn't match) - vk::uniform_params test_ubo_info = { // .physical_handle = physical_device, - .phsyical_memory_properties = - physical_device.memory_properties(), - .size_bytes = sizeof(global_uniform) + vk::index_buffer test_ibo(logical_device, indices, index_params); + + // Creating uniform buffer + vk::buffer_parameters uniform_params = { + .memory_mask = + physical_device.memory_properties(static_cast( + vk::memory_property::host_visible_bit | + vk::memory_property::host_cached_bit)), + .usage = static_cast(vk::buffer_usage::uniform_buffer_bit), }; - vk::uniform_buffer test_ubo = - vk::uniform_buffer(logical_device, test_ubo_info); - std::println("uniform_buffer.alive() = {}", test_ubo.alive()); + vk::uniform_buffer test_ubo = vk::uniform_buffer( + logical_device, sizeof(global_uniform), uniform_params); // vk::write_buffer_descriptor - std::array uniforms0 = { vk::write_buffer{ - .buffer = test_ubo, .offset = 0, .range = test_ubo.size_bytes() } }; + std::array uniforms0 = { + vk::write_buffer{ + .buffer = test_ubo, + .offset = 0, + .range = static_cast(test_ubo.size_bytes()), + }, + }; std::array uniforms = { vk::write_buffer_descriptor{ .dst_binding = 0, .uniforms = uniforms0 } @@ -475,21 +470,23 @@ main() { // renderpass begin/end must be within a recording command buffer vk::renderpass_begin_params begin_renderpass = { - .current_command = current, .extent = swapchain_extent, .current_framebuffer = swapchain_framebuffers[current_frame], .color = color, .subpass = vk::subpass_contents::inline_bit }; - main_renderpass.begin(begin_renderpass); + main_renderpass.begin(current, begin_renderpass); - // Binding a graphics pipeline -- before drawing stuff - // Inside of this graphics pipeline bind, is where you want to do the - // drawing stuff to main_graphics_pipeline.bind(current); - test_vbo.bind(current); - test_ibo.bind(current); + const VkBuffer vertex = test_vbo; + uint64_t offset = 0; + current.bind_vertex_buffers(std::span(&vertex, 1), + std::span(&offset, 1)); + + if (!indices.empty()) { + current.bind_index_buffers32(test_ibo); + } static auto start_time = std::chrono::high_resolution_clock::now(); @@ -513,14 +510,21 @@ main() { 10.0f) }; ubo.proj[1][1] *= -1; - test_ubo.update(&ubo); + test_ubo.transfer( + std::span(&ubo, 1)); // Before we can send stuff to the GPU, since we already updated the // descriptor set 0 beforehand, we must bind that descriptor resource // before making any of the draw calls Something to note: You cannot // update descriptor sets in the process of a current-recording command // buffers or else that becomes undefined behavior - set0_resource.bind(current, main_graphics_pipeline.layout()); + // set0_resource.bind(current, main_graphics_pipeline.layout()); + std::array descriptors = { + set0_resource, + }; + current.bind_descriptors(main_graphics_pipeline.layout(), + VK_PIPELINE_BIND_POINT_GRAPHICS, + descriptors); // Drawing-call to render actual triangle to the screen // vkCmdDraw(current, 3, 1, 0, 0); diff --git a/demos/9-uniforms/conanfile.py b/demos/9-uniforms/conanfile.py index 708fb66..eb977f5 100644 --- a/demos/9-uniforms/conanfile.py +++ b/demos/9-uniforms/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/5.0") + self.requires("vulkan-cpp/6.0") def build(self): cmake = CMake(self)