Skip to content

Commit

Permalink
Fix some minor issues in Windows build (#90)
Browse files Browse the repository at this point in the history
* fix to extension/feature selection

* briefly return to an old swapchain config

* back to some new sync. using best guess last fence

* avoid using gl_MeshPrimitivesEXT[i].gl_PrimitiveID - this prevents pulling in fragment-shading-rate SPIRV caps
  • Loading branch information
crocdialer authored Feb 18, 2025
1 parent 77d73fb commit 3601588
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
30 changes: 15 additions & 15 deletions include/vierkant/SwapChain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class SwapChain
* @param num_samples an optional VkSampleCountFlagBits value to request multisampling
* @param use_vsync flag to request vertical synchronisation (cap fps to refresh rate)
*/
SwapChain(DevicePtr device, VkSurfaceKHR surface, VkSampleCountFlagBits num_samples = VK_SAMPLE_COUNT_1_BIT,
SwapChain(DevicePtr device,
VkSurfaceKHR surface,
VkSampleCountFlagBits num_samples = VK_SAMPLE_COUNT_1_BIT,
bool use_vsync = true);

SwapChain(SwapChain &&other) noexcept;
Expand All @@ -59,20 +61,15 @@ class SwapChain
*/
VkResult present();

/**
* @return a reference to the currently provided framebuffer from swapchain
*/
[[nodiscard]] vierkant::Framebuffer &current_framebuffer() { return m_framebuffers[m_current_frame_index]; };

/**
* @return handle for the managed VkSwapchainKHR
*/
[[nodiscard]] VkSwapchainKHR handle() const { return m_swap_chain; }
[[nodiscard]] VkSwapchainKHR handle() const{ return m_swap_chain; }

/**
* @return handle for the device
*/
[[nodiscard]] DevicePtr device() const { return m_device; }
[[nodiscard]] DevicePtr device() const{ return m_device; }

/**
* @return handle for the shared VkRenderPass, used by all contained Framebuffers
Expand All @@ -82,38 +79,41 @@ class SwapChain
/**
* @return a reference for the contained array of Framebuffers
*/
std::vector<vierkant::Framebuffer> &framebuffers() { return m_framebuffers; }
std::vector<vierkant::Framebuffer> &framebuffers(){ return m_framebuffers; }

vierkant::Framebuffer &current_framebuffer(){ return m_framebuffers[m_swapchain_image_index]; }

/**
* @return a reference for array of SwapChain-Images
*/
[[nodiscard]] const std::vector<vierkant::ImagePtr> &images() const { return m_images; }
[[nodiscard]] const std::vector<vierkant::ImagePtr> &images() const{ return m_images; }

/**
* @return the VkExtent2D (size) of the SwapChain-Images
*/
[[nodiscard]] const VkExtent2D &extent() const { return m_extent; }
[[nodiscard]] const VkExtent2D &extent() const{ return m_extent; }

/**
* @return the VkSampleCountFlagBits stating the number of samples per pixel (MSAA)
*/
[[nodiscard]] VkSampleCountFlagBits sample_count() const { return m_num_samples; }
[[nodiscard]] VkSampleCountFlagBits sample_count() const{ return m_num_samples; }

/**
* @return a flag indicating if vertical synchronization is used
*/
[[nodiscard]] bool v_sync() const { return m_use_v_sync; }
[[nodiscard]] bool v_sync() const{ return m_use_v_sync; }

/**
* @return the current image index inside the SwapChain
*/
[[nodiscard]] uint32_t image_index() const { return m_swapchain_image_index; }
[[nodiscard]] uint32_t image_index() const{ return m_swapchain_image_index; }

friend void swap(SwapChain &lhs, SwapChain &rhs);

inline explicit operator bool() const { return static_cast<bool>(m_swap_chain); };
inline explicit operator bool() const{ return static_cast<bool>(m_swap_chain); };

private:

/**
* @brief sync_objects_t is a helper struct to bundle synchronization data for the SwapChain
*/
Expand Down
4 changes: 2 additions & 2 deletions shaders/pbr/g_buffer.mesh
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ void main()

gl_PrimitiveTriangleIndicesEXT[i] = uvec3(a, b, c);

// keep track of primitive-id // TODO: nice try, but no
gl_MeshPrimitivesEXT[i].gl_PrimitiveID = int(base_index / 3);
// // keep track of primitive-id // TODO: nice try, but no
// gl_MeshPrimitivesEXT[i].gl_PrimitiveID = int(base_index / 3);
#if CULLING
bool culled = false;

Expand Down
6 changes: 3 additions & 3 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Device::Device(const create_info_t &create_info) : m_physical_device(create_info
device_features_12.pNext = &device_features_13;

void **pNext = &device_features_13.pNext;
auto update_pnext = [&pNext, &extensions](const auto &feature_struct, const char *ext_name) {
auto update_pnext = [&pNext, &extensions](const auto &feature_struct, std::string_view ext_name) {
if(crocore::contains(extensions, ext_name))
{
*pNext = (void *) &feature_struct;
Expand Down Expand Up @@ -306,10 +306,10 @@ Device::Device(const create_info_t &create_info) : m_physical_device(create_info
descriptor_buffer_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT;
update_pnext(descriptor_buffer_features, VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME);

//------------------------------------ VK_KHR_fragment_shader_barycentric ----------------------------------------------------
//------------------------------------ VK_KHR_fragment_shader_barycentric ------------------------------------------
VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR barycentric_features = {};
barycentric_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR;
update_pnext(barycentric_features, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
update_pnext(barycentric_features, VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME);

//------------------------------------------------------------------------------------------------------------------
*pNext = create_info.create_device_pNext;
Expand Down
2 changes: 2 additions & 0 deletions src/SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ SwapChain::acquire_image_result_t SwapChain::acquire_next_image(uint64_t timeout
{
acquire_image_result_t ret = {};

m_framebuffers[m_current_frame_index].wait_fence();

ret.image_available = m_sync_objects[m_current_frame_index].image_available;
ret.render_finished = m_sync_objects[m_current_frame_index].render_finished;
ret.result = vkAcquireNextImageKHR(m_device->handle(), m_swap_chain, timeout, ret.image_available, VK_NULL_HANDLE,
Expand Down
5 changes: 2 additions & 3 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,12 @@ void Window::draw(std::vector<vierkant::semaphore_submit_info_t> semaphore_infos
{
if(!m_swap_chain) { return; }

auto &framebuffer = swapchain().current_framebuffer();
auto acquire_result = m_swap_chain.acquire_next_image();
auto &framebuffer = swapchain().framebuffers()[acquire_result.image_index];

// wait for prior frame to finish
framebuffer.wait_fence();

auto acquire_result = m_swap_chain.acquire_next_image();

if(acquire_result.result != VK_SUCCESS)
{
create_swapchain(m_swap_chain.device(), m_swap_chain.sample_count(), m_swap_chain.v_sync());
Expand Down

0 comments on commit 3601588

Please sign in to comment.