Skip to content

Commit

Permalink
WIP: save work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Odd Kiva committed Dec 4, 2023
1 parent cce30fc commit 8766d91
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
28 changes: 19 additions & 9 deletions cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ static const auto indices = std::vector<uint16_t>{
class VulkanImagePipelineBuilder : public kvk::GraphicsPipeline::Builder
{
public:
VulkanImagePipelineBuilder(const svk::Device& device,
const kvk::RenderPass& render_pass)
: kvk::GraphicsPipeline::Builder{device, render_pass}
{
}

//! @brief Boilerplate code.
//! @{
auto create_graphics_pipeline_layout(kvk::GraphicsPipeline& graphics_pipeline)
-> void
{
Expand Down Expand Up @@ -124,7 +132,9 @@ class VulkanImagePipelineBuilder : public kvk::GraphicsPipeline::Builder
fmt::format("Failed to create graphics pipeline! Error code: {}",
static_cast<int>(status))};
}
//! @}

//! @brief Focus the attention here.
auto create() -> kvk::GraphicsPipeline override
{
load_shaders();
Expand All @@ -136,8 +146,8 @@ class VulkanImagePipelineBuilder : public kvk::GraphicsPipeline::Builder

graphics_pipeline.desc_set_layout =
svk::DescriptorSetLayout::Builder{device}
.push_uniform_buffer_layout_binding()
.push_image_sampler_layout_binding()
.push_uniform_buffer_layout_binding(0)
.push_image_sampler_layout_binding(1)
.create();

create_graphics_pipeline_layout(graphics_pipeline);
Expand Down Expand Up @@ -261,7 +271,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
glfwGetWindowSize(window, &w, &h);

_graphics_pipeline =
kvk::GraphicsPipeline::Builder{_device, _render_pass}
VulkanImagePipelineBuilder{_device, _render_pass}
.vertex_shader_path(vertex_shader_path)
.fragment_shader_path(fragment_shader_path)
.vbo_data_format<Vertex>()
Expand Down Expand Up @@ -291,7 +301,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
desc_pool_builder.pool_type(1) = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
// We only need to reserve 1 image descriptor since the image will stay
// unchanged throughout the application runtime
desc_pool_builder.descriptor_count(1) = 1;
desc_pool_builder.descriptor_count(1) = num_frames_in_flight;

_desc_pool = desc_pool_builder.create();
}
Expand Down Expand Up @@ -341,8 +351,8 @@ class VulkanImageRenderer : public kvk::GraphicsBackend

auto write_dsets = std::array<VkWriteDescriptorSet, 2>{};

// 4.a) Register the byte size, the type of buffer which the descriptor
// references to.
// 3. Register the byte size, the type of buffer which the descriptor
// references to.
auto& mvp_wdset = write_dsets[0];
mvp_wdset.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
mvp_wdset.dstSet = _desc_sets[i];
Expand All @@ -361,7 +371,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
image_wdset.descriptorCount = 1;
image_wdset.pImageInfo = &image_info;

// 4.c) Send this metadata to Vulkan.
// 4. Send this metadata to Vulkan.
vkUpdateDescriptorSets(_device,
static_cast<std::uint32_t>(write_dsets.size()),
write_dsets.data(), 0, nullptr);
Expand Down Expand Up @@ -852,9 +862,9 @@ class VulkanImageRenderer : public kvk::GraphicsBackend

// Geometry data (quad)
svk::Buffer _vbo;
svk::Buffer _ebo;

svk::DeviceMemory _vdm;

svk::Buffer _ebo;
svk::DeviceMemory _edm;

// Model-view-projection matrix
Expand Down
11 changes: 6 additions & 5 deletions cpp/src/DO/Shakti/Vulkan/DescriptorSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ namespace DO::Shakti::Vulkan {
{
}

auto push_uniform_buffer_layout_binding() -> DescriptorSetLayout::Builder&
auto push_uniform_buffer_layout_binding(const std::uint32_t binding)
-> DescriptorSetLayout::Builder&
{
// UBO object: matrix-view-projection matrix stack
auto ubo_layout_binding = VkDescriptorSetLayoutBinding{};

// In the vertex shader code, we have something like:
// layout(binding = 0) uniform UBO { ... } ubo;
ubo_layout_binding.binding = static_cast<std::uint32_t>(_bindings.size());
ubo_layout_binding.binding = binding;
ubo_layout_binding.descriptorCount = 1; // TODO: see if this ever
// needs to change.
ubo_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Expand All @@ -100,12 +101,12 @@ namespace DO::Shakti::Vulkan {
return *this;
}

auto push_image_sampler_layout_binding() -> DescriptorSetLayout::Builder&
auto push_image_sampler_layout_binding(const std::uint32_t binding)
-> DescriptorSetLayout::Builder&
{
auto sampler_layout_binding = VkDescriptorSetLayoutBinding{};

sampler_layout_binding.binding =
static_cast<std::uint32_t>(_bindings.size());
sampler_layout_binding.binding = binding;
sampler_layout_binding.descriptorCount = 1; // TODO: see if this ever
// needs to change.
sampler_layout_binding.descriptorType =
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace DO::Kalpana::Vulkan {

graphics_pipeline.desc_set_layout =
Shakti::Vulkan::DescriptorSetLayout::Builder{device}
.push_uniform_buffer_layout_binding()
.push_uniform_buffer_layout_binding(0)
.create();

// Initialize the graphics pipeline layout.
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 @@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(test_device)
//
// 3.a) Create one descriptor set layout for each each descriptor.
const auto ubo_layout_binding = svk::DescriptorSetLayout::Builder{device}
.push_uniform_buffer_layout_binding()
.push_uniform_buffer_layout_binding(0)
.create();
const auto desc_set_layouts =
std::array<VkDescriptorSetLayout, num_desc_sets>{
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Shakti/Vulkan/test_vulkan_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(test_image)
//
// 1. Create the description set layout that the shaders need.
const auto desc_set_layout = svk::DescriptorSetLayout::Builder{device}
.push_image_sampler_layout_binding()
.push_image_sampler_layout_binding(0)
.create();
// 2. Hook this to the graphics pipeline layout data structure.

Expand Down

0 comments on commit 8766d91

Please sign in to comment.