vkd3d: Implement MinLODClamp using VK_EXT_image_view_min_lod
Signed-off-by: Joshua Ashton <joshua@froggi.es>
This commit is contained in:
parent
7241164e2d
commit
046524f2a1
|
@ -32,6 +32,7 @@ These extensions will likely become mandatory later.
|
|||
|
||||
- `VK_KHR_buffer_device_address`
|
||||
- `VK_EXT_extended_dynamic_state`
|
||||
- `VK_EXT_image_view_min_lod`
|
||||
|
||||
`VK_VALVE_mutable_descriptor_type` is also highly recommended, but not mandatory.
|
||||
|
||||
|
|
|
@ -85,6 +85,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),
|
||||
|
@ -1195,6 +1196,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)
|
||||
{
|
||||
|
|
|
@ -3461,9 +3461,10 @@ 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 VkImageViewCreateInfo view_desc;
|
||||
VkImageViewMinLodCreateInfoEXT min_lod_desc;
|
||||
VkImageView vk_view = VK_NULL_HANDLE;
|
||||
VkImageViewCreateInfo view_desc;
|
||||
struct vkd3d_view *object;
|
||||
VkImageView vk_view;
|
||||
VkResult vr;
|
||||
|
||||
view_desc.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
|
@ -3481,35 +3482,39 @@ 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 we clamp out of bounds, then don't make a view
|
||||
* and use a NULL descriptor to stay in-spec.
|
||||
* The clamp is absolute, and not affected by the baseMipLevel. */
|
||||
if (desc->miplevel_clamp <= (float)(desc->miplevel_idx + desc->miplevel_count - 1))
|
||||
{
|
||||
uint32_t clamp_base_level;
|
||||
uint32_t new_base_level;
|
||||
uint32_t end_level;
|
||||
|
||||
clamp_base_level = max((uint32_t)desc->miplevel_clamp, view_desc.subresourceRange.baseMipLevel);
|
||||
if (view_desc.subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS)
|
||||
if (device->device_info.image_view_min_lod_features.minLod)
|
||||
{
|
||||
end_level = view_desc.subresourceRange.baseMipLevel + view_desc.subresourceRange.levelCount;
|
||||
new_base_level = min(end_level - 1, clamp_base_level);
|
||||
view_desc.subresourceRange.levelCount = end_level - new_base_level;
|
||||
view_desc.subresourceRange.baseMipLevel = new_base_level;
|
||||
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;
|
||||
vk_prepend_struct(&view_desc, &min_lod_desc);
|
||||
}
|
||||
else
|
||||
view_desc.subresourceRange.baseMipLevel = clamp_base_level;
|
||||
}
|
||||
{
|
||||
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 without VK_EXT_image_view_min_lod.
|
||||
* It should at least avoid a scenario where implicit LOD fetches from invalid levels. */
|
||||
if (desc->miplevel_clamp >= 1.0f)
|
||||
{
|
||||
uint32_t clamp_base_level = max((uint32_t)desc->miplevel_clamp, view_desc.subresourceRange.baseMipLevel);
|
||||
uint32_t end_level = view_desc.subresourceRange.baseMipLevel + view_desc.subresourceRange.levelCount;
|
||||
uint32_t new_base_level = min(end_level - 1, clamp_base_level);
|
||||
view_desc.subresourceRange.levelCount = end_level - new_base_level;
|
||||
view_desc.subresourceRange.baseMipLevel = new_base_level;
|
||||
}
|
||||
}
|
||||
|
||||
if ((vr = VK_CALL(vkCreateImageView(device->vk_device, &view_desc, NULL, &vk_view))) < 0)
|
||||
{
|
||||
WARN("Failed to create Vulkan image view, vr %d.\n", vr);
|
||||
return false;
|
||||
if ((vr = VK_CALL(vkCreateImageView(device->vk_device, &view_desc, NULL, &vk_view))) < 0)
|
||||
{
|
||||
WARN("Failed to create Vulkan image view, vr %d.\n", vr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(object = vkd3d_view_create(VKD3D_VIEW_TYPE_IMAGE)))
|
||||
|
@ -4035,8 +4040,8 @@ static void vkd3d_create_texture_srv(struct d3d12_desc *descriptor,
|
|||
}
|
||||
}
|
||||
|
||||
/* Only applicable to workaround path. */
|
||||
key.u.texture.miplevel_clamp = min(key.u.texture.miplevel_clamp, (float)resource->desc.MipLevels - 1.0f);
|
||||
if (key.u.texture.miplevel_count == VK_REMAINING_MIP_LEVELS)
|
||||
key.u.texture.miplevel_count = resource->desc.MipLevels - key.u.texture.miplevel_idx;
|
||||
|
||||
if (!(view = vkd3d_view_map_create_view(&resource->view_map, device, &key)))
|
||||
return;
|
||||
|
|
|
@ -133,6 +133,7 @@ struct vkd3d_vulkan_info
|
|||
bool EXT_custom_border_color;
|
||||
bool EXT_depth_clip_enable;
|
||||
bool EXT_descriptor_indexing;
|
||||
bool EXT_image_view_min_lod;
|
||||
bool EXT_inline_uniform_block;
|
||||
bool EXT_robustness2;
|
||||
bool EXT_sampler_filter_minmax;
|
||||
|
@ -2726,6 +2727,7 @@ struct vkd3d_physical_device_info
|
|||
VkPhysicalDeviceShaderAtomicInt64FeaturesKHR shader_atomic_int64_features;
|
||||
VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT shader_image_atomic_int64_features;
|
||||
VkPhysicalDeviceScalarBlockLayoutFeaturesEXT scalar_block_layout_features;
|
||||
VkPhysicalDeviceImageViewMinLodFeaturesEXT image_view_min_lod_features;
|
||||
|
||||
VkPhysicalDeviceFeatures2 features2;
|
||||
|
||||
|
|
Loading…
Reference in New Issue