mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-03 08:10:52 +00:00
Merge pull request #3302 from Themaister/master
Vulkan: Mipmapping, LUT in shader support, Mipmapped FBOs, bugfixes
This commit is contained in:
commit
742bf656dc
@ -265,6 +265,18 @@ void vulkan_sync_texture_to_cpu(vk_t *vk, const struct vk_texture *tex)
|
||||
vkInvalidateMappedMemoryRanges(vk->context->device, 1, &range);
|
||||
}
|
||||
|
||||
static unsigned vulkan_num_miplevels(unsigned width, unsigned height)
|
||||
{
|
||||
unsigned size = MAX(width, height);
|
||||
unsigned levels = 0;
|
||||
while (size)
|
||||
{
|
||||
levels++;
|
||||
size >>= 1;
|
||||
}
|
||||
return levels;
|
||||
}
|
||||
|
||||
struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
struct vk_texture *old,
|
||||
unsigned width, unsigned height,
|
||||
@ -284,6 +296,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
VkCommandBufferAllocateInfo cmd_info = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO };
|
||||
VkSubmitInfo submit_info = { VK_STRUCTURE_TYPE_SUBMIT_INFO };
|
||||
VkCommandBufferBeginInfo begin_info = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
|
||||
unsigned i;
|
||||
|
||||
memset(&tex, 0, sizeof(tex));
|
||||
|
||||
@ -292,8 +305,19 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
info.extent.width = width;
|
||||
info.extent.height = height;
|
||||
info.extent.depth = 1;
|
||||
info.mipLevels = 1;
|
||||
info.arrayLayers = 1;
|
||||
|
||||
/* For simplicity, always build mipmaps for
|
||||
* static textures, samplers can be used to enable it dynamically.
|
||||
*/
|
||||
if (type == VULKAN_TEXTURE_STATIC)
|
||||
{
|
||||
info.mipLevels = vulkan_num_miplevels(width, height);
|
||||
tex.mipmap = true;
|
||||
}
|
||||
else
|
||||
info.mipLevels = 1;
|
||||
|
||||
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
if (type == VULKAN_TEXTURE_STREAMED)
|
||||
@ -317,7 +341,9 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
case VULKAN_TEXTURE_STATIC:
|
||||
retro_assert(initial && "Static textures must have initial data.\n");
|
||||
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
break;
|
||||
|
||||
@ -462,7 +488,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
view.components.a = VK_COMPONENT_SWIZZLE_A;
|
||||
}
|
||||
view.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
view.subresourceRange.levelCount = 1;
|
||||
view.subresourceRange.levelCount = info.mipLevels;
|
||||
view.subresourceRange.layerCount = 1;
|
||||
|
||||
vkCreateImageView(device, &view, NULL, &tex.view);
|
||||
@ -526,8 +552,13 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
VK_PIPELINE_STAGE_HOST_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
|
||||
/* If doing mipmapping on upload, keep in general so we can easily do transfers to
|
||||
* and transfers from the images without having to
|
||||
* mess around with lots of extra transitions at per-level granularity.
|
||||
*/
|
||||
vulkan_image_layout_transition(vk, staging, tex.image,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
tex.mipmap ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
0, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
@ -542,16 +573,69 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
|
||||
vkCmdCopyImage(staging,
|
||||
tmp.image, VK_IMAGE_LAYOUT_GENERAL,
|
||||
tex.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
tex.image,
|
||||
tex.mipmap ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
1, ®ion);
|
||||
|
||||
vulkan_image_layout_transition(vk, staging, tex.image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_SHADER_READ_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
if (tex.mipmap)
|
||||
{
|
||||
for (i = 1; i < info.mipLevels; i++)
|
||||
{
|
||||
VkImageBlit blit_region;
|
||||
unsigned src_width = MAX(width >> (i - 1), 1);
|
||||
unsigned src_height = MAX(height >> (i - 1), 1);
|
||||
unsigned target_width = MAX(width >> i, 1);
|
||||
unsigned target_height = MAX(height >> i, 1);
|
||||
memset(&blit_region, 0, sizeof(blit_region));
|
||||
|
||||
blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
blit_region.srcSubresource.mipLevel = i - 1;
|
||||
blit_region.srcSubresource.baseArrayLayer = 0;
|
||||
blit_region.srcSubresource.layerCount = 1;
|
||||
blit_region.dstSubresource = blit_region.srcSubresource;
|
||||
blit_region.dstSubresource.mipLevel = i;
|
||||
blit_region.srcOffsets[1].x = src_width;
|
||||
blit_region.srcOffsets[1].y = src_height;
|
||||
blit_region.srcOffsets[1].z = 1;
|
||||
blit_region.dstOffsets[1].x = target_width;
|
||||
blit_region.dstOffsets[1].y = target_height;
|
||||
blit_region.dstOffsets[1].z = 1;
|
||||
|
||||
/* Only injects execution and memory barriers,
|
||||
* not actual transition. */
|
||||
vulkan_image_layout_transition(vk, staging, tex.image,
|
||||
VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_TRANSFER_READ_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
|
||||
vkCmdBlitImage(staging,
|
||||
tex.image, VK_IMAGE_LAYOUT_GENERAL,
|
||||
tex.image, VK_IMAGE_LAYOUT_GENERAL,
|
||||
1, &blit_region, VK_FILTER_LINEAR);
|
||||
}
|
||||
|
||||
/* Complete our texture. */
|
||||
vulkan_image_layout_transition(vk, staging, tex.image,
|
||||
VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_SHADER_READ_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
}
|
||||
else
|
||||
{
|
||||
vulkan_image_layout_transition(vk, staging, tex.image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_SHADER_READ_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
}
|
||||
|
||||
vkEndCommandBuffer(staging);
|
||||
submit_info.commandBufferCount = 1;
|
||||
@ -1627,6 +1711,7 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
|
||||
info.pfnCallback = vulkan_debug_cb;
|
||||
vkCreateDebugReportCallbackEXT(vk->context.instance, &info, NULL, &vk->context.debug_callback);
|
||||
}
|
||||
RARCH_LOG("[Vulkan]: Enabling Vulkan debug layers.\n");
|
||||
#endif
|
||||
|
||||
/* Try different API versions if driver has compatible
|
||||
|
@ -173,6 +173,7 @@ struct vk_texture
|
||||
enum vk_texture_type type;
|
||||
bool default_smooth;
|
||||
bool need_manual_cache_management;
|
||||
bool mipmap;
|
||||
};
|
||||
|
||||
struct vk_buffer
|
||||
@ -352,6 +353,8 @@ typedef struct vk
|
||||
{
|
||||
VkSampler linear;
|
||||
VkSampler nearest;
|
||||
VkSampler mipmap_nearest;
|
||||
VkSampler mipmap_linear;
|
||||
} samplers;
|
||||
|
||||
unsigned last_valid_index;
|
||||
|
@ -483,16 +483,31 @@ static void vulkan_init_samplers(vk_t *vk)
|
||||
vkCreateSampler(vk->context->device,
|
||||
&info, NULL, &vk->samplers.nearest);
|
||||
|
||||
info.magFilter = VK_FILTER_LINEAR;
|
||||
info.minFilter = VK_FILTER_LINEAR;
|
||||
info.magFilter = VK_FILTER_LINEAR;
|
||||
info.minFilter = VK_FILTER_LINEAR;
|
||||
vkCreateSampler(vk->context->device,
|
||||
&info, NULL, &vk->samplers.linear);
|
||||
|
||||
info.maxLod = VK_LOD_CLAMP_NONE;
|
||||
info.magFilter = VK_FILTER_NEAREST;
|
||||
info.minFilter = VK_FILTER_NEAREST;
|
||||
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
|
||||
vkCreateSampler(vk->context->device,
|
||||
&info, NULL, &vk->samplers.mipmap_nearest);
|
||||
|
||||
info.magFilter = VK_FILTER_LINEAR;
|
||||
info.minFilter = VK_FILTER_LINEAR;
|
||||
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||
vkCreateSampler(vk->context->device,
|
||||
&info, NULL, &vk->samplers.mipmap_linear);
|
||||
}
|
||||
|
||||
static void vulkan_deinit_samplers(vk_t *vk)
|
||||
{
|
||||
vkDestroySampler(vk->context->device, vk->samplers.nearest, NULL);
|
||||
vkDestroySampler(vk->context->device, vk->samplers.linear, NULL);
|
||||
vkDestroySampler(vk->context->device, vk->samplers.mipmap_nearest, NULL);
|
||||
vkDestroySampler(vk->context->device, vk->samplers.mipmap_linear, NULL);
|
||||
}
|
||||
|
||||
static void vulkan_init_buffers(vk_t *vk)
|
||||
@ -651,6 +666,8 @@ static bool vulkan_init_default_filter_chain(vk_t *vk)
|
||||
info.gpu = vk->context->gpu;
|
||||
info.memory_properties = &vk->context->memory_properties;
|
||||
info.pipeline_cache = vk->pipelines.cache;
|
||||
info.queue = vk->context->queue;
|
||||
info.command_pool = vk->swapchain[vk->context->current_swapchain_index].cmd_pool;
|
||||
info.max_input_size.width = vk->tex_w;
|
||||
info.max_input_size.height = vk->tex_h;
|
||||
info.swapchain.viewport = vk->vk_vp;
|
||||
@ -683,6 +700,8 @@ static bool vulkan_init_filter_chain_preset(vk_t *vk, const char *shader_path)
|
||||
info.gpu = vk->context->gpu;
|
||||
info.memory_properties = &vk->context->memory_properties;
|
||||
info.pipeline_cache = vk->pipelines.cache;
|
||||
info.queue = vk->context->queue;
|
||||
info.command_pool = vk->swapchain[vk->context->current_swapchain_index].cmd_pool;
|
||||
info.max_input_size.width = vk->tex_w;
|
||||
info.max_input_size.height = vk->tex_h;
|
||||
info.swapchain.viewport = vk->vk_vp;
|
||||
@ -1745,7 +1764,9 @@ static bool vulkan_frame(void *data, const void *frame,
|
||||
quad.texture = optimal;
|
||||
}
|
||||
|
||||
quad.sampler = vk->samplers.linear;
|
||||
quad.sampler = optimal->mipmap ?
|
||||
vk->samplers.mipmap_linear : vk->samplers.linear;
|
||||
|
||||
quad.mvp = &vk->mvp_no_rot;
|
||||
quad.color.r = 1.0f;
|
||||
quad.color.g = 1.0f;
|
||||
@ -2133,10 +2154,9 @@ static uintptr_t vulkan_load_texture(void *video_data, void *data,
|
||||
image->width, image->height, VK_FORMAT_B8G8R8A8_UNORM,
|
||||
image->pixels, NULL, VULKAN_TEXTURE_STATIC);
|
||||
|
||||
/* TODO: Actually add mipmapping support.
|
||||
* Optimal tiling would make sense here as well ... */
|
||||
texture->default_smooth =
|
||||
filter_type == TEXTURE_FILTER_MIPMAP_LINEAR || filter_type == TEXTURE_FILTER_LINEAR;
|
||||
texture->mipmap = filter_type == TEXTURE_FILTER_MIPMAP_LINEAR;
|
||||
|
||||
return (uintptr_t)texture;
|
||||
}
|
||||
@ -2366,7 +2386,8 @@ static void vulkan_render_overlay(vk_t *vk)
|
||||
memset(&call, 0, sizeof(call));
|
||||
call.pipeline = vk->display.pipelines[3]; /* Strip with blend */
|
||||
call.texture = &vk->overlay.images[i];
|
||||
call.sampler = vk->samplers.linear;
|
||||
call.sampler = call.texture->mipmap ?
|
||||
vk->samplers.mipmap_linear : vk->samplers.linear;
|
||||
call.uniform = &vk->mvp;
|
||||
call.uniform_size = sizeof(vk->mvp);
|
||||
call.vbo = ⦥
|
||||
|
@ -241,7 +241,7 @@ static void vulkan_raster_font_flush(vulkan_raster_t *font)
|
||||
const struct vk_draw_triangles call = {
|
||||
font->vk->pipelines.font,
|
||||
&font->texture,
|
||||
font->vk->samplers.nearest,
|
||||
font->vk->samplers.mipmap_linear,
|
||||
&font->vk->mvp,
|
||||
sizeof(font->vk->mvp),
|
||||
&font->range,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,18 @@ typedef struct vulkan_filter_chain vulkan_filter_chain_t;
|
||||
enum vulkan_filter_chain_filter
|
||||
{
|
||||
VULKAN_FILTER_CHAIN_LINEAR = 0,
|
||||
VULKAN_FILTER_CHAIN_NEAREST = 1
|
||||
VULKAN_FILTER_CHAIN_NEAREST = 1,
|
||||
VULKAN_FILTER_CHAIN_COUNT
|
||||
};
|
||||
|
||||
enum vulkan_filter_chain_address
|
||||
{
|
||||
VULKAN_FILTER_CHAIN_ADDRESS_REPEAT = 0,
|
||||
VULKAN_FILTER_CHAIN_ADDRESS_MIRRORED_REPEAT = 1,
|
||||
VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_EDGE = 2,
|
||||
VULKAN_FILTER_CHAIN_ADDRESS_CLAMP_TO_BORDER = 3,
|
||||
VULKAN_FILTER_CHAIN_ADDRESS_MIRROR_CLAMP_TO_EDGE = 4,
|
||||
VULKAN_FILTER_CHAIN_ADDRESS_COUNT
|
||||
};
|
||||
|
||||
struct vulkan_filter_chain_texture
|
||||
@ -65,6 +76,11 @@ struct vulkan_filter_chain_pass_info
|
||||
|
||||
/* The filter to use for source in this pass. */
|
||||
enum vulkan_filter_chain_filter source_filter;
|
||||
enum vulkan_filter_chain_filter mip_filter;
|
||||
enum vulkan_filter_chain_address address;
|
||||
|
||||
/* Maximum number of mip-levels to use. */
|
||||
unsigned max_levels;
|
||||
};
|
||||
|
||||
struct vulkan_filter_chain_swapchain_info
|
||||
@ -81,6 +97,8 @@ struct vulkan_filter_chain_create_info
|
||||
VkPhysicalDevice gpu;
|
||||
const VkPhysicalDeviceMemoryProperties *memory_properties;
|
||||
VkPipelineCache pipeline_cache;
|
||||
VkQueue queue;
|
||||
VkCommandPool command_pool;
|
||||
unsigned num_passes;
|
||||
|
||||
VkFormat original_format;
|
||||
|
@ -29,6 +29,7 @@ static bool slang_texture_semantic_is_array(slang_texture_semantic sem)
|
||||
case SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY:
|
||||
case SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT:
|
||||
case SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK:
|
||||
case SLANG_TEXTURE_SEMANTIC_USER:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@ -52,6 +53,7 @@ static const char *texture_semantic_names[] = {
|
||||
"OriginalHistory",
|
||||
"PassOutput",
|
||||
"PassFeedback",
|
||||
"User",
|
||||
nullptr
|
||||
};
|
||||
|
||||
@ -61,6 +63,7 @@ static const char *texture_semantic_uniform_names[] = {
|
||||
"OriginalHistorySize",
|
||||
"PassOutputSize",
|
||||
"PassFeedbackSize",
|
||||
"UserSize",
|
||||
nullptr
|
||||
};
|
||||
|
||||
|
@ -48,6 +48,11 @@ enum slang_texture_semantic
|
||||
// Canonical name: "PassFeedback#", e.g. "PassFeedback2".
|
||||
SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK = 4,
|
||||
|
||||
// Inputs from static textures, defined by the user.
|
||||
// There is no canonical name, and the only way to use these semantics are by
|
||||
// remapping.
|
||||
SLANG_TEXTURE_SEMANTIC_USER = 5,
|
||||
|
||||
SLANG_NUM_TEXTURE_SEMANTICS,
|
||||
SLANG_INVALID_TEXTURE_SEMANTIC = -1
|
||||
};
|
||||
|
@ -193,8 +193,9 @@ static void menu_display_vk_draw(void *data)
|
||||
vk->display.pipelines[
|
||||
to_display_pipeline(draw->prim_type, vk->display.blend)],
|
||||
texture,
|
||||
texture->default_smooth
|
||||
? vk->samplers.linear : vk->samplers.nearest,
|
||||
texture->mipmap ?
|
||||
vk->samplers.mipmap_linear :
|
||||
(texture->default_smooth ? vk->samplers.linear : vk->samplers.nearest),
|
||||
draw->matrix_data
|
||||
? draw->matrix_data : menu_display_vk_get_default_mvp(),
|
||||
sizeof(math_matrix_4x4),
|
||||
|
Loading…
Reference in New Issue
Block a user