Module: Mesa Branch: main Commit: c6471ef918f75de806f2871696a44b24ee1db558 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c6471ef918f75de806f2871696a44b24ee1db558
Author: Joshua Ashton <[email protected]> Date: Tue Jul 6 14:28:20 2021 +0100 radv: Refactor S_FIXED to radv_float_to_{s,u}fixed We'll need to use this in radv_image for VK_EXT_image_view_min_lod. Additionally, creates signed/unsigned variants to avoid sign-extending where we don't need to. Signed-off-by: Joshua Ashton <[email protected]> Reviewed-by: Samuel Pitoiset <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13820> --- src/amd/vulkan/radv_device.c | 12 +++--------- src/amd/vulkan/radv_private.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index d3e7b6952d4..a20fa0fe8e6 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -7214,12 +7214,6 @@ radv_get_max_anisotropy(struct radv_device *device, const VkSamplerCreateInfo *p return 0; } -static inline int -S_FIXED(float value, unsigned frac_bits) -{ - return value * (1 << frac_bits); -} - static uint32_t radv_register_border_color(struct radv_device *device, VkClearColorValue value) { @@ -7312,10 +7306,10 @@ radv_init_sampler(struct radv_device *device, struct radv_sampler *sampler, S_008F30_ANISO_THRESHOLD(max_aniso_ratio >> 1) | S_008F30_ANISO_BIAS(max_aniso_ratio) | S_008F30_DISABLE_CUBE_WRAP(0) | S_008F30_COMPAT_MODE(compat_mode) | S_008F30_FILTER_MODE(filter_mode) | S_008F30_TRUNC_COORD(trunc_coord)); - sampler->state[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo->minLod, 0, 15), 8)) | - S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo->maxLod, 0, 15), 8)) | + sampler->state[1] = (S_008F34_MIN_LOD(radv_float_to_ufixed(CLAMP(pCreateInfo->minLod, 0, 15), 8)) | + S_008F34_MAX_LOD(radv_float_to_ufixed(CLAMP(pCreateInfo->maxLod, 0, 15), 8)) | S_008F34_PERF_MIP(max_aniso_ratio ? max_aniso_ratio + 6 : 0)); - sampler->state[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo->mipLodBias, -16, 16), 8)) | + sampler->state[2] = (S_008F38_LOD_BIAS(radv_float_to_sfixed(CLAMP(pCreateInfo->mipLodBias, -16, 16), 8)) | S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo->magFilter, max_aniso)) | S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo->minFilter, max_aniso)) | S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo->mipmapMode)) | diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index b5dd2a2f3d1..ecf49afb404 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -203,6 +203,18 @@ radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask) } } +static inline int +radv_float_to_sfixed(float value, unsigned frac_bits) +{ + return value * (1 << frac_bits); +} + +static inline unsigned int +radv_float_to_ufixed(float value, unsigned frac_bits) +{ + return value * (1 << frac_bits); +} + /* Whenever we generate an error, pass it through this function. Useful for * debugging, where we can break on it. Only call at error site, not when * propagating errors. Might be useful to plug in a stack trace here.
