Vulkan fixes for amd

This commit is contained in:
luboslenco
2025-07-29 11:06:50 +02:00
parent e37156109f
commit 6d79d0c267
+15 -5
View File
@@ -23,7 +23,7 @@ static gpu_texture_t *current_textures[GPU_MAX_TEXTURES] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
}; };
static VkSemaphore framebuffer_available_semaphore; static VkSemaphore framebuffer_available_semaphore;
static VkSemaphore rendering_finished_semaphore; static VkSemaphore rendering_finished_semaphores[GPU_FRAMEBUFFER_COUNT];
static VkFence fence; static VkFence fence;
static gpu_pipeline_t *current_pipeline = NULL; static gpu_pipeline_t *current_pipeline = NULL;
static VkViewport current_viewport; static VkViewport current_viewport;
@@ -63,6 +63,7 @@ static VkDeviceMemory readback_mem;
static VkBuffer upload_buffer; static VkBuffer upload_buffer;
static int upload_buffer_size = 0; static int upload_buffer_size = 0;
static VkDeviceMemory upload_mem; static VkDeviceMemory upload_mem;
static bool is_amd = false;
void iron_vulkan_get_instance_extensions(const char **extensions, int *index); void iron_vulkan_get_instance_extensions(const char **extensions, int *index);
VkBool32 iron_vulkan_get_physical_device_presentation_support(VkPhysicalDevice physical_device, uint32_t queue_family_index); VkBool32 iron_vulkan_get_physical_device_presentation_support(VkPhysicalDevice physical_device, uint32_t queue_family_index);
@@ -189,6 +190,9 @@ static bool find_layer(VkLayerProperties *layers, int layer_count, const char *w
static void memory_type_from_properties(uint32_t type_bits, VkFlags requirements_mask, uint32_t *type_index) { static void memory_type_from_properties(uint32_t type_bits, VkFlags requirements_mask, uint32_t *type_index) {
for (uint32_t i = 0; i < 32; i++) { for (uint32_t i = 0; i < 32; i++) {
if ((type_bits & 1) == 1) { if ((type_bits & 1) == 1) {
if (is_amd && memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD) {
continue;
}
if ((memory_properties.memoryTypes[i].propertyFlags & requirements_mask) == requirements_mask) { if ((memory_properties.memoryTypes[i].propertyFlags & requirements_mask) == requirements_mask) {
*type_index = i; *type_index = i;
} }
@@ -760,6 +764,7 @@ void gpu_init_internal(int depth_buffer_bits, bool vsync) {
VkPhysicalDeviceProperties properties; VkPhysicalDeviceProperties properties;
vkGetPhysicalDeviceProperties(gpu, &properties); vkGetPhysicalDeviceProperties(gpu, &properties);
iron_log("Chosen Vulkan device: %s", properties.deviceName); iron_log("Chosen Vulkan device: %s", properties.deviceName);
is_amd = properties.vendorID == 0x1002;
free(physical_devices); free(physical_devices);
} }
else { else {
@@ -945,7 +950,9 @@ void gpu_init_internal(int depth_buffer_bits, bool vsync) {
}; };
vkCreateSemaphore(device, &sem_info, NULL, &framebuffer_available_semaphore); vkCreateSemaphore(device, &sem_info, NULL, &framebuffer_available_semaphore);
vkCreateSemaphore(device, &sem_info, NULL, &rendering_finished_semaphore); for (uint32_t i = 0; i < GPU_FRAMEBUFFER_COUNT; i++) {
vkCreateSemaphore(device, &sem_info, NULL, &rendering_finished_semaphores[i]);
}
window_depth_bits = depth_buffer_bits; window_depth_bits = depth_buffer_bits;
window_vsynced = vsync; window_vsynced = vsync;
@@ -1142,6 +1149,10 @@ void gpu_end_internal() {
current_render_targets[i] == &framebuffers[framebuffer_index] ? GPU_TEXTURE_STATE_PRESENT : GPU_TEXTURE_STATE_SHADER_RESOURCE); current_render_targets[i] == &framebuffers[framebuffer_index] ? GPU_TEXTURE_STATE_PRESENT : GPU_TEXTURE_STATE_SHADER_RESOURCE);
} }
current_render_targets_count = 0; current_render_targets_count = 0;
if (is_amd) {
gpu_execute_and_wait(); ////
}
} }
void gpu_wait() { void gpu_wait() {
@@ -1197,7 +1208,7 @@ void gpu_present_internal() {
.commandBufferCount = 1, .commandBufferCount = 1,
.pCommandBuffers = &command_buffer, .pCommandBuffers = &command_buffer,
.signalSemaphoreCount = 1, .signalSemaphoreCount = 1,
.pSignalSemaphores = &rendering_finished_semaphore, .pSignalSemaphores = &rendering_finished_semaphores[framebuffer_index],
}; };
VkSemaphore wait_semaphores[1] = {framebuffer_available_semaphore}; VkSemaphore wait_semaphores[1] = {framebuffer_available_semaphore};
@@ -1213,7 +1224,7 @@ void gpu_present_internal() {
.swapchainCount = 1, .swapchainCount = 1,
.pSwapchains = &window_swapchain, .pSwapchains = &window_swapchain,
.pImageIndices = &framebuffer_index, .pImageIndices = &framebuffer_index,
.pWaitSemaphores = &rendering_finished_semaphore, .pWaitSemaphores = &rendering_finished_semaphores[framebuffer_index],
.waitSemaphoreCount = 1, .waitSemaphoreCount = 1,
}; };
vkQueuePresentKHR(queue, &present); vkQueuePresentKHR(queue, &present);
@@ -1415,7 +1426,6 @@ void gpu_set_texture(int unit, gpu_texture_t *texture) {
} }
void gpu_pipeline_destroy(gpu_pipeline_t *pipeline) { void gpu_pipeline_destroy(gpu_pipeline_t *pipeline) {
gpu_execute_and_wait(); ////
vkDestroyPipeline(device, pipeline->impl.pipeline, NULL); vkDestroyPipeline(device, pipeline->impl.pipeline, NULL);
vkDestroyPipelineLayout(device, pipeline->impl.pipeline_layout, NULL); vkDestroyPipelineLayout(device, pipeline->impl.pipeline_layout, NULL);
} }