From c69dc017965fd5bc14dacb60d1c7b7b942d160c2 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 16 Jun 2023 12:51:36 +0200 Subject: [PATCH] vulkan: avoid needless constant-folding While we're at it, also switch to the nir_f{add,mul}_imm helpers. Reviewed-by: Kenneth Graunke Part-of: --- src/vulkan/runtime/vk_nir_convert_ycbcr.c | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/vulkan/runtime/vk_nir_convert_ycbcr.c b/src/vulkan/runtime/vk_nir_convert_ycbcr.c index bbc8e6ae145..8c2183c2657 100644 --- a/src/vulkan/runtime/vk_nir_convert_ycbcr.c +++ b/src/vulkan/runtime/vk_nir_convert_ycbcr.c @@ -38,12 +38,13 @@ y_range(nir_builder *b, case VK_SAMPLER_YCBCR_RANGE_ITU_FULL: return y_channel; case VK_SAMPLER_YCBCR_RANGE_ITU_NARROW: - return nir_fmul(b, - nir_fadd(b, - nir_fmul(b, y_channel, - nir_imm_float(b, pow(2, bpc) - 1)), - nir_imm_float(b, -16.0f * pow(2, bpc - 8))), - nir_frcp(b, nir_imm_float(b, 219.0f * pow(2, bpc - 8)))); + return nir_fmul_imm(b, + nir_fadd_imm(b, + nir_fmul_imm(b, y_channel, + pow(2, bpc) - 1), + -16.0f * pow(2, bpc - 8)), + 1.0f / (219.0f * pow(2, bpc - 8))); + default: unreachable("missing Ycbcr range"); return NULL; @@ -61,12 +62,12 @@ chroma_range(nir_builder *b, return nir_fadd(b, chroma_channel, nir_imm_float(b, -pow(2, bpc - 1) / (pow(2, bpc) - 1.0f))); case VK_SAMPLER_YCBCR_RANGE_ITU_NARROW: - return nir_fmul(b, - nir_fadd(b, - nir_fmul(b, chroma_channel, - nir_imm_float(b, pow(2, bpc) - 1)), - nir_imm_float(b, -128.0f * pow(2, bpc - 8))), - nir_frcp(b, nir_imm_float(b, 224.0f * pow(2, bpc - 8)))); + return nir_fmul_imm(b, + nir_fadd_imm(b, + nir_fmul_imm(b, chroma_channel, + pow(2, bpc) - 1), + -128.0f * pow(2, bpc - 8)), + 1.0f / (224.0f * pow(2, bpc - 8))); default: unreachable("missing Ycbcr range"); return NULL;