Mesa (staging/18.2): ac: Introduce ac_build_expand()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 24 09:00:25 UTC 2018


Module: Mesa
Branch: staging/18.2
Commit: e3777d9a839a18793d7e375e3c07633ff9257a56
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e3777d9a839a18793d7e375e3c07633ff9257a56

Author: Connor Abbott <cwabbott0 at gmail.com>
Date:   Thu Oct 18 15:30:11 2018 +0200

ac: Introduce ac_build_expand()

And implement ac_bulid_expand_to_vec4() on top of it.

Fixes: 7e7ee82698247d8f93fe37775b99f4838b0247dd ("ac: add support for 16bit buffer loads")
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
(cherry picked from commit 59535b05cf93f7be5487bd07fb74b0d9feed24de)

---

 src/amd/common/ac_llvm_build.c | 40 ++++++++++++++++++++++++++--------------
 src/amd/common/ac_llvm_build.h |  3 +++
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 5e4f410a8d..5a7bc23a4f 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -515,39 +515,51 @@ ac_build_gather_values(struct ac_llvm_context *ctx,
 	return ac_build_gather_values_extended(ctx, values, value_count, 1, false, false);
 }
 
-/* Expand a scalar or vector to <4 x type> by filling the remaining channels
- * with undef. Extract at most num_channels components from the input.
+/* Expand a scalar or vector to <dst_channels x type> by filling the remaining
+ * channels with undef. Extract at most src_channels components from the input.
  */
-LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
-				     LLVMValueRef value,
-				     unsigned num_channels)
+LLVMValueRef ac_build_expand(struct ac_llvm_context *ctx,
+			     LLVMValueRef value,
+			     unsigned src_channels,
+			     unsigned dst_channels)
 {
 	LLVMTypeRef elemtype;
-	LLVMValueRef chan[4];
+	LLVMValueRef chan[dst_channels];
 
 	if (LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMVectorTypeKind) {
 		unsigned vec_size = LLVMGetVectorSize(LLVMTypeOf(value));
-		num_channels = MIN2(num_channels, vec_size);
 
-		if (num_channels >= 4)
+		if (src_channels == dst_channels && vec_size == dst_channels)
 			return value;
 
-		for (unsigned i = 0; i < num_channels; i++)
+		src_channels = MIN2(src_channels, vec_size);
+
+		for (unsigned i = 0; i < src_channels; i++)
 			chan[i] = ac_llvm_extract_elem(ctx, value, i);
 
 		elemtype = LLVMGetElementType(LLVMTypeOf(value));
 	} else {
-		if (num_channels) {
-			assert(num_channels == 1);
+		if (src_channels) {
+			assert(src_channels == 1);
 			chan[0] = value;
 		}
 		elemtype = LLVMTypeOf(value);
 	}
 
-	while (num_channels < 4)
-		chan[num_channels++] = LLVMGetUndef(elemtype);
+	for (unsigned i = src_channels; i < dst_channels; i++)
+		chan[i] = LLVMGetUndef(elemtype);
+
+	return ac_build_gather_values(ctx, chan, dst_channels);
+}
 
-	return ac_build_gather_values(ctx, chan, 4);
+/* Expand a scalar or vector to <4 x type> by filling the remaining channels
+ * with undef. Extract at most num_channels components from the input.
+ */
+LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
+				     LLVMValueRef value,
+				     unsigned num_channels)
+{
+	return ac_build_expand(ctx, value, num_channels, 4);
 }
 
 LLVMValueRef
diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h
index c5753037e7..92d72ae476 100644
--- a/src/amd/common/ac_llvm_build.h
+++ b/src/amd/common/ac_llvm_build.h
@@ -161,6 +161,9 @@ LLVMValueRef
 ac_build_gather_values(struct ac_llvm_context *ctx,
 		       LLVMValueRef *values,
 		       unsigned value_count);
+LLVMValueRef ac_build_expand(struct ac_llvm_context *ctx,
+			     LLVMValueRef value,
+			     unsigned src_channels, unsigned dst_channels);
 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
 				     LLVMValueRef value,
 				     unsigned num_channels);




More information about the mesa-commit mailing list