Skip to content

Commit

Permalink
+ Added support for timeline semaphores, and vulkan device now create…
Browse files Browse the repository at this point in the history
…s them for each renderer, however they are currently unused
  • Loading branch information
harrand committed Dec 8, 2022
1 parent dff57be commit c146f3b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 31 deletions.
14 changes: 2 additions & 12 deletions src/tz/gl/impl/backend/vk2/features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,10 @@ namespace tz::gl::vk2

namespace detail
{
constexpr VkPhysicalDeviceDescriptorIndexingFeatures empty_descriptor_indexing_features()
{
VkPhysicalDeviceDescriptorIndexingFeatures feats{};
feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES;
feats.pNext = nullptr;
return feats;
}

constexpr VkPhysicalDeviceVulkan12Features empty_12_features(VkPhysicalDeviceDescriptorIndexingFeatures& next)
constexpr VkPhysicalDeviceVulkan12Features empty_12_features()
{
VkPhysicalDeviceVulkan12Features feats{};
feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
feats.pNext = &next;
return feats;
}

Expand All @@ -63,8 +54,7 @@ namespace tz::gl::vk2

struct DeviceFeatureInfo
{
VkPhysicalDeviceDescriptorIndexingFeatures descriptor_indexing_features = empty_descriptor_indexing_features();
VkPhysicalDeviceVulkan12Features features12 = empty_12_features(descriptor_indexing_features);
VkPhysicalDeviceVulkan12Features features12 = empty_12_features();
VkPhysicalDeviceFeatures2 features = empty_features2(features12);
};
}
Expand Down
28 changes: 14 additions & 14 deletions src/tz/gl/impl/backend/vk2/hardware/physical_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ namespace tz::gl::vk2
{
ret |= DeviceFeature::MultiDrawIndirect;
}
if(features.descriptor_indexing_features.descriptorBindingStorageImageUpdateAfterBind
&& features.descriptor_indexing_features.descriptorBindingStorageBufferUpdateAfterBind
&& features.descriptor_indexing_features.descriptorBindingSampledImageUpdateAfterBind
&& features.descriptor_indexing_features.descriptorBindingUpdateUnusedWhilePending
&& features.descriptor_indexing_features.descriptorBindingPartiallyBound
&& features.descriptor_indexing_features.descriptorBindingVariableDescriptorCount
&& features.descriptor_indexing_features.runtimeDescriptorArray)
if(features.features12.descriptorBindingStorageImageUpdateAfterBind
&& features.features12.descriptorBindingStorageBufferUpdateAfterBind
&& features.features12.descriptorBindingSampledImageUpdateAfterBind
&& features.features12.descriptorBindingUpdateUnusedWhilePending
&& features.features12.descriptorBindingPartiallyBound
&& features.features12.descriptorBindingVariableDescriptorCount
&& features.features12.runtimeDescriptorArray)
{
ret |= DeviceFeature::BindlessDescriptors;
}
Expand Down Expand Up @@ -94,13 +94,13 @@ namespace tz::gl::vk2

if(feature_field.contains(DeviceFeature::BindlessDescriptors))
{
info.descriptor_indexing_features.descriptorBindingStorageImageUpdateAfterBind = VK_TRUE;
info.descriptor_indexing_features.descriptorBindingStorageBufferUpdateAfterBind = VK_TRUE;
info.descriptor_indexing_features.descriptorBindingSampledImageUpdateAfterBind = VK_TRUE;
info.descriptor_indexing_features.descriptorBindingUpdateUnusedWhilePending = VK_TRUE;
info.descriptor_indexing_features.descriptorBindingPartiallyBound = VK_TRUE;
info.descriptor_indexing_features.descriptorBindingVariableDescriptorCount = VK_TRUE;
info.descriptor_indexing_features.runtimeDescriptorArray = VK_TRUE;
info.features12.descriptorBindingStorageImageUpdateAfterBind = VK_TRUE;
info.features12.descriptorBindingStorageBufferUpdateAfterBind = VK_TRUE;
info.features12.descriptorBindingSampledImageUpdateAfterBind = VK_TRUE;
info.features12.descriptorBindingUpdateUnusedWhilePending = VK_TRUE;
info.features12.descriptorBindingPartiallyBound = VK_TRUE;
info.features12.descriptorBindingVariableDescriptorCount = VK_TRUE;
info.features12.runtimeDescriptorArray = VK_TRUE;
}
return info;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tz/gl/impl/backend/vk2/logical_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace tz::gl::vk2
});
#endif
detail::DeviceFeatureInfo features = detail::from_feature_field(this->enabled_features);
features.features.pNext = &features.descriptor_indexing_features;
features.features.pNext = &features.features12;
create.pEnabledFeatures = nullptr;
create.pNext = &features.features;
VkResult res = vkCreateDevice(this->physical_device.native(), &create, nullptr, &this->dev);
Expand Down
19 changes: 18 additions & 1 deletion src/tz/gl/impl/backend/vk2/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace tz::gl::vk2
device(nullptr){}

TimelineSemaphore::TimelineSemaphore(const LogicalDevice& device, std::uint64_t value):
BinarySemaphore()
BinarySemaphore(device)
{
hdk::assert(TimelineSemaphore::supported(device), "TimelineSemaphores are not supported by the LogicalDevice, but tried to create one. Please submit a bug report.");
VkSemaphoreTypeCreateInfo create_type
Expand Down Expand Up @@ -108,6 +108,23 @@ namespace tz::gl::vk2
break;
}
}

TimelineSemaphore::TimelineSemaphore(TimelineSemaphore&& move)
{
*this = std::move(move);
}

TimelineSemaphore::~TimelineSemaphore()
{
BinarySemaphore::~BinarySemaphore();
}

TimelineSemaphore& TimelineSemaphore::operator=(TimelineSemaphore&& rhs)
{
std::swap(this->sem, rhs.sem);
std::swap(this->device, rhs.device);
return *this;
}

void TimelineSemaphore::signal(std::uint64_t value)
{
Expand Down
2 changes: 2 additions & 0 deletions src/tz/gl/impl/backend/vk2/semaphore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace tz::gl::vk2
TimelineSemaphore(const TimelineSemaphore& copy) = delete;
TimelineSemaphore(TimelineSemaphore&& move);
~TimelineSemaphore();
TimelineSemaphore& operator=(const TimelineSemaphore&& rhs) = delete;
TimelineSemaphore& operator=(TimelineSemaphore&& rhs);

/**
* Instantaneously set the semaphore to the given value.
Expand Down
33 changes: 31 additions & 2 deletions src/tz/gl/impl/frontend/vk2/device.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "tz/gl/impl/frontend/common/device.hpp"
#if TZ_VULKAN
#include "hdk/profile.hpp"
#include "hdk/debug.hpp"
#include "tz/dbgui/dbgui.hpp"
#include "tz/gl/impl/frontend/common/device.hpp"
#include "tz/gl/impl/frontend/vk2/renderer.hpp"
#include "tz/gl/impl/frontend/vk2/device.hpp"
#include "tz/gl/impl/frontend/vk2/convert.hpp"
Expand Down Expand Up @@ -273,6 +273,7 @@ namespace tz::gl

//--------------------------------------------------------------------------------------------------
DeviceRenderSchedulerVulkan::DeviceRenderSchedulerVulkan(const vk2::LogicalDevice& ldev, std::size_t frame_in_flight_count):
ldev(&ldev),
image_available(),
render_work_done(),
frame_work()
Expand All @@ -295,6 +296,16 @@ namespace tz::gl
}
}

void DeviceRenderSchedulerVulkan::notify_renderer_added()
{
this->renderer_timelines.emplace_back(*this->ldev, 0);
}

void DeviceRenderSchedulerVulkan::notify_renderer_removed(std::size_t renderer_id)
{
this->renderer_timelines.erase(this->renderer_timelines.begin() + renderer_id);
}

std::span<const vk2::BinarySemaphore> DeviceRenderSchedulerVulkan::get_image_signals() const
{
return this->image_available;
Expand All @@ -320,6 +331,16 @@ namespace tz::gl
return this->frame_work;
}

std::span<const vk2::TimelineSemaphore> DeviceRenderSchedulerVulkan::get_renderer_timelines() const
{
return this->renderer_timelines;
}

std::span<vk2::TimelineSemaphore> DeviceRenderSchedulerVulkan::get_renderer_timelines()
{
return this->renderer_timelines;
}

void DeviceRenderSchedulerVulkan::wait_frame_work_complete() const
{
for(const vk2::Fence& fence : this->frame_work)
Expand Down Expand Up @@ -353,6 +374,7 @@ namespace tz::gl
tz::gl::RendererHandle DeviceVulkan::create_renderer(const RendererInfoVulkan& info)
{
HDK_PROFZONE("Vulkan Frontend - Renderer Create (via DeviceVulkan)", 0xFFAAAA00);
this->scheduler.notify_renderer_added();
return DeviceCommon<RendererVulkan>::emplace_renderer(info,
tz::gl::RendererDeviceInfoVulkan{
.device = &this->device,
Expand All @@ -363,6 +385,12 @@ namespace tz::gl
});
}

void DeviceVulkan::destroy_renderer(tz::gl::RendererHandle handle)
{
this->scheduler.notify_renderer_removed(static_cast<std::size_t>(static_cast<hdk::hanval>(handle)));
DeviceCommon<RendererVulkan>::destroy_renderer(handle);
}

ImageFormat DeviceVulkan::get_window_format() const
{
return from_vk2(this->window_storage.get_format());
Expand Down Expand Up @@ -419,7 +447,8 @@ namespace tz::gl
vk2::DeviceFeature::NonSolidFillRasteriser,
vk2::DeviceFeature::TessellationShaders,
vk2::DeviceFeature::VertexPipelineResourceWrite,
vk2::DeviceFeature::FragmentShaderResourceWrite
vk2::DeviceFeature::FragmentShaderResourceWrite,
vk2::DeviceFeature::TimelineSemaphores
};
hdk::assert(pdev.get_supported_features().contains(dev_feats), "One or both of DeviceFeatures 'BindlessDescriptors' and 'ColourBlendLogicalOperations' are not supported by this machine/driver. Please ensure your machine meets the system requirements.");
dev_exts = {vk2::DeviceExtension::Swapchain};
Expand Down
8 changes: 7 additions & 1 deletion src/tz/gl/impl/frontend/vk2/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,22 @@ namespace tz::gl
{
public:
DeviceRenderSchedulerVulkan(const vk2::LogicalDevice& ldev, std::size_t frame_in_flight_count);
void notify_renderer_added();
void notify_renderer_removed(std::size_t renderer_id);
std::span<const vk2::BinarySemaphore> get_image_signals() const;
std::span<vk2::BinarySemaphore> get_image_signals();
std::span<const vk2::BinarySemaphore> get_render_work_signals() const;
std::span<const vk2::Fence> get_frame_fences() const;
std::span<vk2::Fence> get_frame_fences();
std::span<const vk2::TimelineSemaphore> get_renderer_timelines() const;
std::span<vk2::TimelineSemaphore> get_renderer_timelines();
void wait_frame_work_complete() const;
private:
const vk2::LogicalDevice* ldev;
std::vector<vk2::BinarySemaphore> image_available;
std::vector<vk2::BinarySemaphore> render_work_done;
std::vector<vk2::Fence> frame_work;
std::vector<vk2::TimelineSemaphore> renderer_timelines;
};

class DeviceVulkan : public DeviceCommon<RendererVulkan>
Expand All @@ -80,7 +86,7 @@ namespace tz::gl
// Satisfies DeviceType.
tz::gl::RendererHandle create_renderer(const RendererInfoVulkan& info);
using DeviceCommon<RendererVulkan>::get_renderer;
using DeviceCommon<RendererVulkan>::destroy_renderer;
void destroy_renderer(tz::gl::RendererHandle handle);
ImageFormat get_window_format() const;
void dbgui();
const vk2::LogicalDevice& vk_get_logical_device() const;
Expand Down

0 comments on commit c146f3b

Please sign in to comment.