From: Marek Olšák <marek.ol...@amd.com>

---
 src/gallium/drivers/radeonsi/si_shader.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index b0417ed..f125483 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -192,6 +192,20 @@ static int get_param_index(unsigned semantic_name, 
unsigned index,
 }
 
 /**
+ * BitField Extract: ((value >> rshift) & ((1 << bitwidth) - 1))
+ */
+static LLVMValueRef build_bfe(struct gallivm_state *gallivm,
+                             LLVMValueRef value, LLVMValueRef rshift,
+                             LLVMValueRef bitwidth)
+{
+       LLVMValueRef args[3] = {value, rshift, bitwidth};
+
+       return build_intrinsic(gallivm->builder, "llvm.AMDGPU.bfe.u32",
+                              LLVMInt32TypeInContext(gallivm->context),
+                              args, Elements(args), LLVMReadNoneAttribute);
+}
+
+/**
  * Build an LLVM bytecode indexed load using LLVMBuildGEP + LLVMBuildLoad.
  * It's equivalent to doing a load from &base_ptr[index].
  *
@@ -1721,7 +1735,6 @@ static void tex_fetch_args(
 
                /* Initialize some constants. */
                LLVMValueRef four = LLVMConstInt(uint_bld->elem_type, 4, 0);
-               LLVMValueRef F = LLVMConstInt(uint_bld->elem_type, 0xF, 0);
 
                /* Apply the formula. */
                LLVMValueRef fmask =
@@ -1734,11 +1747,8 @@ static void tex_fetch_args(
                LLVMValueRef sample_index4 =
                        LLVMBuildMul(gallivm->builder, address[sample_chan], 
four, "");
 
-               LLVMValueRef shifted_fmask =
-                       LLVMBuildLShr(gallivm->builder, fmask, sample_index4, 
"");
-
-               LLVMValueRef final_sample =
-                       LLVMBuildAnd(gallivm->builder, shifted_fmask, F, "");
+               LLVMValueRef final_sample = build_bfe(gallivm, fmask,
+                                                     sample_index4, four);
 
                /* Don't rewrite the sample index if WORD1.DATA_FORMAT of the 
FMASK
                 * resource descriptor is 0 (invalid),
-- 
2.1.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to