From c5c5cd7132e18f4aad8e73d8ee879f8823c4c1e7 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 22 Feb 2010 22:02:58 -0500 Subject: gallium/draw: initial code to properly support llvm in the draw module code generate big chunks of the vertex pipeline in order to speed up software vertex processing. --- src/gallium/auxiliary/draw/draw_llvm_translate.c | 653 +++++++++++++++++++++++ 1 file changed, 653 insertions(+) create mode 100644 src/gallium/auxiliary/draw/draw_llvm_translate.c (limited to 'src/gallium/auxiliary/draw/draw_llvm_translate.c') diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c new file mode 100644 index 0000000000..588e97b29c --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -0,0 +1,653 @@ + + + +#include "util/u_memory.h" +#include "pipe/p_state.h" +#include "translate.h" + + +#define DRAW_DBG 0 + +typedef void (*fetch_func)(const void *ptr, float *attrib); +typedef void (*emit_func)(const float *attrib, void *ptr); + + + +struct translate_generic { + struct translate translate; + + struct { + enum translate_element_type type; + + fetch_func fetch; + unsigned buffer; + unsigned input_offset; + unsigned instance_divisor; + + emit_func emit; + unsigned output_offset; + + char *input_ptr; + unsigned input_stride; + + } attrib[PIPE_MAX_ATTRIBS]; + + unsigned nr_attrib; +}; + + +static struct translate_generic *translate_generic( struct translate *translate ) +{ + return (struct translate_generic *)translate; +} + +/** + * Fetch a float[4] vertex attribute from memory, doing format/type + * conversion as needed. + * + * This is probably needed/dupliocated elsewhere, eg format + * conversion, texture sampling etc. + */ +#define ATTRIB( NAME, SZ, TYPE, FROM, TO ) \ +static void \ +fetch_##NAME(const void *ptr, float *attrib) \ +{ \ + const float defaults[4] = { 0.0f,0.0f,0.0f,1.0f }; \ + unsigned i; \ + \ + for (i = 0; i < SZ; i++) { \ + attrib[i] = FROM(i); \ + } \ + \ + for (; i < 4; i++) { \ + attrib[i] = defaults[i]; \ + } \ +} \ + \ +static void \ +emit_##NAME(const float *attrib, void *ptr) \ +{ \ + unsigned i; \ + TYPE *out = (TYPE *)ptr; \ + \ + for (i = 0; i < SZ; i++) { \ + out[i] = TO(attrib[i]); \ + } \ +} + +{ + + return conv = instr(builder, bc, ""); +} + +static INLINE LLVMValueRef +from_64_float(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMDoubleType() , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + return LLVMBuildFPTrunc(builder, l, LLVMFloatType(), ""); +} + +static INLINE LLVMValueRef +from_32_float(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMFloatType() , ""); + return LLVMBuildLoad(builder, bc, ""); +} + +static INLINE LLVMValueRef +from_8_uscaled(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(builder, val, ""); + return LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); +} + +static INLINE LLVMValueRef +from_16_uscaled(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(16) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + return LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); +} + +static INLINE LLVMValueRef +from_32_uscaled(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(32) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + return LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); +} + +static INLINE LLVMValueRef +from_8_sscaled(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(builder, val, ""); + return LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); +} + +static INLINE LLVMValueRef +from_16_sscaled(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(16) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + return LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); +} + +static INLINE LLVMValueRef +from_32_sscaled(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(32) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + return LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); +} + + +static INLINE LLVMValueRef +from_8_unorm(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(builder, val, ""); + LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); + return LLVMBuildFDiv(builder, uscaled, + LLVMConstReal(builder, 255.)); +} + +static INLINE LLVMValueRef +from_16_unorm(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(16) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); + return LLVMBuildFDiv(builder, uscaled, + LLVMConstReal(builder, 65535.)); +} + +static INLINE LLVMValueRef +from_32_unorm(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(32) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); + + return LLVMBuildFDiv(builder, uscaled, + LLVMConstReal(builder, 4294967295.)); +} + +static INLINE LLVMValueRef +from_8_snorm(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(builder, val, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); + return LLVMBuildFDiv(builder, uscaled, + LLVMConstReal(builder, 127.0)); +} + +static INLINE LLVMValueRef +from_16_snorm(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(16) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); + return LLVMBuildFDiv(builder, uscaled, + LLVMConstReal(builder, 32767.0f)); +} + +static INLINE LLVMValueRef +from_32_snorm(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(32) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); + + return LLVMBuildFDiv(builder, uscaled, + LLVMConstReal(builder, 2147483647.0)); +} + +static INLINE LLVMValueRef +from_32_fixed(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(builder, val, + LLVMIntType(32) , ""); + LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); + + return LLVMBuildFDiv(builder, uscaled, + LLVMConstReal(builder, 65536.0)); +} + +static INLINE LLVMValueRef +to_64_float(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + return LLVMBuildFPExt(builder, l, LLVMDoubleType(), ""); +} + +static INLINE LLVMValueRef +to_32_float(LLVMBuilderRef builder, LLVMValueRef fp) +{ + return LLVMBuildLoad(builder, fp, ""); +} + +atic INLINE LLVMValueRef +to_8_uscaled(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + return LLVMBuildFPToUI(builder, l, LLVMIntType(8), ""); +} + +static INLINE LLVMValueRef +to_16_uscaled(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + return LLVMBuildFPToUI(builder, l, LLVMIntType(16), ""); +} + +static INLINE LLVMValueRef +to_32_uscaled(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + return LLVMBuildFPToUI(builder, l, LLVMIntType(32), ""); +} + +static INLINE LLVMValueRef +to_8_sscaled(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + return LLVMBuildFPToSI(builder, l, LLVMIntType(8), ""); +} + +static INLINE LLVMValueRef +to_16_sscaled(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + return LLVMBuildFPToSI(builder, l, LLVMIntType(16), ""); +} + +static INLINE LLVMValueRef +to_32_sscaled(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + return LLVMBuildFPToSI(builder, l, LLVMIntType(32), ""); +} + +static INLINE LLVMValueRef +to_8_unorm(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(8), ""); + return LLVMBuildFMul(builder, uscaled, + LLVMConstReal(builder, 255.)); +} + +static INLINE LLVMValueRef +to_16_unorm(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), ""); + return LLVMBuildFMul(builder, uscaled, + LLVMConstReal(builder, 65535.)); +} + +static INLINE LLVMValueRef +to_32_unorm(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), ""); + + return LLVMBuildFMul(builder, uscaled, + LLVMConstReal(builder, 4294967295.)); +} + +static INLINE LLVMValueRef +to_8_snorm(LLVMBuilderRef builder, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(builder, val, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(8), ""); + return LLVMBuildFMUL(builder, uscaled, + LLVMConstReal(builder, 127.0)); +} + +static INLINE LLVMValueRef +to_16_snorm(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(16), ""); + return LLVMBuildFMul(builder, uscaled, + LLVMConstReal(builder, 32767.0f)); +} + +static INLINE LLVMValueRef +to_32_snorm(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), ""); + + return LLVMBuildFMUL(builder, uscaled, + LLVMConstReal(builder, 2147483647.0)); +} + +static INLINE LLVMValueRef +to_32_fixed(LLVMBuilderRef builder, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), ""); + + return LLVMBuildFMul(builder, uscaled, + LLVMConstReal(builder, 65536.0)); +} + +static LLVMValueRef +fetch(LLVMValueRef ptr, int val_size, int nr_components, + LLVMValueRef res) +{ + int i; + int offset = 0; + + for (i = 0; i < nr_components; ++i) { + LLVMValueRef src_index = LLVMConstInt(LLVMInt32Type(), offset, 0); + LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0); + //getelementptr i8* ptr, i64 offset + LLVMValueRef src_tmp = LLVMBuildGEP(builder, ptr, &src_index, 1, ""); + //getelementptr float* res, i64 i + LLVMValueRef res_tmp = LLVMBuildGEP(builder, res, &dst_index, 1, ""); + //bitcast i8* src, to res_type* + //load res_type src + //convert res_type src to float + //store float src, float *dst src + offset += val_size; + } +} + + +static void +fetch_B8G8R8A8_UNORM(const void *ptr, float *attrib) +{ + attrib[2] = FROM_8_UNORM(0); + attrib[1] = FROM_8_UNORM(1); + attrib[0] = FROM_8_UNORM(2); + attrib[3] = FROM_8_UNORM(3); +} + +static void +emit_B8G8R8A8_UNORM( const float *attrib, void *ptr) +{ + ubyte *out = (ubyte *)ptr; + out[2] = TO_8_UNORM(attrib[0]); + out[1] = TO_8_UNORM(attrib[1]); + out[0] = TO_8_UNORM(attrib[2]); + out[3] = TO_8_UNORM(attrib[3]); +} + +static void +fetch_NULL( const void *ptr, float *attrib ) +{ + attrib[0] = 0; + attrib[1] = 0; + attrib[2] = 0; + attrib[3] = 1; +} + +static void +emit_NULL( const float *attrib, void *ptr ) +{ + /* do nothing is the only sensible option */ +} + +typedef LLVMValueRef (*from_func)(LLVMBuilderRef, LLVMValueRef); +typedef LLVMValueRef (*to_func)(LLVMBuilderRef, LLVMValueRef); + +struct draw_llvm_translate { + int format; + from_func from; + to_func to; + LLVMTypeRef type; + int num_components; +} translates[] = +{ + {PIPE_FORMAT_R64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 1}, + {PIPE_FORMAT_R64G64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 2}, + {PIPE_FORMAT_R64G64B64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 3}, + {PIPE_FORMAT_R64G64B64A64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 4}, + + {PIPE_FORMAT_R32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 1}, + {PIPE_FORMAT_R32G32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 2}, + {PIPE_FORMAT_R32G32B32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 3}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 4}, + + {PIPE_FORMAT_R32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 1}, + {PIPE_FORMAT_R32G32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 2}, + {PIPE_FORMAT_R32G32B32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 3}, + {PIPE_FORMAT_R32G32B32A32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 4}, + + {PIPE_FORMAT_R32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 1}, + {PIPE_FORMAT_R32G32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 2}, + {PIPE_FORMAT_R32G32B32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 3}, + {PIPE_FORMAT_R32G32B32A32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 4}, + + {PIPE_FORMAT_R32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 1}, + {PIPE_FORMAT_R32G32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 2}, + {PIPE_FORMAT_R32G32B32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 3}, + {PIPE_FORMAT_R32G32B32A32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 4}, + + {PIPE_FORMAT_R32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 1}, + {PIPE_FORMAT_R32G32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 2}, + {PIPE_FORMAT_R32G32B32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 3}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 4}, + + {PIPE_FORMAT_R16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 1}, + {PIPE_FORMAT_R16G16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 2}, + {PIPE_FORMAT_R16G16B16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 3}, + {PIPE_FORMAT_R16G16B16A16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 4}, + + {PIPE_FORMAT_R16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 1}, + {PIPE_FORMAT_R16G16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 2}, + {PIPE_FORMAT_R16G16B16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 3}, + {PIPE_FORMAT_R16G16B16A16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 4}, + + {PIPE_FORMAT_R16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 1}, + {PIPE_FORMAT_R16G16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 2}, + {PIPE_FORMAT_R16G16B16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 3}, + {PIPE_FORMAT_R16G16B16A16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 4}, + + {PIPE_FORMAT_R16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 1}, + {PIPE_FORMAT_R16G16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 2}, + {PIPE_FORMAT_R16G16B16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 3}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 4}, + + {PIPE_FORMAT_R8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 1}, + {PIPE_FORMAT_R8G8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 2}, + {PIPE_FORMAT_R8G8B8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 3}, + {PIPE_FORMAT_R8G8B8A8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 4}, + + {PIPE_FORMAT_R8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 1}, + {PIPE_FORMAT_R8G8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 2}, + {PIPE_FORMAT_R8G8B8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 3}, + {PIPE_FORMAT_R8G8B8A8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 4}, + + {PIPE_FORMAT_R8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 1}, + {PIPE_FORMAT_R8G8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 2}, + {PIPE_FORMAT_R8G8B8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 3}, + {PIPE_FORMAT_R8G8B8A8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 4}, + + {PIPE_FORMAT_R8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 1}, + {PIPE_FORMAT_R8G8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 2}, + {PIPE_FORMAT_R8G8B8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 3}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 4}, + + {PIPE_FORMAT_R32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 1}, + {PIPE_FORMAT_R32G32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 2}, + {PIPE_FORMAT_R32G32B32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 3}, + {PIPE_FORMAT_R32G32B32A32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 4}, + + {PIPE_FORMAT_A8R8G8B8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 4}, + {PIPE_FORMAT_B8G8R8A8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(), 4}, +}; + +/** + * Fetch vertex attributes for 'count' vertices. + */ +static void PIPE_CDECL generic_run_elts( struct translate *translate, + const unsigned *elts, + unsigned count, + unsigned instance_id, + void *output_buffer ) +{ + struct translate_generic *tg = translate_generic(translate); + char *vert = output_buffer; + unsigned nr_attrs = tg->nr_attrib; + unsigned attr; + unsigned i; + + /* loop over vertex attributes (vertex shader inputs) + */ + for (i = 0; i < count; i++) { + unsigned elt = *elts++; + + for (attr = 0; attr < nr_attrs; attr++) { + float data[4]; + const char *src; + + char *dst = (vert + + tg->attrib[attr].output_offset); + + if (tg->attrib[attr].instance_divisor) { + src = tg->attrib[attr].input_ptr + + tg->attrib[attr].input_stride * + (instance_id / tg->attrib[attr].instance_divisor); + } else { + src = tg->attrib[attr].input_ptr + + tg->attrib[attr].input_stride * elt; + } + + tg->attrib[attr].fetch( src, data ); + + if (0) debug_printf("vert %d/%d attr %d: %f %f %f %f\n", + i, elt, attr, data[0], data[1], data[2], data[3]); + + tg->attrib[attr].emit( data, dst ); + } + + vert += tg->translate.key.output_stride; + } +} + + + +static void PIPE_CDECL generic_run( struct translate *translate, + unsigned start, + unsigned count, + unsigned instance_id, + void *output_buffer ) +{ + struct translate_generic *tg = translate_generic(translate); + char *vert = output_buffer; + unsigned nr_attrs = tg->nr_attrib; + unsigned attr; + unsigned i; + + /* loop over vertex attributes (vertex shader inputs) + */ + for (i = 0; i < count; i++) { + unsigned elt = start + i; + + for (attr = 0; attr < nr_attrs; attr++) { + float data[4]; + + char *dst = (vert + + tg->attrib[attr].output_offset); + + if (tg->attrib[attr].type == TRANSLATE_ELEMENT_NORMAL) { + const char *src; + + if (tg->attrib[attr].instance_divisor) { + src = tg->attrib[attr].input_ptr + + tg->attrib[attr].input_stride * + (instance_id / tg->attrib[attr].instance_divisor); + } else { + src = tg->attrib[attr].input_ptr + + tg->attrib[attr].input_stride * elt; + } + + tg->attrib[attr].fetch( src, data ); + } else { + data[0] = (float)instance_id; + } + + if (0) debug_printf("vert %d attr %d: %f %f %f %f\n", + i, attr, data[0], data[1], data[2], data[3]); + + tg->attrib[attr].emit( data, dst ); + } + + vert += tg->translate.key.output_stride; + } +} + + + +static void generic_set_buffer( struct translate *translate, + unsigned buf, + const void *ptr, + unsigned stride ) +{ + struct translate_generic *tg = translate_generic(translate); + unsigned i; + + for (i = 0; i < tg->nr_attrib; i++) { + if (tg->attrib[i].buffer == buf) { + tg->attrib[i].input_ptr = ((char *)ptr + + tg->attrib[i].input_offset); + tg->attrib[i].input_stride = stride; + } + } +} + + +static void generic_release( struct translate *translate ) +{ + /* Refcount? + */ + FREE(translate); +} + +struct translate *translate_generic_create( const struct translate_key *key ) +{ + struct translate_generic *tg = CALLOC_STRUCT(translate_generic); + unsigned i; + + if (tg == NULL) + return NULL; + + tg->translate.key = *key; + tg->translate.release = generic_release; + tg->translate.set_buffer = generic_set_buffer; + tg->translate.run_elts = generic_run_elts; + tg->translate.run = generic_run; + + for (i = 0; i < key->nr_elements; i++) { + tg->attrib[i].type = key->element[i].type; + + tg->attrib[i].fetch = get_fetch_func(key->element[i].input_format); + tg->attrib[i].buffer = key->element[i].input_buffer; + tg->attrib[i].input_offset = key->element[i].input_offset; + tg->attrib[i].instance_divisor = key->element[i].instance_divisor; + + tg->attrib[i].emit = get_emit_func(key->element[i].output_format); + tg->attrib[i].output_offset = key->element[i].output_offset; + + } + + tg->nr_attrib = key->nr_elements; + + + return &tg->translate; +} -- cgit v1.2.3 From f44af927ff90a9fe1256d8c6f4869a39a55043d3 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 29 Mar 2010 13:19:16 -0400 Subject: draw llvmpipe: lots of fixes for fetch/emit the values passed are still not right, but the general scheme is looking good. --- src/gallium/auxiliary/draw/draw_llvm.c | 155 ++++++++++++++++++-- src/gallium/auxiliary/draw/draw_llvm.h | 8 +- src/gallium/auxiliary/draw/draw_llvm_translate.c | 163 ++------------------- .../draw/draw_pt_fetch_shade_pipeline_llvm.c | 4 +- 4 files changed, 160 insertions(+), 170 deletions(-) (limited to 'src/gallium/auxiliary/draw/draw_llvm_translate.c') diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 6b0ddfd064..91fe838b8b 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -114,6 +114,10 @@ init_globals(struct draw_llvm *llvm) llvm->context_ptr_type = LLVMPointerType(context_type, 0); } + { + LLVMTypeRef buffer_ptr = LLVMPointerType(LLVMOpaqueType(), 0); + llvm->buffer_ptr_type = LLVMArrayType(buffer_ptr, PIPE_MAX_ATTRIBS); + } } struct draw_llvm * @@ -171,6 +175,7 @@ draw_llvm_destroy(struct draw_llvm *llvm) void draw_llvm_prepare(struct draw_llvm *llvm) { + draw_llvm_generate(llvm); } @@ -194,14 +199,14 @@ fail: static void generate_vs(struct draw_llvm *llvm, LLVMBuilderRef builder, + LLVMValueRef (*outputs)[NUM_CHANNELS], + const LLVMValueRef (*inputs)[NUM_CHANNELS], LLVMValueRef context_ptr, LLVMValueRef io) { const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens; struct lp_type vs_type = lp_type_float(32); LLVMValueRef vs_consts; - const LLVMValueRef (*inputs)[NUM_CHANNELS]; - LLVMValueRef (*outputs)[NUM_CHANNELS]; lp_build_tgsi_soa(builder, tokens, @@ -214,28 +219,129 @@ generate_vs(struct draw_llvm *llvm, NULL/*sampler*/); } +static void +generate_fetch(LLVMBuilderRef builder, + const LLVMValueRef vbuffers_ptr, + LLVMValueRef *res, + struct pipe_vertex_element *velem, + struct pipe_vertex_buffer *vbuf, + LLVMValueRef index) +{ + LLVMValueRef indices = LLVMConstInt(LLVMInt32Type(), + velem->vertex_buffer_index, 0); + LLVMValueRef vbuffer_ptr = LLVMBuildGEP(builder, vbuffers_ptr, + &indices, 1, ""); + LLVMValueRef stride = LLVMBuildMul(builder, + LLVMConstInt(LLVMInt32Type(), vbuf->stride, 0), + index, ""); + stride = LLVMBuildAdd(builder, stride, + LLVMConstInt(LLVMInt32Type(), vbuf->buffer_offset, 0), + ""); + stride = LLVMBuildAdd(builder, stride, + LLVMConstInt(LLVMInt32Type(), velem->src_offset, 0), + ""); + + vbuffer_ptr = LLVMBuildGEP(builder, vbuffer_ptr, &stride, 1, ""); + + *res = draw_llvm_translate_from(builder, vbuffer_ptr, velem->src_format); +} + +static LLVMValueRef +aos_to_soa(LLVMBuilderRef builder, + LLVMValueRef val0, + LLVMValueRef val1, + LLVMValueRef val2, + LLVMValueRef val3, + LLVMValueRef channel) +{ + LLVMValueRef ex, res; + + ex = LLVMBuildExtractElement(builder, val0, + channel, ""); + res = LLVMBuildInsertElement(builder, + LLVMConstNull(LLVMTypeOf(val0)), + ex, + LLVMConstInt(LLVMInt32Type(), 0, 0), + ""); + + ex = LLVMBuildExtractElement(builder, val1, + channel, ""); + res = LLVMBuildInsertElement(builder, + res, ex, + LLVMConstInt(LLVMInt32Type(), 1, 0), + ""); + + ex = LLVMBuildExtractElement(builder, val2, + channel, ""); + res = LLVMBuildInsertElement(builder, + res, ex, + LLVMConstInt(LLVMInt32Type(), 2, 0), + ""); + + ex = LLVMBuildExtractElement(builder, val3, + channel, ""); + res = LLVMBuildInsertElement(builder, + res, ex, + LLVMConstInt(LLVMInt32Type(), 3, 0), + ""); + + return res; +} + +static void +convert_to_soa(LLVMBuilderRef builder, + LLVMValueRef (*aos)[NUM_CHANNELS], + LLVMValueRef (*soa)[NUM_CHANNELS], + int num_attribs) +{ + int i; + + debug_assert(NUM_CHANNELS == 4); + + for (i = 0; i < num_attribs; ++i) { + LLVMValueRef val0 = aos[i][0]; + LLVMValueRef val1 = aos[i][1]; + LLVMValueRef val2 = aos[i][2]; + LLVMValueRef val3 = aos[i][3]; + + soa[i][0] = aos_to_soa(builder, val0, val1, val2, val3, + LLVMConstInt(LLVMInt32Type(), 0, 0)); + soa[i][1] = aos_to_soa(builder, val0, val1, val2, val3, + LLVMConstInt(LLVMInt32Type(), 1, 0)); + soa[i][2] = aos_to_soa(builder, val0, val1, val2, val3, + LLVMConstInt(LLVMInt32Type(), 2, 0)); + soa[i][3] = aos_to_soa(builder, val0, val1, val2, val3, + LLVMConstInt(LLVMInt32Type(), 3, 0)); + + } +} + void draw_llvm_generate(struct draw_llvm *llvm) { - LLVMTypeRef arg_types[5]; + LLVMTypeRef arg_types[6]; LLVMTypeRef func_type; LLVMValueRef context_ptr; LLVMBasicBlockRef block; LLVMBuilderRef builder; LLVMValueRef function; LLVMValueRef start, end, count, stride, step; - LLVMValueRef io_ptr; - unsigned i; + LLVMValueRef io_ptr, vbuffers_ptr; + struct draw_context *draw = llvm->draw; + unsigned i, j; unsigned chan; struct lp_build_context bld; struct lp_build_loop_state lp_loop; - struct lp_type vs_type = lp_type_float(32); + struct lp_type vs_type = lp_type_float_vec(32); + const int max_vertices = 4; + LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS]; arg_types[0] = llvm->context_ptr_type; /* context */ arg_types[1] = llvm->vertex_header_ptr_type; /* vertex_header */ - arg_types[2] = LLVMInt32Type(); /* start */ - arg_types[3] = LLVMInt32Type(); /* count */ - arg_types[4] = LLVMInt32Type(); /* stride */ + arg_types[2] = llvm->buffer_ptr_type; /* vbuffers */ + arg_types[3] = LLVMInt32Type(); /* start */ + arg_types[4] = LLVMInt32Type(); /* count */ + arg_types[5] = LLVMInt32Type(); /* stride */ func_type = LLVMFunctionType(LLVMVoidType(), arg_types, Elements(arg_types), 0); @@ -247,12 +353,14 @@ draw_llvm_generate(struct draw_llvm *llvm) context_ptr = LLVMGetParam(function, 0); io_ptr = LLVMGetParam(function, 1); - start = LLVMGetParam(function, 2); - count = LLVMGetParam(function, 3); - stride = LLVMGetParam(function, 4); + vbuffers_ptr = LLVMGetParam(function, 2); + start = LLVMGetParam(function, 3); + count = LLVMGetParam(function, 4); + stride = LLVMGetParam(function, 5); lp_build_name(context_ptr, "context"); lp_build_name(io_ptr, "io"); + lp_build_name(vbuffers_ptr, "vbuffers"); lp_build_name(start, "start"); lp_build_name(count, "count"); lp_build_name(stride, "stride"); @@ -269,13 +377,34 @@ draw_llvm_generate(struct draw_llvm *llvm) end = lp_build_add(&bld, start, count); - step = LLVMConstInt(LLVMInt32Type(), 1, 0); + step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0); lp_build_loop_begin(builder, start, &lp_loop); { + LLVMValueRef inputs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; + LLVMValueRef aos_attribs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; LLVMValueRef io = LLVMBuildGEP(builder, io_ptr, &lp_loop.counter, 1, ""); + for (i = 0; i < NUM_CHANNELS; ++i) { + LLVMValueRef true_index = LLVMBuildAdd( + builder, + lp_loop.counter, + LLVMConstInt(LLVMInt32Type(), i, 0), ""); + for (j = 0; j < draw->pt.nr_vertex_elements; ++j) { + struct pipe_vertex_element *velem = &draw->pt.vertex_element[j]; + struct pipe_vertex_buffer *vbuf = &draw->pt.vertex_buffer[ + velem->vertex_buffer_index]; + + generate_fetch(builder, vbuffers_ptr, + &aos_attribs[j][i], velem, vbuf, true_index); + } + } + convert_to_soa(builder, inputs, aos_attribs, + draw->pt.nr_vertex_elements); + generate_vs(llvm, builder, + outputs, + inputs, context_ptr, io); } diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h index 0a1845f1fb..cbbfeeccc5 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -78,12 +78,12 @@ struct draw_jit_context const float *gs_constants; struct draw_jit_texture textures[PIPE_MAX_SAMPLERS]; - const void *vbuffers; }; void draw_shader(struct draw_jit_context *context, struct vertex_header *io, + const void *vbuffers[PIPE_MAX_ATTRIBS], unsigned start, unsigned count, unsigned stride) @@ -115,6 +115,7 @@ draw_shader(struct draw_jit_context *context, typedef void (*draw_jit_vert_func)(struct draw_jit_context *context, struct vertex_header *io, + const void *vbuffers[PIPE_MAX_ATTRIBS], unsigned start, unsigned count, unsigned stride); @@ -134,6 +135,7 @@ struct draw_llvm { LLVMTypeRef context_ptr_type; LLVMTypeRef vertex_header_ptr_type; + LLVMTypeRef buffer_ptr_type; }; @@ -150,5 +152,9 @@ draw_llvm_prepare(struct draw_llvm *llvm); void draw_llvm_generate(struct draw_llvm *llvm); +LLVMValueRef +draw_llvm_translate_from(LLVMBuilderRef builder, + LLVMValueRef vbuffer, + enum pipe_format from_format); #endif diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c index 588e97b29c..012ca3f6f0 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_translate.c +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -492,162 +492,17 @@ struct draw_llvm_translate { {PIPE_FORMAT_B8G8R8A8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(), 4}, }; -/** - * Fetch vertex attributes for 'count' vertices. - */ -static void PIPE_CDECL generic_run_elts( struct translate *translate, - const unsigned *elts, - unsigned count, - unsigned instance_id, - void *output_buffer ) -{ - struct translate_generic *tg = translate_generic(translate); - char *vert = output_buffer; - unsigned nr_attrs = tg->nr_attrib; - unsigned attr; - unsigned i; - - /* loop over vertex attributes (vertex shader inputs) - */ - for (i = 0; i < count; i++) { - unsigned elt = *elts++; - - for (attr = 0; attr < nr_attrs; attr++) { - float data[4]; - const char *src; - - char *dst = (vert + - tg->attrib[attr].output_offset); - - if (tg->attrib[attr].instance_divisor) { - src = tg->attrib[attr].input_ptr + - tg->attrib[attr].input_stride * - (instance_id / tg->attrib[attr].instance_divisor); - } else { - src = tg->attrib[attr].input_ptr + - tg->attrib[attr].input_stride * elt; - } - - tg->attrib[attr].fetch( src, data ); - - if (0) debug_printf("vert %d/%d attr %d: %f %f %f %f\n", - i, elt, attr, data[0], data[1], data[2], data[3]); - - tg->attrib[attr].emit( data, dst ); - } - - vert += tg->translate.key.output_stride; - } -} - - -static void PIPE_CDECL generic_run( struct translate *translate, - unsigned start, - unsigned count, - unsigned instance_id, - void *output_buffer ) +LLVMValueRef +draw_llvm_translate_from(LLVMBuilderRef builder, + LLVMValueRef vbuffer, + enum pipe_format from_format) { - struct translate_generic *tg = translate_generic(translate); - char *vert = output_buffer; - unsigned nr_attrs = tg->nr_attrib; - unsigned attr; - unsigned i; - - /* loop over vertex attributes (vertex shader inputs) - */ - for (i = 0; i < count; i++) { - unsigned elt = start + i; - - for (attr = 0; attr < nr_attrs; attr++) { - float data[4]; - - char *dst = (vert + - tg->attrib[attr].output_offset); - - if (tg->attrib[attr].type == TRANSLATE_ELEMENT_NORMAL) { - const char *src; - - if (tg->attrib[attr].instance_divisor) { - src = tg->attrib[attr].input_ptr + - tg->attrib[attr].input_stride * - (instance_id / tg->attrib[attr].instance_divisor); - } else { - src = tg->attrib[attr].input_ptr + - tg->attrib[attr].input_stride * elt; - } - - tg->attrib[attr].fetch( src, data ); - } else { - data[0] = (float)instance_id; - } - - if (0) debug_printf("vert %d attr %d: %f %f %f %f\n", - i, attr, data[0], data[1], data[2], data[3]); - - tg->attrib[attr].emit( data, dst ); - } - - vert += tg->translate.key.output_stride; - } -} - - - -static void generic_set_buffer( struct translate *translate, - unsigned buf, - const void *ptr, - unsigned stride ) -{ - struct translate_generic *tg = translate_generic(translate); - unsigned i; - - for (i = 0; i < tg->nr_attrib; i++) { - if (tg->attrib[i].buffer == buf) { - tg->attrib[i].input_ptr = ((char *)ptr + - tg->attrib[i].input_offset); - tg->attrib[i].input_stride = stride; + int i; + for (i = 0; i < Elements(translates); ++i) { + if (translates[i].format == from_format) { + return translates.from_func(builder, vbuffer, from_format); } } -} - - -static void generic_release( struct translate *translate ) -{ - /* Refcount? - */ - FREE(translate); -} - -struct translate *translate_generic_create( const struct translate_key *key ) -{ - struct translate_generic *tg = CALLOC_STRUCT(translate_generic); - unsigned i; - - if (tg == NULL) - return NULL; - - tg->translate.key = *key; - tg->translate.release = generic_release; - tg->translate.set_buffer = generic_set_buffer; - tg->translate.run_elts = generic_run_elts; - tg->translate.run = generic_run; - - for (i = 0; i < key->nr_elements; i++) { - tg->attrib[i].type = key->element[i].type; - - tg->attrib[i].fetch = get_fetch_func(key->element[i].input_format); - tg->attrib[i].buffer = key->element[i].input_buffer; - tg->attrib[i].input_offset = key->element[i].input_offset; - tg->attrib[i].instance_divisor = key->element[i].instance_divisor; - - tg->attrib[i].emit = get_emit_func(key->element[i].output_format); - tg->attrib[i].output_offset = key->element[i].output_offset; - - } - - tg->nr_attrib = key->nr_elements; - - - return &tg->translate; + return LLVMGetUndef(LLVMTypeOf(vbuffer)); } diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c index ae5956333e..38b1c4462d 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c @@ -110,8 +110,7 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle, */ draw_pt_post_vs_prepare( fpme->post_vs, (boolean)draw->bypass_clipping, - (boolean)(draw->identity_viewport || - draw->rasterizer->bypass_vs_clip_and_viewport), + (boolean)(draw->identity_viewport), (boolean)draw->rasterizer->gl_rasterization_rules, (draw->vs.edgeflag_output ? true : false) ); @@ -242,6 +241,7 @@ static void llvm_middle_end_linear_run( struct draw_pt_middle_end *middle, fpme->llvm->jit_func( &fpme->llvm->jit_context, pipeline_verts, + draw->pt.user.vbuffer, start, count, fpme->vertex_size ); -- cgit v1.2.3 From 1963112f9d0a2ed8e237641eef8eb384365d1375 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 30 Mar 2010 12:35:40 -0400 Subject: draw llvm: various fixes for the translation code the from translation isn't quite right yet --- src/gallium/auxiliary/SConscript | 3 +- src/gallium/auxiliary/draw/draw_gs.c | 12 +- src/gallium/auxiliary/draw/draw_llvm.c | 12 +- src/gallium/auxiliary/draw/draw_llvm.h | 2 +- src/gallium/auxiliary/draw/draw_llvm_translate.c | 420 +++++++++++------------ 5 files changed, 206 insertions(+), 243 deletions(-) (limited to 'src/gallium/auxiliary/draw/draw_llvm_translate.c') diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 76675fb69c..b234b2f5f4 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -205,7 +205,8 @@ if drawllvm: 'gallivm/lp_bld_tgsi_soa.c', 'gallivm/lp_bld_type.c', 'draw/draw_llvm.c', - 'draw/draw_pt_fetch_shade_pipeline_llvm.c' + 'draw/draw_pt_fetch_shade_pipeline_llvm.c', + 'draw/draw_llvm_translate.c' ] gallium = env.ConvenienceLibrary( diff --git a/src/gallium/auxiliary/draw/draw_gs.c b/src/gallium/auxiliary/draw/draw_gs.c index 7069aa6b18..131deed43e 100644 --- a/src/gallium/auxiliary/draw/draw_gs.c +++ b/src/gallium/auxiliary/draw/draw_gs.c @@ -342,10 +342,10 @@ void draw_geometry_shader_delete(struct draw_geometry_shader *shader) void draw_geometry_shader_prepare(struct draw_geometry_shader *shader, struct draw_context *draw) { - if (shader->machine->Tokens != shader->state.tokens) { - tgsi_exec_machine_bind_shader(shader->machine, - shader->state.tokens, - draw->gs.num_samplers, - draw->gs.samplers); - } + if (shader && shader->machine->Tokens != shader->state.tokens) { + tgsi_exec_machine_bind_shader(shader->machine, + shader->state.tokens, + draw->gs.num_samplers, + draw->gs.samplers); + } } diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 91fe838b8b..aa4a310a07 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -115,8 +115,8 @@ init_globals(struct draw_llvm *llvm) llvm->context_ptr_type = LLVMPointerType(context_type, 0); } { - LLVMTypeRef buffer_ptr = LLVMPointerType(LLVMOpaqueType(), 0); - llvm->buffer_ptr_type = LLVMArrayType(buffer_ptr, PIPE_MAX_ATTRIBS); + LLVMTypeRef buffer_ptr = LLVMPointerType(LLVMIntType(8), 0); + llvm->buffer_ptr_type = LLVMPointerType(buffer_ptr, 0); } } @@ -221,19 +221,19 @@ generate_vs(struct draw_llvm *llvm, static void generate_fetch(LLVMBuilderRef builder, - const LLVMValueRef vbuffers_ptr, + LLVMValueRef vbuffers_ptr, LLVMValueRef *res, struct pipe_vertex_element *velem, struct pipe_vertex_buffer *vbuf, LLVMValueRef index) { - LLVMValueRef indices = LLVMConstInt(LLVMInt32Type(), - velem->vertex_buffer_index, 0); + LLVMValueRef indices = LLVMConstInt(LLVMInt64Type(), velem->vertex_buffer_index, 0); LLVMValueRef vbuffer_ptr = LLVMBuildGEP(builder, vbuffers_ptr, &indices, 1, ""); LLVMValueRef stride = LLVMBuildMul(builder, LLVMConstInt(LLVMInt32Type(), vbuf->stride, 0), index, ""); + stride = LLVMBuildAdd(builder, stride, LLVMConstInt(LLVMInt32Type(), vbuf->buffer_offset, 0), ""); @@ -393,7 +393,7 @@ draw_llvm_generate(struct draw_llvm *llvm) struct pipe_vertex_element *velem = &draw->pt.vertex_element[j]; struct pipe_vertex_buffer *vbuf = &draw->pt.vertex_buffer[ velem->vertex_buffer_index]; - + LLVMDumpValue(function); generate_fetch(builder, vbuffers_ptr, &aos_attribs[j][i], velem, vbuf, true_index); } diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h index cbbfeeccc5..e375008f3b 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -115,7 +115,7 @@ draw_shader(struct draw_jit_context *context, typedef void (*draw_jit_vert_func)(struct draw_jit_context *context, struct vertex_header *io, - const void *vbuffers[PIPE_MAX_ATTRIBS], + const char *vbuffers[PIPE_MAX_ATTRIBS], unsigned start, unsigned count, unsigned stride); diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c index 012ca3f6f0..6cbe98c489 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_translate.c +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -1,86 +1,23 @@ +#include "draw_private.h" +#include "draw_context.h" +#include "draw_llvm.h" +#include "gallivm/lp_bld_arit.h" +#include "gallivm/lp_bld_interp.h" +#include "gallivm/lp_bld_struct.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_flow.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_tgsi.h" #include "util/u_memory.h" #include "pipe/p_state.h" -#include "translate.h" #define DRAW_DBG 0 -typedef void (*fetch_func)(const void *ptr, float *attrib); -typedef void (*emit_func)(const float *attrib, void *ptr); - - - -struct translate_generic { - struct translate translate; - - struct { - enum translate_element_type type; - - fetch_func fetch; - unsigned buffer; - unsigned input_offset; - unsigned instance_divisor; - - emit_func emit; - unsigned output_offset; - - char *input_ptr; - unsigned input_stride; - - } attrib[PIPE_MAX_ATTRIBS]; - - unsigned nr_attrib; -}; - - -static struct translate_generic *translate_generic( struct translate *translate ) -{ - return (struct translate_generic *)translate; -} - -/** - * Fetch a float[4] vertex attribute from memory, doing format/type - * conversion as needed. - * - * This is probably needed/dupliocated elsewhere, eg format - * conversion, texture sampling etc. - */ -#define ATTRIB( NAME, SZ, TYPE, FROM, TO ) \ -static void \ -fetch_##NAME(const void *ptr, float *attrib) \ -{ \ - const float defaults[4] = { 0.0f,0.0f,0.0f,1.0f }; \ - unsigned i; \ - \ - for (i = 0; i < SZ; i++) { \ - attrib[i] = FROM(i); \ - } \ - \ - for (; i < 4; i++) { \ - attrib[i] = defaults[i]; \ - } \ -} \ - \ -static void \ -emit_##NAME(const float *attrib, void *ptr) \ -{ \ - unsigned i; \ - TYPE *out = (TYPE *)ptr; \ - \ - for (i = 0; i < SZ; i++) { \ - out[i] = TO(attrib[i]); \ - } \ -} - -{ - - return conv = instr(builder, bc, ""); -} - -static INLINE LLVMValueRef +static LLVMValueRef from_64_float(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, @@ -89,7 +26,7 @@ from_64_float(LLVMBuilderRef builder, LLVMValueRef val) return LLVMBuildFPTrunc(builder, l, LLVMFloatType(), ""); } -static INLINE LLVMValueRef +static LLVMValueRef from_32_float(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, @@ -154,7 +91,7 @@ from_8_unorm(LLVMBuilderRef builder, LLVMValueRef val) LLVMValueRef l = LLVMBuildLoad(builder, val, ""); LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, - LLVMConstReal(builder, 255.)); + LLVMConstReal(LLVMFloatType(), 255.), ""); } static INLINE LLVMValueRef @@ -165,7 +102,7 @@ from_16_unorm(LLVMBuilderRef builder, LLVMValueRef val) LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, - LLVMConstReal(builder, 65535.)); + LLVMConstReal(LLVMFloatType(), 65535.), ""); } static INLINE LLVMValueRef @@ -177,7 +114,7 @@ from_32_unorm(LLVMBuilderRef builder, LLVMValueRef val) LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, - LLVMConstReal(builder, 4294967295.)); + LLVMConstReal(LLVMFloatType(), 4294967295.), ""); } static INLINE LLVMValueRef @@ -186,7 +123,7 @@ from_8_snorm(LLVMBuilderRef builder, LLVMValueRef val) LLVMValueRef l = LLVMBuildLoad(builder, val, ""); LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, - LLVMConstReal(builder, 127.0)); + LLVMConstReal(LLVMFloatType(), 127.0), ""); } static INLINE LLVMValueRef @@ -197,7 +134,7 @@ from_16_snorm(LLVMBuilderRef builder, LLVMValueRef val) LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, - LLVMConstReal(builder, 32767.0f)); + LLVMConstReal(LLVMFloatType(), 32767.0f), ""); } static INLINE LLVMValueRef @@ -209,7 +146,7 @@ from_32_snorm(LLVMBuilderRef builder, LLVMValueRef val) LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, - LLVMConstReal(builder, 2147483647.0)); + LLVMConstReal(LLVMFloatType(), 2147483647.0), ""); } static INLINE LLVMValueRef @@ -221,23 +158,23 @@ from_32_fixed(LLVMBuilderRef builder, LLVMValueRef val) LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, - LLVMConstReal(builder, 65536.0)); + LLVMConstReal(LLVMFloatType(), 65536.0), ""); } -static INLINE LLVMValueRef +static LLVMValueRef to_64_float(LLVMBuilderRef builder, LLVMValueRef fp) { LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); return LLVMBuildFPExt(builder, l, LLVMDoubleType(), ""); } -static INLINE LLVMValueRef +static LLVMValueRef to_32_float(LLVMBuilderRef builder, LLVMValueRef fp) { return LLVMBuildLoad(builder, fp, ""); } -atic INLINE LLVMValueRef +static INLINE LLVMValueRef to_8_uscaled(LLVMBuilderRef builder, LLVMValueRef fp) { LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); @@ -285,7 +222,7 @@ to_8_unorm(LLVMBuilderRef builder, LLVMValueRef fp) LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(8), ""); return LLVMBuildFMul(builder, uscaled, - LLVMConstReal(builder, 255.)); + LLVMConstReal(LLVMFloatType(), 255.), ""); } static INLINE LLVMValueRef @@ -294,7 +231,7 @@ to_16_unorm(LLVMBuilderRef builder, LLVMValueRef fp) LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), ""); return LLVMBuildFMul(builder, uscaled, - LLVMConstReal(builder, 65535.)); + LLVMConstReal(LLVMFloatType(), 65535.), ""); } static INLINE LLVMValueRef @@ -304,7 +241,7 @@ to_32_unorm(LLVMBuilderRef builder, LLVMValueRef fp) LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), ""); return LLVMBuildFMul(builder, uscaled, - LLVMConstReal(builder, 4294967295.)); + LLVMConstReal(LLVMFloatType(), 4294967295.), ""); } static INLINE LLVMValueRef @@ -312,8 +249,8 @@ to_8_snorm(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef l = LLVMBuildLoad(builder, val, ""); LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(8), ""); - return LLVMBuildFMUL(builder, uscaled, - LLVMConstReal(builder, 127.0)); + return LLVMBuildFMul(builder, uscaled, + LLVMConstReal(LLVMFloatType(), 127.0), ""); } static INLINE LLVMValueRef @@ -322,7 +259,7 @@ to_16_snorm(LLVMBuilderRef builder, LLVMValueRef fp) LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(16), ""); return LLVMBuildFMul(builder, uscaled, - LLVMConstReal(builder, 32767.0f)); + LLVMConstReal(LLVMFloatType(), 32767.0f), ""); } static INLINE LLVMValueRef @@ -331,8 +268,8 @@ to_32_snorm(LLVMBuilderRef builder, LLVMValueRef fp) LLVMValueRef l = LLVMBuildLoad(builder, fp, ""); LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), ""); - return LLVMBuildFMUL(builder, uscaled, - LLVMConstReal(builder, 2147483647.0)); + return LLVMBuildFMul(builder, uscaled, + LLVMConstReal(LLVMFloatType(), 2147483647.0), ""); } static INLINE LLVMValueRef @@ -342,156 +279,176 @@ to_32_fixed(LLVMBuilderRef builder, LLVMValueRef fp) LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), ""); return LLVMBuildFMul(builder, uscaled, - LLVMConstReal(builder, 65536.0)); + LLVMConstReal(LLVMFloatType(), 65536.0), ""); +} + +typedef LLVMValueRef (*from_func)(LLVMBuilderRef, LLVMValueRef); +typedef LLVMValueRef (*to_func)(LLVMBuilderRef, LLVMValueRef); + +/* so that underneath can avoid function calls which are prohibited + * for static initialization we need this conversion */ +enum ll_type { + LL_Double, + LL_Float, + LL_Int32, + LL_Int16, + LL_Int8 +}; + +static INLINE LLVMTypeRef +ll_type_to_llvm(enum ll_type type) +{ + switch (type) { + case LL_Double: + return LLVMDoubleType(); + case LL_Float: + return LLVMFloatType(); + case LL_Int32: + return LLVMInt32Type(); + case LL_Int16: + return LLVMIntType(16); + case LL_Int8: + return LLVMIntType(8); + } + return LLVMIntType(8); +} + +static INLINE int +ll_type_size(enum ll_type type) +{ + switch (type) { + case LL_Double: + return 8; + case LL_Float: + return 4; + case LL_Int32: + return 4; + case LL_Int16: + return 2; + case LL_Int8: + return 1; + } + return 1; } +struct draw_llvm_translate { + int format; + from_func from; + to_func to; + enum ll_type type; + int num_components; +} translates[] = +{ + {PIPE_FORMAT_R64_FLOAT, from_64_float, to_64_float, LL_Double, 1}, + {PIPE_FORMAT_R64G64_FLOAT, from_64_float, to_64_float, LL_Double, 2}, + {PIPE_FORMAT_R64G64B64_FLOAT, from_64_float, to_64_float, LL_Double, 3}, + {PIPE_FORMAT_R64G64B64A64_FLOAT, from_64_float, to_64_float, LL_Double, 4}, + {PIPE_FORMAT_R32_FLOAT, from_32_float, to_32_float, LL_Float, 1}, + {PIPE_FORMAT_R32G32_FLOAT, from_32_float, to_32_float, LL_Float, 2}, + {PIPE_FORMAT_R32G32B32_FLOAT, from_32_float, to_32_float, LL_Float, 3}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, from_32_float, to_32_float, LL_Float, 4}, + + {PIPE_FORMAT_R32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 4}, + + {PIPE_FORMAT_R32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 4}, + + {PIPE_FORMAT_R32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 4}, + + {PIPE_FORMAT_R32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 4}, + + {PIPE_FORMAT_R16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 4}, + + {PIPE_FORMAT_R16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 4}, + + {PIPE_FORMAT_R16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 4}, + + {PIPE_FORMAT_R16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 4}, + + {PIPE_FORMAT_R8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 4}, + + {PIPE_FORMAT_R8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 4}, + + {PIPE_FORMAT_R8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 4}, + + {PIPE_FORMAT_R8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 4}, + + {PIPE_FORMAT_R32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 4}, + + {PIPE_FORMAT_A8R8G8B8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 4}, + {PIPE_FORMAT_B8G8R8A8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 4}, +}; + + static LLVMValueRef -fetch(LLVMValueRef ptr, int val_size, int nr_components, - LLVMValueRef res) +fetch(LLVMBuilderRef builder, + LLVMValueRef ptr, int val_size, int nr_components, + from_func func) { int i; int offset = 0; + LLVMValueRef res = LLVMConstNull( + LLVMVectorType(LLVMFloatType(), 4)); for (i = 0; i < nr_components; ++i) { LLVMValueRef src_index = LLVMConstInt(LLVMInt32Type(), offset, 0); LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0); - //getelementptr i8* ptr, i64 offset LLVMValueRef src_tmp = LLVMBuildGEP(builder, ptr, &src_index, 1, ""); - //getelementptr float* res, i64 i - LLVMValueRef res_tmp = LLVMBuildGEP(builder, res, &dst_index, 1, ""); - //bitcast i8* src, to res_type* - //load res_type src - //convert res_type src to float - //store float src, float *dst src - offset += val_size; - } -} - - -static void -fetch_B8G8R8A8_UNORM(const void *ptr, float *attrib) -{ - attrib[2] = FROM_8_UNORM(0); - attrib[1] = FROM_8_UNORM(1); - attrib[0] = FROM_8_UNORM(2); - attrib[3] = FROM_8_UNORM(3); -} + LLVMValueRef component; -static void -emit_B8G8R8A8_UNORM( const float *attrib, void *ptr) -{ - ubyte *out = (ubyte *)ptr; - out[2] = TO_8_UNORM(attrib[0]); - out[1] = TO_8_UNORM(attrib[1]); - out[0] = TO_8_UNORM(attrib[2]); - out[3] = TO_8_UNORM(attrib[3]); -} + src_tmp = LLVMBuildLoad(builder, src_tmp, ""); -static void -fetch_NULL( const void *ptr, float *attrib ) -{ - attrib[0] = 0; - attrib[1] = 0; - attrib[2] = 0; - attrib[3] = 1; -} + /* convert src_tmp to float */ + component = func(builder, src_tmp); -static void -emit_NULL( const float *attrib, void *ptr ) -{ - /* do nothing is the only sensible option */ + /* vec.comp = component */ + res = LLVMBuildInsertElement(builder, + res, + component, + dst_index, ""); + offset += val_size; + } + return res; } -typedef LLVMValueRef (*from_func)(LLVMBuilderRef, LLVMValueRef); -typedef LLVMValueRef (*to_func)(LLVMBuilderRef, LLVMValueRef); - -struct draw_llvm_translate { - int format; - from_func from; - to_func to; - LLVMTypeRef type; - int num_components; -} translates[] = -{ - {PIPE_FORMAT_R64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 1}, - {PIPE_FORMAT_R64G64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 2}, - {PIPE_FORMAT_R64G64B64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 3}, - {PIPE_FORMAT_R64G64B64A64_FLOAT, from_64_float, to_64_float, LLVMDoubleType(), 4}, - - {PIPE_FORMAT_R32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 1}, - {PIPE_FORMAT_R32G32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 2}, - {PIPE_FORMAT_R32G32B32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 3}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, from_32_float, to_32_float, LLVMFloatType(), 4}, - - {PIPE_FORMAT_R32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 1}, - {PIPE_FORMAT_R32G32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 2}, - {PIPE_FORMAT_R32G32B32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 3}, - {PIPE_FORMAT_R32G32B32A32_UNORM, from_32_unorm, to_32_unorm, LLVMIntType(32), 4}, - - {PIPE_FORMAT_R32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 1}, - {PIPE_FORMAT_R32G32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 2}, - {PIPE_FORMAT_R32G32B32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 3}, - {PIPE_FORMAT_R32G32B32A32_USCALED, from_32_uscaled, to_32_uscaled, LLVMIntType(32), 4}, - - {PIPE_FORMAT_R32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 1}, - {PIPE_FORMAT_R32G32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 2}, - {PIPE_FORMAT_R32G32B32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 3}, - {PIPE_FORMAT_R32G32B32A32_SNORM, from_32_snorm, to_32_snorm, LLVMIntType(32), 4}, - - {PIPE_FORMAT_R32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 1}, - {PIPE_FORMAT_R32G32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 2}, - {PIPE_FORMAT_R32G32B32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 3}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, from_32_sscaled, to_32_sscaled, LLVMIntType(32), 4}, - - {PIPE_FORMAT_R16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 1}, - {PIPE_FORMAT_R16G16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 2}, - {PIPE_FORMAT_R16G16B16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 3}, - {PIPE_FORMAT_R16G16B16A16_UNORM, from_16_unorm, to_16_unorm, LLVMIntType(16), 4}, - - {PIPE_FORMAT_R16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 1}, - {PIPE_FORMAT_R16G16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 2}, - {PIPE_FORMAT_R16G16B16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 3}, - {PIPE_FORMAT_R16G16B16A16_USCALED, from_16_uscaled, to_16_uscaled, LLVMIntType(16), 4}, - - {PIPE_FORMAT_R16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 1}, - {PIPE_FORMAT_R16G16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 2}, - {PIPE_FORMAT_R16G16B16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 3}, - {PIPE_FORMAT_R16G16B16A16_SNORM, from_16_snorm, to_16_snorm, LLVMIntType(16), 4}, - - {PIPE_FORMAT_R16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 1}, - {PIPE_FORMAT_R16G16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 2}, - {PIPE_FORMAT_R16G16B16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 3}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, from_16_sscaled, to_16_sscaled, LLVMIntType(16), 4}, - - {PIPE_FORMAT_R8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 1}, - {PIPE_FORMAT_R8G8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 2}, - {PIPE_FORMAT_R8G8B8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 3}, - {PIPE_FORMAT_R8G8B8A8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 4}, - - {PIPE_FORMAT_R8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 1}, - {PIPE_FORMAT_R8G8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 2}, - {PIPE_FORMAT_R8G8B8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 3}, - {PIPE_FORMAT_R8G8B8A8_USCALED, from_8_uscaled, to_8_uscaled, LLVMIntType(8), 4}, - - {PIPE_FORMAT_R8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 1}, - {PIPE_FORMAT_R8G8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 2}, - {PIPE_FORMAT_R8G8B8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 3}, - {PIPE_FORMAT_R8G8B8A8_SNORM, from_8_snorm, to_8_snorm, LLVMIntType(8), 4}, - - {PIPE_FORMAT_R8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 1}, - {PIPE_FORMAT_R8G8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 2}, - {PIPE_FORMAT_R8G8B8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 3}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, from_8_sscaled, to_8_sscaled, LLVMIntType(8), 4}, - - {PIPE_FORMAT_R32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 1}, - {PIPE_FORMAT_R32G32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 2}, - {PIPE_FORMAT_R32G32B32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 3}, - {PIPE_FORMAT_R32G32B32A32_FIXED, from_32_fixed, to_32_fixed, LLVMIntType(32), 4}, - - {PIPE_FORMAT_A8R8G8B8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(8), 4}, - {PIPE_FORMAT_B8G8R8A8_UNORM, from_8_unorm, to_8_unorm, LLVMIntType(), 4}, -}; - LLVMValueRef draw_llvm_translate_from(LLVMBuilderRef builder, @@ -501,8 +458,13 @@ draw_llvm_translate_from(LLVMBuilderRef builder, int i; for (i = 0; i < Elements(translates); ++i) { if (translates[i].format == from_format) { - return translates.from_func(builder, vbuffer, from_format); + /*LLVMTypeRef type = ll_type_to_llvm(translates[i].type);*/ + return fetch(builder, + vbuffer, + ll_type_size(translates[i].type), + translates[i].num_components, + translates[i].from); } } - return LLVMGetUndef(LLVMTypeOf(vbuffer)); + return LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4)); } -- cgit v1.2.3 From 6f34339af421d4001dcc01114be462d2ea381f16 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 30 Mar 2010 12:52:09 -0400 Subject: draw llvm: we translate between pointers, not values directly --- src/gallium/auxiliary/draw/draw_llvm_translate.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/gallium/auxiliary/draw/draw_llvm_translate.c') diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c index 6cbe98c489..74830f1b46 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_translate.c +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -21,7 +21,7 @@ static LLVMValueRef from_64_float(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMDoubleType() , ""); + LLVMPointerType(LLVMDoubleType(), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); return LLVMBuildFPTrunc(builder, l, LLVMFloatType(), ""); } @@ -30,7 +30,7 @@ static LLVMValueRef from_32_float(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMFloatType() , ""); + LLVMPointerType(LLVMFloatType(), 0) , ""); return LLVMBuildLoad(builder, bc, ""); } @@ -45,7 +45,7 @@ static INLINE LLVMValueRef from_16_uscaled(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(16) , ""); + LLVMPointerType(LLVMIntType(16), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); return LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); } @@ -54,7 +54,7 @@ static INLINE LLVMValueRef from_32_uscaled(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(32) , ""); + LLVMPointerType(LLVMIntType(32), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); return LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); } @@ -70,7 +70,7 @@ static INLINE LLVMValueRef from_16_sscaled(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(16) , ""); + LLVMPointerType(LLVMIntType(16), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); return LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); } @@ -79,7 +79,7 @@ static INLINE LLVMValueRef from_32_sscaled(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(32) , ""); + LLVMPointerType(LLVMIntType(32), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); return LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); } @@ -98,7 +98,7 @@ static INLINE LLVMValueRef from_16_unorm(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(16) , ""); + LLVMPointerType(LLVMIntType(16), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, @@ -109,7 +109,7 @@ static INLINE LLVMValueRef from_32_unorm(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(32) , ""); + LLVMPointerType(LLVMIntType(32), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), ""); @@ -130,7 +130,7 @@ static INLINE LLVMValueRef from_16_snorm(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(16) , ""); + LLVMPointerType(LLVMIntType(16), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); return LLVMBuildFDiv(builder, uscaled, @@ -141,7 +141,7 @@ static INLINE LLVMValueRef from_32_snorm(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(32) , ""); + LLVMPointerType(LLVMIntType(32), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); @@ -153,7 +153,7 @@ static INLINE LLVMValueRef from_32_fixed(LLVMBuilderRef builder, LLVMValueRef val) { LLVMValueRef bc = LLVMBuildBitCast(builder, val, - LLVMIntType(32) , ""); + LLVMPointerType(LLVMIntType(32), 0) , ""); LLVMValueRef l = LLVMBuildLoad(builder, bc, ""); LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), ""); @@ -436,6 +436,7 @@ fetch(LLVMBuilderRef builder, src_tmp = LLVMBuildLoad(builder, src_tmp, ""); + LLVMDumpValue(src_tmp); /* convert src_tmp to float */ component = func(builder, src_tmp); -- cgit v1.2.3 From 8bc07fc83e344c9e693bdec4148009320a1731f1 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 30 Mar 2010 16:16:36 -0400 Subject: draw llvm: fix some silly mistakes the vs_type selection isn't ideal, but for now both llvmpipe's fs and vs do the same thing which is operate on 4xfloat vector as the base type --- src/gallium/auxiliary/draw/draw_llvm.c | 22 +++++++++++++++------- src/gallium/auxiliary/draw/draw_llvm_translate.c | 1 - 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src/gallium/auxiliary/draw/draw_llvm_translate.c') diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index aa4a310a07..cd183d5087 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -205,14 +205,24 @@ generate_vs(struct draw_llvm *llvm, LLVMValueRef io) { const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens; - struct lp_type vs_type = lp_type_float(32); - LLVMValueRef vs_consts; + struct lp_type vs_type; + LLVMValueRef consts_ptr = draw_jit_context_vs_constants(builder, context_ptr); + + memset(&vs_type, 0, sizeof vs_type); + vs_type.floating = TRUE; /* floating point values */ + vs_type.sign = TRUE; /* values are signed */ + vs_type.norm = FALSE; /* values are not limited to [0,1] or [-1,1] */ + vs_type.width = 32; /* 32-bit float */ + vs_type.length = 4; /* 4 elements per vector */ +#if 0 + num_vs = 4; /* number of vertices per block */ +#endif lp_build_tgsi_soa(builder, tokens, vs_type, NULL /*struct lp_build_mask_context *mask*/, - vs_consts, + consts_ptr, NULL /*pos*/, inputs, outputs, @@ -312,7 +322,6 @@ convert_to_soa(LLVMBuilderRef builder, LLVMConstInt(LLVMInt32Type(), 2, 0)); soa[i][3] = aos_to_soa(builder, val0, val1, val2, val3, LLVMConstInt(LLVMInt32Type(), 3, 0)); - } } @@ -329,7 +338,6 @@ draw_llvm_generate(struct draw_llvm *llvm) LLVMValueRef io_ptr, vbuffers_ptr; struct draw_context *draw = llvm->draw; unsigned i, j; - unsigned chan; struct lp_build_context bld; struct lp_build_loop_state lp_loop; struct lp_type vs_type = lp_type_float_vec(32); @@ -393,12 +401,11 @@ draw_llvm_generate(struct draw_llvm *llvm) struct pipe_vertex_element *velem = &draw->pt.vertex_element[j]; struct pipe_vertex_buffer *vbuf = &draw->pt.vertex_buffer[ velem->vertex_buffer_index]; - LLVMDumpValue(function); generate_fetch(builder, vbuffers_ptr, &aos_attribs[j][i], velem, vbuf, true_index); } } - convert_to_soa(builder, inputs, aos_attribs, + convert_to_soa(builder, aos_attribs, inputs, draw->pt.nr_vertex_elements); generate_vs(llvm, @@ -407,6 +414,7 @@ draw_llvm_generate(struct draw_llvm *llvm) inputs, context_ptr, io); + LLVMDumpModule(llvm->module); } lp_build_loop_end(builder, end, step, &lp_loop); diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c index 74830f1b46..260568aaa4 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_translate.c +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -436,7 +436,6 @@ fetch(LLVMBuilderRef builder, src_tmp = LLVMBuildLoad(builder, src_tmp, ""); - LLVMDumpValue(src_tmp); /* convert src_tmp to float */ component = func(builder, src_tmp); -- cgit v1.2.3 From ae5487d4276007e466b6a7c783d6fb740f9539c5 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Wed, 31 Mar 2010 22:15:12 -0400 Subject: draw llvm: fix iteration over buffers fetching was converting garbage --- src/gallium/auxiliary/draw/draw_llvm.c | 25 ++++++++++++++++++++++-- src/gallium/auxiliary/draw/draw_llvm_translate.c | 5 +++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src/gallium/auxiliary/draw/draw_llvm_translate.c') diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 6347acb0b9..2978621826 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -10,6 +10,7 @@ #include "gallivm/lp_bld_flow.h" #include "gallivm/lp_bld_debug.h" #include "gallivm/lp_bld_tgsi.h" +#include "gallivm/lp_bld_printf.h" #include "util/u_cpu_detect.h" @@ -229,6 +230,23 @@ generate_vs(struct draw_llvm *llvm, NULL/*sampler*/); } + +static void print_vectorf(LLVMBuilderRef builder, + LLVMValueRef vec) +{ + LLVMValueRef val[4]; + val[0] = LLVMBuildExtractElement(builder, vec, + LLVMConstInt(LLVMInt32Type(), 0, 0), ""); + val[1] = LLVMBuildExtractElement(builder, vec, + LLVMConstInt(LLVMInt32Type(), 1, 0), ""); + val[2] = LLVMBuildExtractElement(builder, vec, + LLVMConstInt(LLVMInt32Type(), 2, 0), ""); + val[3] = LLVMBuildExtractElement(builder, vec, + LLVMConstInt(LLVMInt32Type(), 3, 0), ""); + lp_build_printf(builder, "vector = [%f, %f, %f, %f]\n", + val[0], val[1], val[2], val[3]); +} + static void generate_fetch(LLVMBuilderRef builder, LLVMValueRef vbuffers_ptr, @@ -244,6 +262,8 @@ generate_fetch(LLVMBuilderRef builder, LLVMConstInt(LLVMInt32Type(), vbuf->stride, 0), index, ""); + vbuffer_ptr = LLVMBuildLoad(builder, vbuffer_ptr, "vbuffer"); + stride = LLVMBuildAdd(builder, stride, LLVMConstInt(LLVMInt32Type(), vbuf->buffer_offset, 0), ""); @@ -251,6 +271,7 @@ generate_fetch(LLVMBuilderRef builder, LLVMConstInt(LLVMInt32Type(), velem->src_offset, 0), ""); + /*lp_build_printf(builder, "vbuf index = %d, stride is %d\n", indices, stride);*/ vbuffer_ptr = LLVMBuildGEP(builder, vbuffer_ptr, &stride, 1, ""); *res = draw_llvm_translate_from(builder, vbuffer_ptr, velem->src_format); @@ -386,6 +407,7 @@ draw_llvm_generate(struct draw_llvm *llvm) end = lp_build_add(&bld, start, count); step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0); + lp_build_loop_begin(builder, start, &lp_loop); { LLVMValueRef inputs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; @@ -404,6 +426,7 @@ draw_llvm_generate(struct draw_llvm *llvm) velem->vertex_buffer_index]; generate_fetch(builder, vbuffers_ptr, &aos_attribs[j][i], velem, vbuf, true_index); + /*print_vectorf(builder, aos_attribs[j][i]);*/ } } convert_to_soa(builder, aos_attribs, inputs, @@ -416,7 +439,6 @@ draw_llvm_generate(struct draw_llvm *llvm) ptr_aos, context_ptr, io); - LLVMDumpModule(llvm->module); } lp_build_loop_end(builder, end, step, &lp_loop); @@ -441,7 +463,6 @@ draw_llvm_generate(struct draw_llvm *llvm) LLVMDumpValue(function); debug_printf("\n"); } - llvm->jit_func = (draw_jit_vert_func)LLVMGetPointerToGlobal(llvm->draw->engine, function); if (1) diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c index 260568aaa4..bc17d3861a 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_translate.c +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -10,6 +10,7 @@ #include "gallivm/lp_bld_flow.h" #include "gallivm/lp_bld_debug.h" #include "gallivm/lp_bld_tgsi.h" +#include "gallivm/lp_bld_printf.h" #include "util/u_memory.h" #include "pipe/p_state.h" @@ -431,10 +432,10 @@ fetch(LLVMBuilderRef builder, for (i = 0; i < nr_components; ++i) { LLVMValueRef src_index = LLVMConstInt(LLVMInt32Type(), offset, 0); LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0); - LLVMValueRef src_tmp = LLVMBuildGEP(builder, ptr, &src_index, 1, ""); + LLVMValueRef src_tmp; LLVMValueRef component; - src_tmp = LLVMBuildLoad(builder, src_tmp, ""); + src_tmp = LLVMBuildGEP(builder, ptr, &src_index, 1, "src_tmp"); /* convert src_tmp to float */ component = func(builder, src_tmp); -- cgit v1.2.3 From 557b75248a3ebc6daabe3c2b69ac24d409aaa1e0 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Fri, 2 Apr 2010 15:56:34 -0400 Subject: draw llvm: fix translation of formats with variable components --- src/gallium/auxiliary/draw/draw_llvm_translate.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/gallium/auxiliary/draw/draw_llvm_translate.c') diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c index bc17d3861a..b29ebdec3a 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_translate.c +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -428,6 +428,12 @@ fetch(LLVMBuilderRef builder, int offset = 0; LLVMValueRef res = LLVMConstNull( LLVMVectorType(LLVMFloatType(), 4)); + LLVMValueRef defaults[4]; + + defaults[0] = LLVMConstReal(LLVMFloatType(), 0); + defaults[1] = LLVMConstReal(LLVMFloatType(), 0); + defaults[2] = LLVMConstReal(LLVMFloatType(), 0); + defaults[3] = LLVMConstReal(LLVMFloatType(), 1); for (i = 0; i < nr_components; ++i) { LLVMValueRef src_index = LLVMConstInt(LLVMInt32Type(), offset, 0); @@ -447,6 +453,13 @@ fetch(LLVMBuilderRef builder, dst_index, ""); offset += val_size; } + for (; i < 4; ++i) { + LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0); + res = LLVMBuildInsertElement(builder, + res, + defaults[i], + dst_index, ""); + } return res; } -- cgit v1.2.3