mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-21 17:55:40 -04:00
HostDisplay: Use streaming for sw renderer display
This commit is contained in:
@ -19,8 +19,13 @@ std::unique_ptr<Vulkan::Context> g_vulkan_context;
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
enum : u32
|
||||
{
|
||||
TEXTURE_BUFFER_SIZE = 16 * 1024 * 1024,
|
||||
};
|
||||
|
||||
Context::Context(VkInstance instance, VkPhysicalDevice physical_device, bool owns_device)
|
||||
: m_instance(instance), m_physical_device(physical_device), m_owns_device(owns_device)
|
||||
: m_instance(instance), m_physical_device(physical_device)
|
||||
{
|
||||
// Read device physical memory properties, we need it for allocating buffers
|
||||
vkGetPhysicalDeviceProperties(physical_device, &m_device_properties);
|
||||
@ -37,29 +42,7 @@ Context::Context(VkInstance instance, VkPhysicalDevice physical_device, bool own
|
||||
std::max(m_device_properties.limits.optimalBufferCopyRowPitchAlignment, static_cast<VkDeviceSize>(1));
|
||||
}
|
||||
|
||||
Context::~Context()
|
||||
{
|
||||
StopPresentThread();
|
||||
|
||||
if (m_device != VK_NULL_HANDLE)
|
||||
WaitForGPUIdle();
|
||||
|
||||
DestroyRenderPassCache();
|
||||
DestroyGlobalDescriptorPool();
|
||||
DestroyCommandBuffers();
|
||||
|
||||
if (m_owns_device && m_device != VK_NULL_HANDLE)
|
||||
vkDestroyDevice(m_device, nullptr);
|
||||
|
||||
if (m_debug_messenger_callback != VK_NULL_HANDLE)
|
||||
DisableDebugUtils();
|
||||
|
||||
if (m_owns_device)
|
||||
{
|
||||
vkDestroyInstance(m_instance, nullptr);
|
||||
Vulkan::UnloadVulkanLibrary();
|
||||
}
|
||||
}
|
||||
Context::~Context() = default;
|
||||
|
||||
bool Context::CheckValidationLayerAvailablility()
|
||||
{
|
||||
@ -369,6 +352,7 @@ bool Context::Create(std::string_view gpu_name, const WindowInfo* wi, std::uniqu
|
||||
// Attempt to create the device.
|
||||
if (!g_vulkan_context->CreateDevice(surface, enable_validation_layer, nullptr, 0, nullptr, 0, nullptr) ||
|
||||
!g_vulkan_context->CreateGlobalDescriptorPool() || !g_vulkan_context->CreateCommandBuffers() ||
|
||||
!g_vulkan_context->CreateTextureStreamBuffer() ||
|
||||
(enable_surface && (*out_swap_chain = SwapChain::Create(wi_copy, surface, true)) == nullptr))
|
||||
{
|
||||
// Since we are destroying the instance, we're also responsible for destroying the surface.
|
||||
@ -415,6 +399,29 @@ bool Context::CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice g
|
||||
void Context::Destroy()
|
||||
{
|
||||
AssertMsg(g_vulkan_context, "Has context");
|
||||
|
||||
g_vulkan_context->StopPresentThread();
|
||||
|
||||
if (g_vulkan_context->m_device != VK_NULL_HANDLE)
|
||||
g_vulkan_context->WaitForGPUIdle();
|
||||
|
||||
g_vulkan_context->m_texture_upload_buffer.Destroy(false);
|
||||
|
||||
g_vulkan_context->DestroyRenderPassCache();
|
||||
g_vulkan_context->DestroyGlobalDescriptorPool();
|
||||
g_vulkan_context->DestroyCommandBuffers();
|
||||
|
||||
if (g_vulkan_context->m_device != VK_NULL_HANDLE)
|
||||
vkDestroyDevice(g_vulkan_context->m_device, nullptr);
|
||||
|
||||
if (g_vulkan_context->m_debug_messenger_callback != VK_NULL_HANDLE)
|
||||
g_vulkan_context->DisableDebugUtils();
|
||||
|
||||
if (g_vulkan_context->m_instance != VK_NULL_HANDLE)
|
||||
vkDestroyInstance(g_vulkan_context->m_instance, nullptr);
|
||||
|
||||
Vulkan::UnloadVulkanLibrary();
|
||||
|
||||
g_vulkan_context.reset();
|
||||
}
|
||||
|
||||
@ -785,6 +792,17 @@ void Context::DestroyGlobalDescriptorPool()
|
||||
}
|
||||
}
|
||||
|
||||
bool Context::CreateTextureStreamBuffer()
|
||||
{
|
||||
if (!m_texture_upload_buffer.Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, TEXTURE_BUFFER_SIZE))
|
||||
{
|
||||
Log_ErrorPrintf("Failed to allocate texture upload buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::DestroyRenderPassCache()
|
||||
{
|
||||
for (auto& it : m_render_pass_cache)
|
||||
@ -1105,7 +1123,8 @@ void Context::ActivateCommandBuffer(u32 index)
|
||||
{
|
||||
const double ns_diff =
|
||||
(timestamps[1] - timestamps[0]) * static_cast<double>(m_device_properties.limits.timestampPeriod);
|
||||
m_accumulated_gpu_time = static_cast<float>(static_cast<double>(m_accumulated_gpu_time) + (ns_diff / 1000000.0));
|
||||
m_accumulated_gpu_time =
|
||||
static_cast<float>(static_cast<double>(m_accumulated_gpu_time) + (ns_diff / 1000000.0));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "../types.h"
|
||||
#include "loader.h"
|
||||
#include "stream_buffer.h"
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
@ -91,22 +92,31 @@ public:
|
||||
ALWAYS_INLINE bool SupportsDualSourceBlend() const { return m_device_features.dualSrcBlend == VK_TRUE; }
|
||||
|
||||
// Helpers for getting constants
|
||||
ALWAYS_INLINE VkDeviceSize GetUniformBufferAlignment() const
|
||||
ALWAYS_INLINE u32 GetUniformBufferAlignment() const
|
||||
{
|
||||
return m_device_properties.limits.minUniformBufferOffsetAlignment;
|
||||
return static_cast<u32>(m_device_properties.limits.minUniformBufferOffsetAlignment);
|
||||
}
|
||||
ALWAYS_INLINE VkDeviceSize GetTexelBufferAlignment() const
|
||||
ALWAYS_INLINE u32 GetTexelBufferAlignment() const
|
||||
{
|
||||
return m_device_properties.limits.minTexelBufferOffsetAlignment;
|
||||
return static_cast<u32>(m_device_properties.limits.minTexelBufferOffsetAlignment);
|
||||
}
|
||||
ALWAYS_INLINE VkDeviceSize GetStorageBufferAlignment() const
|
||||
ALWAYS_INLINE u32 GetStorageBufferAlignment() const
|
||||
{
|
||||
return m_device_properties.limits.minStorageBufferOffsetAlignment;
|
||||
return static_cast<u32>(m_device_properties.limits.minStorageBufferOffsetAlignment);
|
||||
}
|
||||
ALWAYS_INLINE VkDeviceSize GetBufferImageGranularity() const
|
||||
ALWAYS_INLINE u32 GetBufferImageGranularity() const
|
||||
{
|
||||
return m_device_properties.limits.bufferImageGranularity;
|
||||
return static_cast<u32>(m_device_properties.limits.bufferImageGranularity);
|
||||
}
|
||||
ALWAYS_INLINE u32 GetBufferCopyOffsetAlignment() const
|
||||
{
|
||||
return static_cast<u32>(m_device_properties.limits.optimalBufferCopyOffsetAlignment);
|
||||
}
|
||||
ALWAYS_INLINE u32 GetBufferCopyRowPitchAlignment() const
|
||||
{
|
||||
return static_cast<u32>(m_device_properties.limits.optimalBufferCopyRowPitchAlignment);
|
||||
}
|
||||
ALWAYS_INLINE u32 GetMaxImageDimension2D() const { return m_device_properties.limits.maxImageDimension2D; }
|
||||
|
||||
// Finds a memory type index for the specified memory properties and the bits returned by
|
||||
// vkGetImageMemoryRequirements
|
||||
@ -125,6 +135,7 @@ public:
|
||||
// is submitted, after that you should call these functions again.
|
||||
ALWAYS_INLINE VkDescriptorPool GetGlobalDescriptorPool() const { return m_global_descriptor_pool; }
|
||||
ALWAYS_INLINE VkCommandBuffer GetCurrentCommandBuffer() const { return m_current_command_buffer; }
|
||||
ALWAYS_INLINE StreamBuffer& GetTextureUploadBuffer() { return m_texture_upload_buffer; }
|
||||
ALWAYS_INLINE VkDescriptorPool GetCurrentDescriptorPool() const
|
||||
{
|
||||
return m_frame_resources[m_current_frame].descriptor_pool;
|
||||
@ -198,6 +209,7 @@ private:
|
||||
void DestroyCommandBuffers();
|
||||
bool CreateGlobalDescriptorPool();
|
||||
void DestroyGlobalDescriptorPool();
|
||||
bool CreateTextureStreamBuffer();
|
||||
void DestroyRenderPassCache();
|
||||
|
||||
void ActivateCommandBuffer(u32 index);
|
||||
@ -247,7 +259,7 @@ private:
|
||||
u64 m_completed_fence_counter = 0;
|
||||
u32 m_current_frame;
|
||||
|
||||
bool m_owns_device = false;
|
||||
StreamBuffer m_texture_upload_buffer;
|
||||
|
||||
std::atomic_bool m_last_present_failed{false};
|
||||
std::atomic_bool m_present_done{true};
|
||||
|
Reference in New Issue
Block a user