anv,hasvk: Use the inbuilt macro from src/util for clamping int64_t
Signed-off-by: Rohan Garg <rohan.garg@intel.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20104>
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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 = {
|
||||
|
@@ -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,
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user