diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 4c9d566c0ac..447aad06a76 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -351,19 +351,6 @@ anv_minify(uint32_t n, uint32_t levels) return MAX2(n >> levels, 1); } -static inline float -anv_clamp_f(float f, float min, float max) -{ - assert(min < max); - - if (f > max) - return max; - else if (f < min) - return min; - else - return f; -} - static inline union isl_color_value vk_to_isl_color(VkClearColorValue color) { diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 96fc1475350..c6e4c64fddf 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -3047,17 +3047,6 @@ cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer) } } -static int64_t -clamp_int64(int64_t x, int64_t min, int64_t max) -{ - if (x < min) - return min; - else if (x < max) - return x; - else - return max; -} - static void cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer) { @@ -3103,19 +3092,19 @@ cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer) int64_t x_max = MIN2(s->offset.x + s->extent.width - 1, vp->x + vp->width - 1); - y_max = clamp_int64(y_max, 0, INT16_MAX >> 1); - x_max = clamp_int64(x_max, 0, INT16_MAX >> 1); + y_max = CLAMP(y_max, 0, INT16_MAX >> 1); + x_max = CLAMP(x_max, 0, INT16_MAX >> 1); /* Do this math using int64_t so overflow gets clamped correctly. */ if (cmd_buffer->vk.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) { - y_min = clamp_int64((uint64_t) y_min, gfx->render_area.offset.y, max); - x_min = clamp_int64((uint64_t) x_min, gfx->render_area.offset.x, max); - y_max = clamp_int64((uint64_t) y_max, 0, - gfx->render_area.offset.y + - gfx->render_area.extent.height - 1); - x_max = clamp_int64((uint64_t) x_max, 0, - gfx->render_area.offset.x + - gfx->render_area.extent.width - 1); + y_min = CLAMP((uint64_t) y_min, gfx->render_area.offset.y, max); + x_min = CLAMP((uint64_t) x_min, gfx->render_area.offset.x, max); + y_max = CLAMP((uint64_t) y_max, 0, + gfx->render_area.offset.y + + gfx->render_area.extent.height - 1); + x_max = CLAMP((uint64_t) x_max, 0, + gfx->render_area.offset.x + + gfx->render_area.extent.width - 1); } const struct GENX(SCISSOR_RECT) scissor = { diff --git a/src/intel/vulkan/genX_state.c b/src/intel/vulkan/genX_state.c index cb5f3dcc9a9..ae9ec5b5ca5 100644 --- a/src/intel/vulkan/genX_state.c +++ b/src/intel/vulkan/genX_state.c @@ -756,7 +756,7 @@ vk_to_intel_tex_filter(VkFilter filter, bool anisotropyEnable) static uint32_t vk_to_intel_max_anisotropy(float ratio) { - return (anv_clamp_f(ratio, 2, 16) - 2) / 2; + return (CLAMP(ratio, 2, 16) - 2) / 2; } static const uint32_t vk_to_intel_mipmap_mode[] = { @@ -949,11 +949,11 @@ VkResult genX(CreateSampler)( .MipModeFilter = mip_filter_mode, .MagModeFilter = vk_to_intel_tex_filter(mag_filter, pCreateInfo->anisotropyEnable), .MinModeFilter = vk_to_intel_tex_filter(min_filter, pCreateInfo->anisotropyEnable), - .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16, 15.996), + .TextureLODBias = CLAMP(pCreateInfo->mipLodBias, -16, 15.996), .AnisotropicAlgorithm = pCreateInfo->anisotropyEnable ? EWAApproximation : LEGACY, - .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14), - .MaxLOD = anv_clamp_f(pCreateInfo->maxLod, 0, 14), + .MinLOD = CLAMP(pCreateInfo->minLod, 0, 14), + .MaxLOD = CLAMP(pCreateInfo->maxLod, 0, 14), .ChromaKeyEnable = 0, .ChromaKeyIndex = 0, .ChromaKeyMode = 0, diff --git a/src/intel/vulkan_hasvk/anv_private.h b/src/intel/vulkan_hasvk/anv_private.h index 24f7475852b..5ab9e5eb18d 100644 --- a/src/intel/vulkan_hasvk/anv_private.h +++ b/src/intel/vulkan_hasvk/anv_private.h @@ -335,19 +335,6 @@ anv_minify(uint32_t n, uint32_t levels) return MAX2(n >> levels, 1); } -static inline float -anv_clamp_f(float f, float min, float max) -{ - assert(min < max); - - if (f > max) - return max; - else if (f < min) - return min; - else - return f; -} - static inline union isl_color_value vk_to_isl_color(VkClearColorValue color) { diff --git a/src/intel/vulkan_hasvk/genX_cmd_buffer.c b/src/intel/vulkan_hasvk/genX_cmd_buffer.c index b04c1417624..9a5e2cc64bc 100644 --- a/src/intel/vulkan_hasvk/genX_cmd_buffer.c +++ b/src/intel/vulkan_hasvk/genX_cmd_buffer.c @@ -3043,17 +3043,6 @@ cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer, } } -static int64_t -clamp_int64(int64_t x, int64_t min, int64_t max) -{ - if (x < min) - return min; - else if (x < max) - return x; - else - return max; -} - static void cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer) { @@ -3099,17 +3088,17 @@ cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer) int64_t x_max = MIN2(s->offset.x + s->extent.width - 1, vp->x + vp->width - 1); - y_max = clamp_int64(y_max, 0, INT16_MAX >> 1); - x_max = clamp_int64(x_max, 0, INT16_MAX >> 1); + y_max = CLAMP(y_max, 0, INT16_MAX >> 1); + x_max = CLAMP(x_max, 0, INT16_MAX >> 1); /* Do this math using int64_t so overflow gets clamped correctly. */ if (cmd_buffer->vk.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) { - y_min = clamp_int64((uint64_t) y_min, gfx->render_area.offset.y, max); - x_min = clamp_int64((uint64_t) x_min, gfx->render_area.offset.x, max); - y_max = clamp_int64((uint64_t) y_max, 0, + y_min = CLAMP((uint64_t) y_min, gfx->render_area.offset.y, max); + x_min = CLAMP((uint64_t) x_min, gfx->render_area.offset.x, max); + y_max = CLAMP((uint64_t) y_max, 0, gfx->render_area.offset.y + gfx->render_area.extent.height - 1); - x_max = clamp_int64((uint64_t) x_max, 0, + x_max = CLAMP((uint64_t) x_max, 0, gfx->render_area.offset.x + gfx->render_area.extent.width - 1); } diff --git a/src/intel/vulkan_hasvk/genX_state.c b/src/intel/vulkan_hasvk/genX_state.c index 7f87c8d8c56..649d65bbdc0 100644 --- a/src/intel/vulkan_hasvk/genX_state.c +++ b/src/intel/vulkan_hasvk/genX_state.c @@ -369,7 +369,7 @@ vk_to_intel_tex_filter(VkFilter filter, bool anisotropyEnable) static uint32_t vk_to_intel_max_anisotropy(float ratio) { - return (anv_clamp_f(ratio, 2, 16) - 2) / 2; + return (CLAMP(ratio, 2, 16) - 2) / 2; } static const uint32_t vk_to_intel_mipmap_mode[] = { @@ -551,11 +551,11 @@ VkResult genX(CreateSampler)( .MipModeFilter = mip_filter_mode, .MagModeFilter = vk_to_intel_tex_filter(mag_filter, pCreateInfo->anisotropyEnable), .MinModeFilter = vk_to_intel_tex_filter(min_filter, pCreateInfo->anisotropyEnable), - .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16, 15.996), + .TextureLODBias = CLAMP(pCreateInfo->mipLodBias, -16, 15.996), .AnisotropicAlgorithm = pCreateInfo->anisotropyEnable ? EWAApproximation : LEGACY, - .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14), - .MaxLOD = anv_clamp_f(pCreateInfo->maxLod, 0, 14), + .MinLOD = CLAMP(pCreateInfo->minLod, 0, 14), + .MaxLOD = CLAMP(pCreateInfo->maxLod, 0, 14), .ChromaKeyEnable = 0, .ChromaKeyIndex = 0, .ChromaKeyMode = 0,