summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/draw
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2023-05-17 06:23:50 +1000
committerMarge Bot <emma+marge@anholt.net>2023-05-23 14:39:32 +0000
commit7c84ca23055161cb7f440514aba0b511f6764a3b (patch)
treec24459114a432d677f707e659dfd8dc6275579e0 /src/gallium/auxiliary/draw
parentb2c604973b9f101f94c333489c20b78ac7fade37 (diff)
gallivm/draw: refactor vertex header jit type out
mesh shaders will want access to this as well so start moving it to common code. Reviewed-by: Brian Paul <brianp@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23065>
Diffstat (limited to 'src/gallium/auxiliary/draw')
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c62
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h16
-rw-r--r--src/gallium/auxiliary/draw/draw_private.h19
-rw-r--r--src/gallium/auxiliary/draw/draw_vertex_header.h48
4 files changed, 57 insertions, 88 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index e754f407cd9..d395b23154d 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -274,54 +274,6 @@ create_jit_vertex_buffer_type(struct gallivm_state *gallivm,
}
-/**
- * Create LLVM type for struct vertex_header;
- */
-static LLVMTypeRef
-create_jit_vertex_header(struct gallivm_state *gallivm, int data_elems)
-{
- LLVMTargetDataRef target = gallivm->target;
- LLVMTypeRef elem_types[3];
- LLVMTypeRef vertex_header;
- char struct_name[24];
-
- snprintf(struct_name, 23, "vertex_header%d", data_elems);
-
- elem_types[DRAW_JIT_VERTEX_VERTEX_ID] = LLVMIntTypeInContext(gallivm->context, 32);
- elem_types[DRAW_JIT_VERTEX_CLIP_POS] = LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
- elem_types[DRAW_JIT_VERTEX_DATA] = LLVMArrayType(elem_types[1], data_elems);
-
- vertex_header = LLVMStructTypeInContext(gallivm->context, elem_types,
- ARRAY_SIZE(elem_types), 0);
-
- /* these are bit-fields and we can't take address of them
- LP_CHECK_MEMBER_OFFSET(struct vertex_header, clipmask,
- target, vertex_header,
- DRAW_JIT_VERTEX_CLIPMASK);
- LP_CHECK_MEMBER_OFFSET(struct vertex_header, edgeflag,
- target, vertex_header,
- DRAW_JIT_VERTEX_EDGEFLAG);
- LP_CHECK_MEMBER_OFFSET(struct vertex_header, pad,
- target, vertex_header,
- DRAW_JIT_VERTEX_PAD);
- LP_CHECK_MEMBER_OFFSET(struct vertex_header, vertex_id,
- target, vertex_header,
- DRAW_JIT_VERTEX_VERTEX_ID);
- */
- (void) target; /* silence unused var warning for non-debug build */
- LP_CHECK_MEMBER_OFFSET(struct vertex_header, clip_pos,
- target, vertex_header,
- DRAW_JIT_VERTEX_CLIP_POS);
- LP_CHECK_MEMBER_OFFSET(struct vertex_header, data,
- target, vertex_header,
- DRAW_JIT_VERTEX_DATA);
-
- assert(LLVMABISizeOfType(target, vertex_header) ==
- offsetof(struct vertex_header, data[data_elems]));
-
- return vertex_header;
-}
-
static LLVMTypeRef
create_tcs_jit_input_type_deref(struct gallivm_state *gallivm)
{
@@ -573,7 +525,7 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
draw_llvm_dump_variant_key(&variant->key);
}
- variant->vertex_header_type = create_jit_vertex_header(variant->gallivm, num_inputs);
+ variant->vertex_header_type = lp_build_create_jit_vertex_header_type(variant->gallivm, num_inputs);
variant->vertex_header_ptr_type = LLVMPointerType(variant->vertex_header_type, 0);
draw_llvm_generate(llvm, variant);
@@ -828,8 +780,8 @@ store_aos(struct gallivm_state *gallivm,
{
LLVMTypeRef data_ptr_type = LLVMPointerType(lp_build_vec_type(gallivm, lp_float32_vec4_type()), 0);
LLVMBuilderRef builder = gallivm->builder;
- LLVMValueRef data_ptr = draw_jit_header_data(gallivm, io_type, io_ptr);
- LLVMTypeRef data_type = LLVMStructGetTypeAtIndex(io_type, DRAW_JIT_VERTEX_DATA);
+ LLVMValueRef data_ptr = lp_jit_vertex_header_data(gallivm, io_type, io_ptr);
+ LLVMTypeRef data_type = LLVMStructGetTypeAtIndex(io_type, LP_JIT_VERTEX_HEADER_DATA);
LLVMValueRef indices[3];
indices[0] = lp_build_const_int32(gallivm, 0);
@@ -952,7 +904,7 @@ store_aos_array(struct gallivm_state *gallivm,
/* OR with the clipmask */
cliptmp = LLVMBuildOr(builder, val, clipmask, "");
for (unsigned i = 0; i < vector_length; i++) {
- LLVMValueRef id_ptr = draw_jit_header_id(gallivm, io_type, io_ptrs[i]);
+ LLVMValueRef id_ptr = lp_jit_vertex_header_id(gallivm, io_type, io_ptrs[i]);
val = LLVMBuildExtractElement(builder, cliptmp, linear_inds[i], "");
val = adjust_mask(gallivm, val);
#if DEBUG_STORE
@@ -1079,7 +1031,7 @@ store_clip(struct gallivm_state *gallivm,
soa[3] = LLVMBuildLoad2(builder, single_type, outputs[idx][3], ""); /*w0 w1 .. wn*/
for (int i = 0; i < vs_type.length; i++) {
- clip_ptrs[i] = draw_jit_header_clip_pos(gallivm, io_type, io_ptrs[i]);
+ clip_ptrs[i] = lp_jit_vertex_header_clip_pos(gallivm, io_type, io_ptrs[i]);
}
lp_build_transpose_aos(gallivm, vs_type, soa, soa);
@@ -2639,7 +2591,7 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm,
create_gs_jit_types(variant);
- variant->vertex_header_type = create_jit_vertex_header(variant->gallivm, num_outputs);
+ variant->vertex_header_type = lp_build_create_jit_vertex_header_type(variant->gallivm, num_outputs);
variant->vertex_header_ptr_type = LLVMPointerType(variant->vertex_header_type, 0);
draw_gs_llvm_generate(llvm, variant);
@@ -3812,7 +3764,7 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm,
create_tes_jit_types(variant);
- variant->vertex_header_type = create_jit_vertex_header(variant->gallivm, num_outputs);
+ variant->vertex_header_type = lp_build_create_jit_vertex_header_type(variant->gallivm, num_outputs);
variant->vertex_header_ptr_type = LLVMPointerType(variant->vertex_header_type, 0);
if (gallivm_debug & (GALLIVM_DEBUG_TGSI | GALLIVM_DEBUG_IR)) {
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index 05d383c484d..ef00bdaea5f 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -49,12 +49,6 @@ struct llvm_geometry_shader;
struct llvm_tess_ctrl_shader;
struct llvm_tess_eval_shader;
-enum {
- DRAW_JIT_VERTEX_VERTEX_ID = 0,
- DRAW_JIT_VERTEX_CLIP_POS,
- DRAW_JIT_VERTEX_DATA
-};
-
/**
* This structure is passed directly to the generated vertex shader.
*
@@ -85,16 +79,6 @@ enum {
lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")
-#define draw_jit_header_id(_gallivm, _type, _ptr) \
- lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
-
-#define draw_jit_header_clip_pos(_gallivm, _type, _ptr) \
- lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
-
-#define draw_jit_header_data(_gallivm, _type, _ptr) \
- lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_DATA, "data")
-
-
#define draw_jit_vbuffer_stride(_gallivm, _type, _ptr) \
lp_build_struct_get2(_gallivm, _type, _ptr, 0, "stride")
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index e69ae6f3d0c..93fc0d39715 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -46,14 +46,13 @@
#include "tgsi/tgsi_scan.h"
+#include "draw_vertex_header.h"
+
#ifdef DRAW_LLVM_AVAILABLE
struct gallivm_state;
#endif
-/** Sum of frustum planes and user-defined planes */
-#define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES)
-
/**
* The largest possible index of a vertex that can be fetched.
*/
@@ -111,20 +110,6 @@ struct draw_vertex_buffer {
uint32_t size;
};
-/**
- * Basic vertex info. Used to represent vertices after VS (through GS, TESS,
- * etc.) to vbuf output.
- */
-struct vertex_header {
- unsigned clipmask:DRAW_TOTAL_CLIP_PLANES;
- unsigned edgeflag:1;
- unsigned pad:1;
- unsigned vertex_id:16;
-
- float clip_pos[4];
- float data[][4]; // the vertex attributes
-};
-
/* NOTE: It should match vertex_id size above */
#define UNDEFINED_VERTEX_ID 0xffff
diff --git a/src/gallium/auxiliary/draw/draw_vertex_header.h b/src/gallium/auxiliary/draw/draw_vertex_header.h
new file mode 100644
index 00000000000..da585710273
--- /dev/null
+++ b/src/gallium/auxiliary/draw/draw_vertex_header.h
@@ -0,0 +1,48 @@
+/**************************************************************************
+ *
+ * Copyright 2007 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef DRAW_VERTEX_HEADER_H
+#define DRAW_VERTEX_HEADER_H
+
+/** Sum of frustum planes and user-defined planes */
+#define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES)
+
+/**
+ * Basic vertex info. Used to represent vertices after VS (through GS, TESS,
+ * etc.) to vbuf output.
+ */
+struct vertex_header {
+ unsigned clipmask:DRAW_TOTAL_CLIP_PLANES;
+ unsigned edgeflag:1;
+ unsigned pad:1;
+ unsigned vertex_id:16;
+
+ float clip_pos[4];
+ float data[][4]; // the vertex attributes
+};
+
+#endif