vkd3d: Implement MinLODClamp using VK_EXT_image_view_min_lod

Signed-off-by: Joshua Ashton <joshua@froggi.es>
This commit is contained in:
Joshua Ashton 2021-07-06 16:51:24 +01:00
parent cf632186fd
commit 828606ef80
No known key found for this signature in database
GPG Key ID: C85A08669126BE8D
4 changed files with 41 additions and 19 deletions

View File

@ -26,6 +26,7 @@ There are some hard requirements on drivers to be able to implement D3D12 in a r
- `VK_KHR_sampler_mirror_clamp_to_edge`
- `VK_EXT_robustness2`
- `VK_KHR_separate_depth_stencil_layouts`
- `VK_EXT_image_view_min_lod`
Some notable extensions that **should** be supported for optimal or correct behavior.
These extensions will likely become mandatory later.

View File

@ -81,6 +81,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] =
VK_EXTENSION(EXT_CUSTOM_BORDER_COLOR, EXT_custom_border_color),
VK_EXTENSION(EXT_DEPTH_CLIP_ENABLE, EXT_depth_clip_enable),
VK_EXTENSION(EXT_DESCRIPTOR_INDEXING, EXT_descriptor_indexing),
VK_EXTENSION(EXT_IMAGE_VIEW_MIN_LOD, EXT_image_view_min_lod),
VK_EXTENSION(EXT_INLINE_UNIFORM_BLOCK, EXT_inline_uniform_block),
VK_EXTENSION(EXT_ROBUSTNESS_2, EXT_robustness2),
VK_EXTENSION(EXT_SAMPLER_FILTER_MINMAX, EXT_sampler_filter_minmax),
@ -1133,6 +1134,12 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i
vk_prepend_struct(&info->features2, &info->mutable_descriptor_features);
}
if (vulkan_info->EXT_image_view_min_lod)
{
info->image_view_min_lod_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT;
vk_prepend_struct(&info->features2, &info->image_view_min_lod_features);
}
if (vulkan_info->KHR_acceleration_structure && vulkan_info->KHR_ray_tracing_pipeline &&
vulkan_info->KHR_deferred_host_operations && vulkan_info->KHR_spirv_1_4)
{

View File

@ -3399,6 +3399,7 @@ bool vkd3d_create_texture_view(struct d3d12_device *device, const struct vkd3d_t
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
const struct vkd3d_format *format = desc->format;
struct VkImageViewMinLodCreateInfoEXT min_lod_desc;
struct VkImageViewCreateInfo view_desc;
struct vkd3d_view *object;
VkImageView vk_view;
@ -3419,29 +3420,40 @@ bool vkd3d_create_texture_view(struct d3d12_device *device, const struct vkd3d_t
view_desc.subresourceRange.baseArrayLayer = desc->layer_idx;
view_desc.subresourceRange.layerCount = desc->layer_count;
if (desc->miplevel_clamp != 0.0f)
FIXME_ONCE("Cannot handle MinResourceLOD clamp of %f correctly.\n", desc->miplevel_clamp);
/* This is not correct, but it's the best we can do with existing API.
* It should at least avoid a scenario where implicit LOD fetches from invalid levels.
* TODO: We will need an extension with vkCreateImageView pNext specifying minLODClamp.
* It will be trivial to add in RADV at least ... */
if (desc->miplevel_clamp >= 1.0f)
if (!device->device_info.image_view_min_lod_features.minLod)
{
uint32_t new_base_level;
uint32_t level_offset;
uint32_t end_level;
if (desc->miplevel_clamp != 0.0f)
FIXME_ONCE("Cannot handle MinResourceLOD clamp of %f correctly.\n", desc->miplevel_clamp);
level_offset = (uint32_t)desc->miplevel_clamp;
if (view_desc.subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS)
/* This is not correct, but it's the best we can do with existing API.
* It should at least avoid a scenario where implicit LOD fetches from invalid levels.
* TODO: We will need an extension with vkCreateImageView pNext specifying minLODClamp.
* It will be trivial to add in RADV at least ... */
if (desc->miplevel_clamp >= 1.0f)
{
end_level = view_desc.subresourceRange.baseMipLevel + view_desc.subresourceRange.levelCount;
new_base_level = min(end_level - 1, desc->miplevel_idx + level_offset);
view_desc.subresourceRange.levelCount = end_level - new_base_level;
view_desc.subresourceRange.baseMipLevel = new_base_level;
uint32_t new_base_level;
uint32_t level_offset;
uint32_t end_level;
level_offset = (uint32_t)desc->miplevel_clamp;
if (view_desc.subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS)
{
end_level = view_desc.subresourceRange.baseMipLevel + view_desc.subresourceRange.levelCount;
new_base_level = min(end_level - 1, desc->miplevel_idx + level_offset);
view_desc.subresourceRange.levelCount = end_level - new_base_level;
view_desc.subresourceRange.baseMipLevel = new_base_level;
}
else
view_desc.subresourceRange.baseMipLevel += level_offset;
}
else
view_desc.subresourceRange.baseMipLevel += level_offset;
}
else
{
min_lod_desc.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_MIN_LOD_CREATE_INFO_EXT;
min_lod_desc.pNext = NULL;
min_lod_desc.minLod = desc->miplevel_clamp;
view_desc.pNext = &min_lod_desc;
}
if ((vr = VK_CALL(vkCreateImageView(device->vk_device, &view_desc, NULL, &vk_view))) < 0)

View File

@ -128,6 +128,7 @@ struct vkd3d_vulkan_info
bool EXT_depth_clip_enable;
bool EXT_descriptor_indexing;
bool EXT_inline_uniform_block;
bool EXT_image_view_min_lod;
bool EXT_robustness2;
bool EXT_sampler_filter_minmax;
bool EXT_shader_demote_to_helper_invocation;
@ -2519,6 +2520,7 @@ struct vkd3d_physical_device_info
VkPhysicalDeviceShaderDrawParametersFeatures shader_draw_parameters_features;
VkPhysicalDeviceSubgroupSizeControlFeaturesEXT subgroup_size_control_features;
VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR separate_depth_stencil_layout_features;
VkPhysicalDeviceImageViewMinLodFeaturesEXT image_view_min_lod_features;
VkPhysicalDeviceFeatures2 features2;