diff --git a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h index 45be14d0f..ca6fbf353 100644 --- a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h +++ b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h @@ -503,7 +503,7 @@ void kinc_internal_restore_render_target(kinc_g5_command_list_t *list, struct ki scissor.offset.y = 0; vkCmdSetScissor(list->impl._buffer, 0, 1, &scissor); - if (onBackBuffer) { + if (onBackBuffer && in_render_pass) { return; } @@ -542,6 +542,13 @@ void kinc_internal_restore_render_target(kinc_g5_command_list_t *list, struct ki } void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count) { + for (int i = 0; i < count; ++i) { + currentRenderTargets[i] = targets[i]; + } + for (int i = count; i < 8; ++i) { + currentRenderTargets[i] = NULL; + } + if (targets[0]->framebuffer_index >= 0) { kinc_internal_restore_render_target(list, targets[0]); return; @@ -549,12 +556,6 @@ void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struc endPass(list); - for (int i = 0; i < count; ++i) { - currentRenderTargets[i] = targets[i]; - } - for (int i = count; i < 8; ++i) { - currentRenderTargets[i] = NULL; - } onBackBuffer = false; VkClearValue clear_values[9]; @@ -879,10 +880,15 @@ void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_text } void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) { - vulkanSamplers[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler; + if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { + vulkanSamplers[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler; + } } -void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {} +void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { + vulkanTextures[unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]] = texture; + vulkanRenderTargets[unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]] = NULL; +} void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face) {} @@ -919,8 +925,13 @@ void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_ } void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) { - endPass(list); + if (in_render_pass) { + vkCmdEndRenderPass(list->impl._buffer); + in_render_pass = false; + } + vkCmdDispatch(list->impl._buffer, x, y, z); + int render_target_count = 0; for (int i = 0; i < 8; ++i) { if (currentRenderTargets[i] == NULL) { @@ -928,5 +939,7 @@ void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, in } ++render_target_count; } - kinc_g5_command_list_set_render_targets(list, currentRenderTargets, render_target_count); + if (render_target_count > 0) { + kinc_g5_command_list_set_render_targets(list, currentRenderTargets, render_target_count); + } } diff --git a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h index a86555de2..3c26676e0 100644 --- a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h +++ b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h @@ -215,6 +215,7 @@ kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_s for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { unit.stages[i] = -1; } + unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] = 0; /*kinc_internal_hash_index_t *compute_unit = findComputeTextureUnit(shader->impl.textures, hash); if (compute_unit == NULL) { #ifndef NDEBUG diff --git a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h index af402d62b..fb67369b3 100644 --- a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h +++ b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h @@ -910,7 +910,7 @@ VkDescriptorSet getDescriptorSet() { } texture_count++; } - tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; } VkWriteDescriptorSet writes[18]; @@ -1021,8 +1021,8 @@ static VkDescriptorSet get_compute_descriptor_set() { int texture_count = 0; for (int i = 0; i < 16; ++i) { if (vulkanTextures[i] != NULL) { - assert(vulkanSamplers[i] != VK_NULL_HANDLE); - tex_desc[i].sampler = vulkanSamplers[i]; + // assert(vulkanSamplers[i] != VK_NULL_HANDLE); + tex_desc[i].sampler = VK_NULL_HANDLE; // vulkanSamplers[i]; tex_desc[i].imageView = vulkanTextures[i]->impl.texture.view; texture_count++; } @@ -1037,7 +1037,7 @@ static VkDescriptorSet get_compute_descriptor_set() { } texture_count++; } - tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; } VkWriteDescriptorSet writes[18]; @@ -1062,7 +1062,7 @@ static VkDescriptorSet get_compute_descriptor_set() { writes[i].dstSet = descriptor_set; writes[i].dstBinding = i; writes[i].descriptorCount = 1; - writes[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + writes[i].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; writes[i].pImageInfo = &tex_desc[i - 2]; } diff --git a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h index 0fac5c956..33e9e0930 100644 --- a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h +++ b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h @@ -235,7 +235,8 @@ void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *i if ((props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) && !use_staging_buffer) { // Device can texture using linear textures prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR, - VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format); + VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, + tex_format); flush_init_cmd(); } @@ -247,8 +248,8 @@ void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *i prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &staging_texture, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format); prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &texture->impl.texture, VK_IMAGE_TILING_OPTIMAL, - (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture->impl.deviceSize, - tex_format); + (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + &texture->impl.deviceSize, tex_format); set_image_layout(staging_texture.image, VK_IMAGE_ASPECT_COLOR_BIT, staging_texture.imageLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); set_image_layout(texture->impl.texture.image, VK_IMAGE_ASPECT_COLOR_BIT, texture->impl.texture.imageLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); @@ -315,8 +316,8 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin vkGetPhysicalDeviceFormatProperties(vk_ctx.gpu, tex_format, &props); // Device can texture using linear textures - prepare_texture_image(NULL, (uint32_t)width, (uint32_t)height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format); + prepare_texture_image(NULL, (uint32_t)width, (uint32_t)height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR, + VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format); flush_init_cmd();