mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-22 05:20:37 +02:00
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>
This commit is contained in:
parent
b2c604973b
commit
7c84ca2305
7 changed files with 125 additions and 88 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
48
src/gallium/auxiliary/draw/draw_vertex_header.h
Normal file
48
src/gallium/auxiliary/draw/draw_vertex_header.h
Normal file
|
|
@ -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
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
#include "gallivm/lp_bld_const.h"
|
||||
#include "gallivm/lp_bld_debug.h"
|
||||
#include "gallivm/lp_bld_ir_common.h"
|
||||
#include "draw/draw_vertex_header.h"
|
||||
#include "lp_bld_jit_types.h"
|
||||
|
||||
|
||||
|
|
@ -602,3 +603,51 @@ lp_build_jit_fill_image_dynamic_state(struct lp_sampler_dynamic_state *state)
|
|||
state->num_samples = lp_build_llvm_image_num_samples;
|
||||
state->sample_stride = lp_build_llvm_image_sample_stride;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create LLVM type for struct vertex_header;
|
||||
*/
|
||||
LLVMTypeRef
|
||||
lp_build_create_jit_vertex_header_type(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[LP_JIT_VERTEX_HEADER_VERTEX_ID] = LLVMIntTypeInContext(gallivm->context, 32);
|
||||
elem_types[LP_JIT_VERTEX_HEADER_CLIP_POS] = LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
|
||||
elem_types[LP_JIT_VERTEX_HEADER_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,
|
||||
LP_JIT_VERTEX_HEADER_CLIPMASK);
|
||||
LP_CHECK_MEMBER_OFFSET(struct vertex_header, edgeflag,
|
||||
target, vertex_header,
|
||||
LP_JIT_VERTEX_HEADER_EDGEFLAG);
|
||||
LP_CHECK_MEMBER_OFFSET(struct vertex_header, pad,
|
||||
target, vertex_header,
|
||||
LP_JIT_VERTEX_HEADER_PAD);
|
||||
LP_CHECK_MEMBER_OFFSET(struct vertex_header, vertex_id,
|
||||
target, vertex_header,
|
||||
LP_JIT_VERTEX_HEADER_VERTEX_ID);
|
||||
*/
|
||||
(void) target; /* silence unused var warning for non-debug build */
|
||||
LP_CHECK_MEMBER_OFFSET(struct vertex_header, clip_pos,
|
||||
target, vertex_header,
|
||||
LP_JIT_VERTEX_HEADER_CLIP_POS);
|
||||
LP_CHECK_MEMBER_OFFSET(struct vertex_header, data,
|
||||
target, vertex_header,
|
||||
LP_JIT_VERTEX_HEADER_DATA);
|
||||
|
||||
assert(LLVMABISizeOfType(target, vertex_header) ==
|
||||
offsetof(struct vertex_header, data[data_elems]));
|
||||
|
||||
return vertex_header;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,6 +163,24 @@ enum {
|
|||
LLVMTypeRef
|
||||
lp_build_jit_resources_type(struct gallivm_state *gallivm);
|
||||
|
||||
enum {
|
||||
LP_JIT_VERTEX_HEADER_VERTEX_ID = 0,
|
||||
LP_JIT_VERTEX_HEADER_CLIP_POS,
|
||||
LP_JIT_VERTEX_HEADER_DATA
|
||||
};
|
||||
|
||||
#define lp_jit_vertex_header_id(_gallivm, _type, _ptr) \
|
||||
lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_VERTEX_ID, "id")
|
||||
|
||||
#define lp_jit_vertex_header_clip_pos(_gallivm, _type, _ptr) \
|
||||
lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_CLIP_POS, "clip_pos")
|
||||
|
||||
#define lp_jit_vertex_header_data(_gallivm, _type, _ptr) \
|
||||
lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_DATA, "data")
|
||||
|
||||
LLVMTypeRef
|
||||
lp_build_create_jit_vertex_header_type(struct gallivm_state *gallivm, int data_elems);
|
||||
|
||||
void
|
||||
lp_build_jit_fill_sampler_dynamic_state(struct lp_sampler_dynamic_state *state);
|
||||
void
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ files_libgallium = files(
|
|||
'draw/draw_vbuf.h',
|
||||
'draw/draw_vertex.c',
|
||||
'draw/draw_vertex.h',
|
||||
'draw/draw_vertex_header.h',
|
||||
'draw/draw_vs.c',
|
||||
'draw/draw_vs_exec.c',
|
||||
'draw/draw_vs.h',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue