aboutsummaryrefslogtreecommitdiffstats
path: root/src/amd/llvm
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2020-01-09 19:12:36 -0500
committerMarek Olšák <[email protected]>2020-01-20 16:16:11 -0500
commit4e4b2d13f09023c294f69235ca1ff16db1e9d7aa (patch)
treead6d58c7191b82dc510f057483a3a2a8d3274865 /src/amd/llvm
parent8db00a51f85109e958631ef74a458b0614f37097 (diff)
ac: add helper ac_build_triangle_strip_indices_to_triangle
Acked-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Diffstat (limited to 'src/amd/llvm')
-rw-r--r--src/amd/llvm/ac_llvm_build.c35
-rw-r--r--src/amd/llvm/ac_llvm_build.h4
2 files changed, 39 insertions, 0 deletions
diff --git a/src/amd/llvm/ac_llvm_build.c b/src/amd/llvm/ac_llvm_build.c
index 3640c7c22fa..33cec6b878d 100644
--- a/src/amd/llvm/ac_llvm_build.c
+++ b/src/amd/llvm/ac_llvm_build.c
@@ -4967,3 +4967,38 @@ LLVMValueRef ac_prefix_bitcount_2x64(struct ac_llvm_context *ctx,
return LLVMBuildAdd(builder, prefix_bcnt[0], prefix_bcnt[1], "");
#endif
}
+
+/**
+ * Convert triangle strip indices to triangle indices. This is used to decompose
+ * triangle strips into triangles.
+ */
+void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context *ctx,
+ LLVMValueRef is_odd,
+ LLVMValueRef flatshade_first,
+ LLVMValueRef index[3])
+{
+ LLVMBuilderRef builder = ctx->builder;
+ LLVMValueRef out[3];
+
+ /* We need to change the vertex order for odd triangles to get correct
+ * front/back facing by swapping 2 vertex indices, but we also have to
+ * keep the provoking vertex in the same place.
+ *
+ * If the first vertex is provoking, swap index 1 and 2.
+ * If the last vertex is provoking, swap index 0 and 1.
+ */
+ out[0] = LLVMBuildSelect(builder, flatshade_first,
+ index[0],
+ LLVMBuildSelect(builder, is_odd,
+ index[1], index[0], ""), "");
+ out[1] = LLVMBuildSelect(builder, flatshade_first,
+ LLVMBuildSelect(builder, is_odd,
+ index[2], index[1], ""),
+ LLVMBuildSelect(builder, is_odd,
+ index[0], index[1], ""), "");
+ out[2] = LLVMBuildSelect(builder, flatshade_first,
+ LLVMBuildSelect(builder, is_odd,
+ index[1], index[2], ""),
+ index[2], "");
+ memcpy(index, out, sizeof(out));
+}
diff --git a/src/amd/llvm/ac_llvm_build.h b/src/amd/llvm/ac_llvm_build.h
index 4be06a9c104..772054efecd 100644
--- a/src/amd/llvm/ac_llvm_build.h
+++ b/src/amd/llvm/ac_llvm_build.h
@@ -795,6 +795,10 @@ LLVMValueRef ac_prefix_bitcount(struct ac_llvm_context *ctx,
LLVMValueRef mask, LLVMValueRef index);
LLVMValueRef ac_prefix_bitcount_2x64(struct ac_llvm_context *ctx,
LLVMValueRef mask[2], LLVMValueRef index);
+void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context *ctx,
+ LLVMValueRef is_odd,
+ LLVMValueRef flatshade_first,
+ LLVMValueRef index[3]);
#ifdef __cplusplus
}