Skip to content

Commit

Permalink
vk: Clean up around vkQueueSubmit handling
Browse files Browse the repository at this point in the history
- Explicitly declare one version for CB flush and the other for Async flush
- Always flush descriptors on CB flush in case of page fault handling.
  Other threads other than offloader can also enter the method and require normal flow.
- Fix overlapping interrupt IDs.
- Minor formatting fixes
  • Loading branch information
kd-11 committed Sep 28, 2021
1 parent 3d49976 commit a105599
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/Common/bitfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace rsx

void clear()
{
m_data.store(0);
m_data.release(0);
}
};
}
31 changes: 21 additions & 10 deletions rpcs3/Emu/RSX/VK/VKCommandStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ namespace vk
g_submit_mutex.unlock();
}

FORCE_INLINE
static void queue_submit_impl(VkQueue queue, const VkSubmitInfo* info, fence* pfence)
{
acquire_global_submit_lock();
vkQueueSubmit(queue, 1, info, pfence->handle);
release_global_submit_lock();

// Signal fence
pfence->signal_flushed();
}

void queue_submit(VkQueue queue, const VkSubmitInfo* info, fence* pfence, VkBool32 flush)
{
if (rsx::get_current_renderer()->is_current_thread())
{
vk::descriptors::flush();
}
// Access to this method must be externally synchronized.
// Offloader is guaranteed to never call this for async flushes.
vk::descriptors::flush();

if (!flush && g_cfg.video.multithreaded_rsx)
{
Expand All @@ -37,12 +47,13 @@ namespace vk
}
else
{
acquire_global_submit_lock();
vkQueueSubmit(queue, 1, info, pfence->handle);
release_global_submit_lock();

// Signal fence
pfence->signal_flushed();
queue_submit_impl(queue, info, pfence);
}
}

void queue_submit(const vk::submit_packet* packet)
{
// Flush-only version used by asynchronous submit processing (MTRSX)
queue_submit_impl(packet->queue, &packet->submit_info, packet->pfence);
}
}
14 changes: 7 additions & 7 deletions rpcs3/Emu/RSX/VK/VKGSRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,9 @@ bool VKGSRender::on_access_violation(u32 address, bool is_writing)
}

bool has_queue_ref = false;
if (!is_current_thread())
if (!is_current_thread()) [[likely]]
{
//Always submit primary cb to ensure state consistency (flush pending changes such as image transitions)
// Always submit primary cb to ensure state consistency (flush pending changes such as image transitions)
vm::temporary_unlock();

std::lock_guard lock(m_flush_queue_mutex);
Expand All @@ -777,21 +777,21 @@ bool VKGSRender::on_access_violation(u32 address, bool is_writing)
rsx_log.error("Fault in uninterruptible code!");
}

//Flush primary cb queue to sync pending changes (e.g image transitions!)
// Flush primary cb queue to sync pending changes (e.g image transitions!)
flush_command_queue();
}

if (has_queue_ref)
{
//Wait for the RSX thread to process request if it hasn't already
// Wait for the RSX thread to process request if it hasn't already
m_flush_requests.producer_wait();
}

m_texture_cache.flush_all(m_secondary_command_buffer, result);

if (has_queue_ref)
{
//Release RSX thread
// Release RSX thread
m_flush_requests.remove_one();
}
}
Expand Down Expand Up @@ -2340,8 +2340,8 @@ void VKGSRender::renderctl(u32 request_code, void* args)
{
case vk::rctrl_queue_submit:
{
auto packet = reinterpret_cast<vk::submit_packet*>(args);
vk::queue_submit(packet->queue, &packet->submit_info, packet->pfence, VK_TRUE);
const auto packet = reinterpret_cast<vk::submit_packet*>(args);
vk::queue_submit(packet);
free(packet);
break;
}
Expand Down
18 changes: 9 additions & 9 deletions rpcs3/Emu/RSX/VK/VKHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ namespace vk
class image;
class instance;
class render_device;
struct submit_packet;

//VkAllocationCallbacks default_callbacks();
enum runtime_state
{
uninterruptible = 1,
heap_dirty = 2,
heap_changed = 3
heap_dirty = 2,
heap_changed = 4,
};

const vk::render_device *get_current_renderer();
void set_current_renderer(const vk::render_device &device);

//Compatibility workarounds
// Compatibility workarounds
bool emulate_primitive_restart(rsx::primitive_type type);
bool sanitize_fp_values();
bool fence_reset_disabled();
Expand All @@ -54,7 +54,7 @@ namespace vk
// Sync helpers around vkQueueSubmit
void acquire_global_submit_lock();
void release_global_submit_lock();
void queue_submit(VkQueue queue, const VkSubmitInfo* info, fence* pfence, VkBool32 flush = VK_FALSE);
void queue_submit(const vk::submit_packet* packet);

template<class T>
T* get_compute_task();
Expand All @@ -64,20 +64,20 @@ namespace vk

enum image_upload_options
{
upload_contents_async = 1,
upload_contents_async = 1,
initialize_image_layout = 2,
preserve_image_layout = 4,
preserve_image_layout = 4,

// meta-flags
upload_contents_inline = 0,
upload_contents_inline = 0,
upload_heap_align_default = 0
};

void upload_image(const vk::command_buffer& cmd, vk::image* dst_image,
const std::vector<rsx::subresource_layout>& subresource_layout, int format, bool is_swizzled, u16 layer_count,
VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align, rsx::flags32_t image_setup_flags);

//Other texture management helpers
// Other texture management helpers
void copy_image_to_buffer(VkCommandBuffer cmd, const vk::image* src, const vk::buffer* dst, const VkBufferImageCopy& region, bool swap_bytes = false);
void copy_buffer_to_image(VkCommandBuffer cmd, const vk::buffer* src, const vk::image* dst, const VkBufferImageCopy& region);
u64 calculate_working_buffer_size(u64 base_size, VkImageAspectFlags aspect);
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/VK/vkutils/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace vk
{
// This queue flushing method to be implemented by the backend as behavior depends on config
void queue_submit(VkQueue queue, const VkSubmitInfo* info, fence* pfence, VkBool32 flush = VK_FALSE);
void queue_submit(VkQueue queue, const VkSubmitInfo* info, fence* pfence, VkBool32 flush);

void command_pool::create(vk::render_device& dev, u32 queue_family_id)
{
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/VK/vkutils/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace vk
public:
enum access_type_hint
{
flush_only, //Only to be submitted/opened/closed via command flush
all //Auxiliary, can be submitted/opened/closed at any time
flush_only, // Only to be submitted/opened/closed via command flush
all // Auxiliary, can be submitted/opened/closed at any time
}
access_hint = flush_only;

Expand Down

0 comments on commit a105599

Please sign in to comment.