2009-07-26 23:44:38 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2009-08-14 10:27:32 +01:00
|
|
|
* Copyright 2009 VMware, Inc.
|
2009-07-26 23:44:38 +01:00
|
|
|
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
* 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 TUNGSTEN GRAPHICS 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.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-08-22 22:26:55 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Code generate the whole fragment pipeline.
|
|
|
|
*
|
|
|
|
* The fragment pipeline consists of the following stages:
|
|
|
|
* - early depth test
|
|
|
|
* - fragment shader
|
|
|
|
* - alpha test
|
2010-04-18 15:38:19 +01:00
|
|
|
* - depth/stencil test
|
2009-08-22 22:26:55 +01:00
|
|
|
* - blending
|
|
|
|
*
|
2010-03-11 21:03:33 +00:00
|
|
|
* This file has only the glue to assemble the fragment pipeline. The actual
|
2009-08-22 22:26:55 +01:00
|
|
|
* plumbing of converting Gallium state into LLVM IR is done elsewhere, in the
|
|
|
|
* lp_bld_*.[ch] files, and in a complete generic and reusable way. Here we
|
|
|
|
* muster the LLVM JIT execution engine to create a function that follows an
|
|
|
|
* established binary interface and that can be called from C directly.
|
|
|
|
*
|
|
|
|
* A big source of complexity here is that we often want to run different
|
|
|
|
* stages with different precisions and data types and precisions. For example,
|
|
|
|
* the fragment shader needs typically to be done in floats, but the
|
|
|
|
* depth/stencil test and blending is better done in the type that most closely
|
|
|
|
* matches the depth/stencil and color buffer respectively.
|
|
|
|
*
|
|
|
|
* Since the width of a SIMD vector register stays the same regardless of the
|
|
|
|
* element type, different types imply different number of elements, so we must
|
|
|
|
* code generate more instances of the stages with larger types to be able to
|
|
|
|
* feed/consume the stages with smaller types.
|
|
|
|
*
|
|
|
|
* @author Jose Fonseca <jfonseca@vmware.com>
|
|
|
|
*/
|
|
|
|
|
2010-01-08 21:49:34 +00:00
|
|
|
#include <limits.h>
|
2009-07-26 23:44:38 +01:00
|
|
|
#include "pipe/p_defines.h"
|
2010-02-02 14:42:17 +00:00
|
|
|
#include "util/u_inlines.h"
|
2009-07-26 23:44:38 +01:00
|
|
|
#include "util/u_memory.h"
|
2010-05-30 16:38:23 +01:00
|
|
|
#include "util/u_pointer.h"
|
2009-08-21 07:48:04 +01:00
|
|
|
#include "util/u_format.h"
|
2010-02-14 15:21:06 +00:00
|
|
|
#include "util/u_dump.h"
|
2010-06-03 14:22:41 +01:00
|
|
|
#include "util/u_string.h"
|
2010-06-18 13:52:17 +01:00
|
|
|
#include "util/u_simple_list.h"
|
2010-02-08 20:07:31 +00:00
|
|
|
#include "os/os_time.h"
|
2009-07-26 23:44:38 +01:00
|
|
|
#include "pipe/p_shader_tokens.h"
|
|
|
|
#include "draw/draw_context.h"
|
|
|
|
#include "tgsi/tgsi_dump.h"
|
|
|
|
#include "tgsi/tgsi_scan.h"
|
|
|
|
#include "tgsi/tgsi_parse.h"
|
2010-02-08 23:05:22 +00:00
|
|
|
#include "gallivm/lp_bld_type.h"
|
|
|
|
#include "gallivm/lp_bld_const.h"
|
|
|
|
#include "gallivm/lp_bld_conv.h"
|
2010-07-30 19:48:48 +01:00
|
|
|
#include "gallivm/lp_bld_init.h"
|
2010-02-08 23:05:22 +00:00
|
|
|
#include "gallivm/lp_bld_intr.h"
|
|
|
|
#include "gallivm/lp_bld_logic.h"
|
|
|
|
#include "gallivm/lp_bld_tgsi.h"
|
|
|
|
#include "gallivm/lp_bld_swizzle.h"
|
|
|
|
#include "gallivm/lp_bld_flow.h"
|
|
|
|
#include "gallivm/lp_bld_debug.h"
|
2010-04-16 17:34:29 +01:00
|
|
|
|
|
|
|
#include "lp_bld_alpha.h"
|
|
|
|
#include "lp_bld_blend.h"
|
|
|
|
#include "lp_bld_depth.h"
|
|
|
|
#include "lp_bld_interp.h"
|
2010-01-27 20:49:43 +00:00
|
|
|
#include "lp_context.h"
|
2010-05-31 20:01:29 +01:00
|
|
|
#include "lp_debug.h"
|
2010-01-27 20:49:43 +00:00
|
|
|
#include "lp_perf.h"
|
2009-10-09 15:52:18 +01:00
|
|
|
#include "lp_setup.h"
|
2009-08-14 10:27:32 +01:00
|
|
|
#include "lp_state.h"
|
2009-09-06 11:20:14 +01:00
|
|
|
#include "lp_tex_sample.h"
|
2010-06-18 13:52:17 +01:00
|
|
|
#include "lp_flush.h"
|
2010-06-17 21:19:09 +01:00
|
|
|
#include "lp_state_fs.h"
|
2009-08-14 10:27:32 +01:00
|
|
|
|
|
|
|
|
2010-03-11 20:57:52 +00:00
|
|
|
#include <llvm-c/Analysis.h>
|
2010-10-14 23:31:54 +01:00
|
|
|
#include <llvm-c/BitWriter.h>
|
2010-03-11 20:57:52 +00:00
|
|
|
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
/** Fragment shader number (for debugging) */
|
2010-06-03 14:22:41 +01:00
|
|
|
static unsigned fs_no = 0;
|
|
|
|
|
|
|
|
|
2009-12-16 23:02:59 +00:00
|
|
|
/**
|
2010-06-17 21:19:09 +01:00
|
|
|
* Expand the relevent bits of mask_input to a 4-dword mask for the
|
2009-12-16 23:02:59 +00:00
|
|
|
* four pixels in a 2x2 quad. This will set the four elements of the
|
|
|
|
* quad mask vector to 0 or ~0.
|
2010-06-17 21:19:09 +01:00
|
|
|
*
|
|
|
|
* \param quad which quad of the quad group to test, in [0,3]
|
|
|
|
* \param mask_input bitwise mask for the whole 4x4 stamp
|
2009-12-16 23:02:59 +00:00
|
|
|
*/
|
2010-06-17 21:19:09 +01:00
|
|
|
static LLVMValueRef
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_quad_mask(struct gallivm_state *gallivm,
|
2010-06-17 21:19:09 +01:00
|
|
|
struct lp_type fs_type,
|
|
|
|
unsigned quad,
|
|
|
|
LLVMValueRef mask_input) /* int32 */
|
2009-12-16 23:02:59 +00:00
|
|
|
{
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMBuilderRef builder = gallivm->builder;
|
2010-06-17 21:19:09 +01:00
|
|
|
struct lp_type mask_type;
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
|
2010-06-17 21:19:09 +01:00
|
|
|
LLVMValueRef bits[4];
|
|
|
|
LLVMValueRef mask;
|
2010-09-07 07:55:28 +01:00
|
|
|
int shift;
|
2009-12-16 23:02:59 +00:00
|
|
|
|
2010-01-08 21:49:34 +00:00
|
|
|
/*
|
2010-06-17 21:19:09 +01:00
|
|
|
* XXX: We'll need a different path for 16 x u8
|
2010-01-08 21:49:34 +00:00
|
|
|
*/
|
2010-06-17 21:19:09 +01:00
|
|
|
assert(fs_type.width == 32);
|
|
|
|
assert(fs_type.length == 4);
|
|
|
|
mask_type = lp_int_type(fs_type);
|
2010-01-11 19:59:36 +00:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
/*
|
|
|
|
* mask_input >>= (quad * 4)
|
2010-01-11 22:30:17 +00:00
|
|
|
*/
|
2010-09-07 07:55:28 +01:00
|
|
|
switch (quad) {
|
|
|
|
case 0:
|
|
|
|
shift = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
shift = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
shift = 8;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
shift = 10;
|
|
|
|
break;
|
2010-09-14 08:17:13 +01:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
shift = 0;
|
2010-09-07 07:55:28 +01:00
|
|
|
}
|
2009-12-16 23:02:59 +00:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
mask_input = LLVMBuildLShr(builder,
|
|
|
|
mask_input,
|
2010-09-07 07:55:28 +01:00
|
|
|
LLVMConstInt(i32t, shift, 0),
|
2010-06-17 21:19:09 +01:00
|
|
|
"");
|
2009-12-16 23:02:59 +00:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
/*
|
|
|
|
* mask = { mask_input & (1 << i), for i in [0,3] }
|
|
|
|
*/
|
2010-11-30 23:07:52 +00:00
|
|
|
mask = lp_build_broadcast(gallivm,
|
|
|
|
lp_build_vec_type(gallivm, mask_type),
|
|
|
|
mask_input);
|
2010-01-15 02:15:00 +00:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
bits[0] = LLVMConstInt(i32t, 1 << 0, 0);
|
|
|
|
bits[1] = LLVMConstInt(i32t, 1 << 1, 0);
|
2010-09-07 07:55:28 +01:00
|
|
|
bits[2] = LLVMConstInt(i32t, 1 << 4, 0);
|
|
|
|
bits[3] = LLVMConstInt(i32t, 1 << 5, 0);
|
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
mask = LLVMBuildAnd(builder, mask, LLVMConstVector(bits, 4), "");
|
2010-01-15 02:15:00 +00:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
/*
|
|
|
|
* mask = mask != 0 ? ~0 : 0
|
|
|
|
*/
|
2010-11-30 23:07:52 +00:00
|
|
|
mask = lp_build_compare(gallivm,
|
2010-06-17 21:19:09 +01:00
|
|
|
mask_type, PIPE_FUNC_NOTEQUAL,
|
|
|
|
mask,
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_const_int_vec(gallivm, mask_type, 0));
|
2010-01-15 02:15:00 +00:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
return mask;
|
2010-01-15 18:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-09 11:28:00 +01:00
|
|
|
#define EARLY_DEPTH_TEST 0x1
|
|
|
|
#define LATE_DEPTH_TEST 0x2
|
|
|
|
#define EARLY_DEPTH_WRITE 0x4
|
|
|
|
#define LATE_DEPTH_WRITE 0x8
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_output_by_semantic( const struct tgsi_shader_info *info,
|
|
|
|
unsigned semantic,
|
|
|
|
unsigned index )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < info->num_outputs; i++)
|
|
|
|
if (info->output_semantic_name[i] == semantic &&
|
|
|
|
info->output_semantic_index[i] == index)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-15 18:21:16 +00:00
|
|
|
|
2009-08-22 12:39:44 +01:00
|
|
|
/**
|
2009-08-22 22:26:55 +01:00
|
|
|
* Generate the fragment shader, depth/stencil test, and alpha tests.
|
2009-12-16 23:02:59 +00:00
|
|
|
* \param i which quad in the tile, in range [0,3]
|
2010-06-17 21:19:09 +01:00
|
|
|
* \param partial_mask if 1, do mask_input testing
|
2009-08-22 12:39:44 +01:00
|
|
|
*/
|
|
|
|
static void
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_fs(struct gallivm_state *gallivm,
|
|
|
|
struct lp_fragment_shader *shader,
|
2009-08-22 12:39:44 +01:00
|
|
|
const struct lp_fragment_shader_variant_key *key,
|
|
|
|
LLVMBuilderRef builder,
|
2009-09-14 11:05:06 +01:00
|
|
|
struct lp_type type,
|
2009-08-23 07:38:41 +01:00
|
|
|
LLVMValueRef context_ptr,
|
2009-08-22 12:39:44 +01:00
|
|
|
unsigned i,
|
2010-10-06 22:25:48 +01:00
|
|
|
struct lp_build_interp_soa_context *interp,
|
2009-09-06 11:20:14 +01:00
|
|
|
struct lp_build_sampler_soa *sampler,
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMValueRef *pmask,
|
2010-01-10 17:22:09 +00:00
|
|
|
LLVMValueRef (*color)[4],
|
2009-12-16 23:02:59 +00:00
|
|
|
LLVMValueRef depth_ptr,
|
2010-03-18 19:02:53 +00:00
|
|
|
LLVMValueRef facing,
|
2010-06-17 21:19:09 +01:00
|
|
|
unsigned partial_mask,
|
|
|
|
LLVMValueRef mask_input,
|
2010-05-06 18:45:42 +01:00
|
|
|
LLVMValueRef counter)
|
2009-08-14 10:27:32 +01:00
|
|
|
{
|
2010-10-09 11:28:00 +01:00
|
|
|
const struct util_format_description *zs_format_desc = NULL;
|
2009-08-14 10:27:32 +01:00
|
|
|
const struct tgsi_token *tokens = shader->base.tokens;
|
|
|
|
LLVMTypeRef vec_type;
|
2009-08-23 07:38:41 +01:00
|
|
|
LLVMValueRef consts_ptr;
|
2012-01-14 13:46:05 +00:00
|
|
|
LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][TGSI_NUM_CHANNELS];
|
2010-10-06 22:25:48 +01:00
|
|
|
LLVMValueRef z;
|
2010-10-09 11:28:00 +01:00
|
|
|
LLVMValueRef zs_value = NULL;
|
2010-03-18 17:31:38 +00:00
|
|
|
LLVMValueRef stencil_refs[2];
|
2009-08-22 12:39:44 +01:00
|
|
|
struct lp_build_mask_context mask;
|
2010-09-02 16:30:23 +01:00
|
|
|
boolean simple_shader = (shader->info.base.file_count[TGSI_FILE_SAMPLER] == 0 &&
|
|
|
|
shader->info.base.num_inputs < 3 &&
|
|
|
|
shader->info.base.num_instructions < 8);
|
2009-08-22 12:39:44 +01:00
|
|
|
unsigned attrib;
|
|
|
|
unsigned chan;
|
2010-01-10 17:22:09 +00:00
|
|
|
unsigned cbuf;
|
2010-10-09 11:28:00 +01:00
|
|
|
unsigned depth_mode;
|
|
|
|
|
|
|
|
if (key->depth.enabled ||
|
|
|
|
key->stencil[0].enabled ||
|
|
|
|
key->stencil[1].enabled) {
|
|
|
|
|
|
|
|
zs_format_desc = util_format_description(key->zsbuf_format);
|
|
|
|
assert(zs_format_desc);
|
|
|
|
|
2010-09-02 16:30:23 +01:00
|
|
|
if (!shader->info.base.writes_z) {
|
|
|
|
if (key->alpha.enabled || shader->info.base.uses_kill)
|
2010-10-09 11:28:00 +01:00
|
|
|
/* With alpha test and kill, can do the depth test early
|
|
|
|
* and hopefully eliminate some quads. But need to do a
|
|
|
|
* special deferred depth write once the final mask value
|
|
|
|
* is known.
|
|
|
|
*/
|
|
|
|
depth_mode = EARLY_DEPTH_TEST | LATE_DEPTH_WRITE;
|
|
|
|
else
|
|
|
|
depth_mode = EARLY_DEPTH_TEST | EARLY_DEPTH_WRITE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
depth_mode = LATE_DEPTH_TEST | LATE_DEPTH_WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(key->depth.enabled && key->depth.writemask) &&
|
|
|
|
!(key->stencil[0].enabled && key->stencil[0].writemask))
|
|
|
|
depth_mode &= ~(LATE_DEPTH_WRITE | EARLY_DEPTH_WRITE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
depth_mode = 0;
|
|
|
|
}
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2009-12-16 23:02:59 +00:00
|
|
|
assert(i < 4);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
stencil_refs[0] = lp_jit_context_stencil_ref_front_value(gallivm, context_ptr);
|
|
|
|
stencil_refs[1] = lp_jit_context_stencil_ref_back_value(gallivm, context_ptr);
|
2010-03-16 20:32:18 +00:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
vec_type = lp_build_vec_type(gallivm, type);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
consts_ptr = lp_jit_context_constants(gallivm, context_ptr);
|
2009-08-23 07:38:41 +01:00
|
|
|
|
2009-09-10 11:44:03 +01:00
|
|
|
memset(outputs, 0, sizeof outputs);
|
|
|
|
|
|
|
|
/* Declare the color and z variables */
|
2010-01-10 17:22:09 +00:00
|
|
|
for(cbuf = 0; cbuf < key->nr_cbufs; cbuf++) {
|
2012-01-14 13:46:05 +00:00
|
|
|
for(chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) {
|
2010-11-30 23:07:52 +00:00
|
|
|
color[cbuf][chan] = lp_build_alloca(gallivm, vec_type, "color");
|
2010-01-10 17:22:09 +00:00
|
|
|
}
|
2009-09-10 11:44:03 +01:00
|
|
|
}
|
|
|
|
|
2009-12-16 23:02:59 +00:00
|
|
|
/* do triangle edge testing */
|
2010-06-17 21:19:09 +01:00
|
|
|
if (partial_mask) {
|
2010-11-30 23:07:52 +00:00
|
|
|
*pmask = generate_quad_mask(gallivm, type,
|
2010-06-17 21:19:09 +01:00
|
|
|
i, mask_input);
|
2010-01-15 18:21:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-11-30 23:07:52 +00:00
|
|
|
*pmask = lp_build_const_int_vec(gallivm, type, ~0);
|
2010-01-15 18:21:16 +00:00
|
|
|
}
|
2009-12-16 23:02:59 +00:00
|
|
|
|
2009-12-17 17:52:50 +00:00
|
|
|
/* 'mask' will control execution based on quad's pixel alive/killed state */
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_mask_begin(&mask, gallivm, type, *pmask);
|
2010-10-07 15:01:07 +01:00
|
|
|
|
2010-10-09 11:28:00 +01:00
|
|
|
if (!(depth_mode & EARLY_DEPTH_TEST) && !simple_shader)
|
2010-10-07 15:01:07 +01:00
|
|
|
lp_build_mask_check(&mask);
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_interp_soa_update_pos(interp, gallivm, i);
|
2010-10-07 15:01:07 +01:00
|
|
|
z = interp->pos[2];
|
|
|
|
|
2010-10-09 11:28:00 +01:00
|
|
|
if (depth_mode & EARLY_DEPTH_TEST) {
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_depth_stencil_test(gallivm,
|
2010-10-09 11:28:00 +01:00
|
|
|
&key->depth,
|
|
|
|
key->stencil,
|
|
|
|
type,
|
|
|
|
zs_format_desc,
|
|
|
|
&mask,
|
|
|
|
stencil_refs,
|
|
|
|
z,
|
|
|
|
depth_ptr, facing,
|
|
|
|
&zs_value,
|
|
|
|
!simple_shader);
|
|
|
|
|
2010-10-13 14:28:51 +01:00
|
|
|
if (depth_mode & EARLY_DEPTH_WRITE) {
|
|
|
|
lp_build_depth_write(builder, zs_format_desc, depth_ptr, zs_value);
|
|
|
|
}
|
2010-10-09 11:28:00 +01:00
|
|
|
}
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_interp_soa_update_inputs(interp, gallivm, i);
|
2010-10-09 11:28:00 +01:00
|
|
|
|
|
|
|
/* Build the actual shader */
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_tgsi_soa(gallivm, tokens, type, &mask,
|
2010-12-09 02:02:14 +00:00
|
|
|
consts_ptr, NULL, /* sys values array */
|
|
|
|
interp->pos, interp->inputs,
|
2010-09-02 16:30:23 +01:00
|
|
|
outputs, sampler, &shader->info.base);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-10-09 11:28:00 +01:00
|
|
|
/* Alpha test */
|
|
|
|
if (key->alpha.enabled) {
|
2010-09-02 16:30:23 +01:00
|
|
|
int color0 = find_output_by_semantic(&shader->info.base,
|
2010-10-09 11:28:00 +01:00
|
|
|
TGSI_SEMANTIC_COLOR,
|
|
|
|
0);
|
|
|
|
|
2010-10-15 13:23:05 +01:00
|
|
|
if (color0 != -1 && outputs[color0][3]) {
|
2010-10-09 11:28:00 +01:00
|
|
|
LLVMValueRef alpha = LLVMBuildLoad(builder, outputs[color0][3], "alpha");
|
|
|
|
LLVMValueRef alpha_ref_value;
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
alpha_ref_value = lp_jit_context_alpha_ref_value(gallivm, context_ptr);
|
|
|
|
alpha_ref_value = lp_build_broadcast(gallivm, vec_type, alpha_ref_value);
|
2010-10-09 11:28:00 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_alpha_test(gallivm, key->alpha.func, type,
|
2010-10-09 11:28:00 +01:00
|
|
|
&mask, alpha, alpha_ref_value,
|
|
|
|
(depth_mode & LATE_DEPTH_TEST) != 0);
|
2009-08-22 12:39:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-09 11:28:00 +01:00
|
|
|
/* Late Z test */
|
|
|
|
if (depth_mode & LATE_DEPTH_TEST) {
|
2010-09-02 16:30:23 +01:00
|
|
|
int pos0 = find_output_by_semantic(&shader->info.base,
|
2010-10-09 11:28:00 +01:00
|
|
|
TGSI_SEMANTIC_POSITION,
|
|
|
|
0);
|
|
|
|
|
2010-10-15 13:23:05 +01:00
|
|
|
if (pos0 != -1 && outputs[pos0][2]) {
|
2010-10-17 17:58:04 +01:00
|
|
|
z = LLVMBuildLoad(builder, outputs[pos0][2], "output.z");
|
2010-10-09 11:28:00 +01:00
|
|
|
}
|
2009-09-10 13:35:39 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_depth_stencil_test(gallivm,
|
2010-10-09 11:28:00 +01:00
|
|
|
&key->depth,
|
|
|
|
key->stencil,
|
|
|
|
type,
|
|
|
|
zs_format_desc,
|
|
|
|
&mask,
|
|
|
|
stencil_refs,
|
|
|
|
z,
|
|
|
|
depth_ptr, facing,
|
|
|
|
&zs_value,
|
|
|
|
!simple_shader);
|
|
|
|
/* Late Z write */
|
2010-10-13 14:28:51 +01:00
|
|
|
if (depth_mode & LATE_DEPTH_WRITE) {
|
|
|
|
lp_build_depth_write(builder, zs_format_desc, depth_ptr, zs_value);
|
|
|
|
}
|
2010-10-09 11:28:00 +01:00
|
|
|
}
|
|
|
|
else if ((depth_mode & EARLY_DEPTH_TEST) &&
|
|
|
|
(depth_mode & LATE_DEPTH_WRITE))
|
|
|
|
{
|
|
|
|
/* Need to apply a reduced mask to the depth write. Reload the
|
|
|
|
* depth value, update from zs_value with the new mask value and
|
|
|
|
* write that out.
|
|
|
|
*/
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_deferred_depth_write(gallivm,
|
2010-10-09 11:28:00 +01:00
|
|
|
type,
|
|
|
|
zs_format_desc,
|
|
|
|
&mask,
|
|
|
|
depth_ptr,
|
|
|
|
zs_value);
|
|
|
|
}
|
2009-09-10 13:35:39 +01:00
|
|
|
|
|
|
|
|
2010-10-09 11:28:00 +01:00
|
|
|
/* Color write */
|
2010-09-02 16:30:23 +01:00
|
|
|
for (attrib = 0; attrib < shader->info.base.num_outputs; ++attrib)
|
2010-10-09 11:28:00 +01:00
|
|
|
{
|
2010-10-15 13:23:30 +01:00
|
|
|
if (shader->info.base.output_semantic_name[attrib] == TGSI_SEMANTIC_COLOR &&
|
|
|
|
shader->info.base.output_semantic_index[attrib] < key->nr_cbufs)
|
2010-10-09 11:28:00 +01:00
|
|
|
{
|
2010-09-02 16:30:23 +01:00
|
|
|
unsigned cbuf = shader->info.base.output_semantic_index[attrib];
|
2012-01-14 13:46:05 +00:00
|
|
|
for(chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) {
|
2010-10-14 13:15:28 +01:00
|
|
|
if(outputs[attrib][chan]) {
|
|
|
|
/* XXX: just initialize outputs to point at colors[] and
|
|
|
|
* skip this.
|
|
|
|
*/
|
|
|
|
LLVMValueRef out = LLVMBuildLoad(builder, outputs[attrib][chan], "");
|
|
|
|
lp_build_name(out, "color%u.%u.%c", i, attrib, "rgba"[chan]);
|
|
|
|
LLVMBuildStore(builder, out, color[cbuf][chan]);
|
|
|
|
}
|
2009-08-22 12:39:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-09 11:28:00 +01:00
|
|
|
if (counter)
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_occlusion_count(gallivm, type,
|
2010-10-09 12:55:31 +01:00
|
|
|
lp_build_mask_value(&mask), counter);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-10-09 12:55:31 +01:00
|
|
|
*pmask = lp_build_mask_end(&mask);
|
2009-08-22 12:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-08-22 22:26:55 +01:00
|
|
|
* Generate color blending and color output.
|
2010-05-11 00:02:06 +01:00
|
|
|
* \param rt the render target index (to index blend, colormask state)
|
|
|
|
* \param type the pixel color type
|
|
|
|
* \param context_ptr pointer to the runtime JIT context
|
|
|
|
* \param mask execution mask (active fragment/pixel mask)
|
|
|
|
* \param src colors from the fragment shader
|
|
|
|
* \param dst_ptr the destination color buffer pointer
|
2009-08-22 12:39:44 +01:00
|
|
|
*/
|
|
|
|
static void
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_blend(struct gallivm_state *gallivm,
|
|
|
|
const struct pipe_blend_state *blend,
|
2010-05-11 00:02:06 +01:00
|
|
|
unsigned rt,
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMBuilderRef builder,
|
2009-09-14 11:05:06 +01:00
|
|
|
struct lp_type type,
|
2009-08-23 07:38:41 +01:00
|
|
|
LLVMValueRef context_ptr,
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMValueRef mask,
|
|
|
|
LLVMValueRef *src,
|
2010-10-07 15:01:07 +01:00
|
|
|
LLVMValueRef dst_ptr,
|
|
|
|
boolean do_branch)
|
2009-08-22 12:39:44 +01:00
|
|
|
{
|
|
|
|
struct lp_build_context bld;
|
2009-09-10 12:01:42 +01:00
|
|
|
struct lp_build_mask_context mask_ctx;
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMTypeRef vec_type;
|
2009-08-23 07:38:41 +01:00
|
|
|
LLVMValueRef const_ptr;
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMValueRef con[4];
|
|
|
|
LLVMValueRef dst[4];
|
|
|
|
LLVMValueRef res[4];
|
|
|
|
unsigned chan;
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_context_init(&bld, gallivm, type);
|
2009-09-10 12:01:42 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_mask_begin(&mask_ctx, gallivm, type, mask);
|
2010-10-07 15:01:07 +01:00
|
|
|
if (do_branch)
|
|
|
|
lp_build_mask_check(&mask_ctx);
|
2009-09-10 12:01:42 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
vec_type = lp_build_vec_type(gallivm, type);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
const_ptr = lp_jit_context_blend_color(gallivm, context_ptr);
|
2009-08-23 07:38:41 +01:00
|
|
|
const_ptr = LLVMBuildBitCast(builder, const_ptr,
|
|
|
|
LLVMPointerType(vec_type, 0), "");
|
|
|
|
|
2010-05-11 00:02:06 +01:00
|
|
|
/* load constant blend color and colors from the dest color buffer */
|
2009-08-22 12:39:44 +01:00
|
|
|
for(chan = 0; chan < 4; ++chan) {
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMValueRef index = lp_build_const_int32(gallivm, chan);
|
2009-08-23 07:38:41 +01:00
|
|
|
con[chan] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), "");
|
2009-08-22 12:39:44 +01:00
|
|
|
|
|
|
|
dst[chan] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), "");
|
|
|
|
|
|
|
|
lp_build_name(con[chan], "con.%c", "rgba"[chan]);
|
|
|
|
lp_build_name(dst[chan], "dst.%c", "rgba"[chan]);
|
|
|
|
}
|
|
|
|
|
2010-05-11 00:02:06 +01:00
|
|
|
/* do blend */
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_blend_soa(gallivm, blend, type, rt, src, dst, con, res);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-05-11 00:02:06 +01:00
|
|
|
/* store results to color buffer */
|
2009-08-22 12:39:44 +01:00
|
|
|
for(chan = 0; chan < 4; ++chan) {
|
2010-05-11 00:02:06 +01:00
|
|
|
if(blend->rt[rt].colormask & (1 << chan)) {
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMValueRef index = lp_build_const_int32(gallivm, chan);
|
2009-09-10 12:37:44 +01:00
|
|
|
lp_build_name(res[chan], "res.%c", "rgba"[chan]);
|
|
|
|
res[chan] = lp_build_select(&bld, mask, res[chan], dst[chan]);
|
|
|
|
LLVMBuildStore(builder, res[chan], LLVMBuildGEP(builder, dst_ptr, &index, 1, ""));
|
|
|
|
}
|
2009-08-22 12:39:44 +01:00
|
|
|
}
|
2009-09-10 12:01:42 +01:00
|
|
|
|
|
|
|
lp_build_mask_end(&mask_ctx);
|
2009-08-22 12:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-22 22:26:55 +01:00
|
|
|
/**
|
|
|
|
* Generate the runtime callable function for the whole fragment pipeline.
|
2009-12-02 22:13:45 +00:00
|
|
|
* Note that the function which we generate operates on a block of 16
|
|
|
|
* pixels at at time. The block contains 2x2 quads. Each quad contains
|
|
|
|
* 2x2 pixels.
|
2009-08-22 22:26:55 +01:00
|
|
|
*/
|
2010-01-11 20:16:00 +00:00
|
|
|
static void
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_fragment(struct llvmpipe_context *lp,
|
2009-08-22 12:39:44 +01:00
|
|
|
struct lp_fragment_shader *shader,
|
2010-01-15 18:21:16 +00:00
|
|
|
struct lp_fragment_shader_variant *variant,
|
2010-06-17 21:19:09 +01:00
|
|
|
unsigned partial_mask)
|
2009-08-22 12:39:44 +01:00
|
|
|
{
|
2010-11-30 23:07:52 +00:00
|
|
|
struct gallivm_state *gallivm = lp->gallivm;
|
2010-01-11 20:16:00 +00:00
|
|
|
const struct lp_fragment_shader_variant_key *key = &variant->key;
|
2010-09-05 13:17:43 +01:00
|
|
|
struct lp_shader_input inputs[PIPE_MAX_SHADER_INPUTS];
|
2010-06-03 14:22:41 +01:00
|
|
|
char func_name[256];
|
2009-09-14 11:05:06 +01:00
|
|
|
struct lp_type fs_type;
|
|
|
|
struct lp_type blend_type;
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMTypeRef fs_elem_type;
|
|
|
|
LLVMTypeRef blend_vec_type;
|
2010-06-17 21:19:09 +01:00
|
|
|
LLVMTypeRef arg_types[11];
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMTypeRef func_type;
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context);
|
|
|
|
LLVMTypeRef int8_type = LLVMInt8TypeInContext(gallivm->context);
|
2009-08-23 06:35:09 +01:00
|
|
|
LLVMValueRef context_ptr;
|
2009-08-19 17:58:04 +01:00
|
|
|
LLVMValueRef x;
|
|
|
|
LLVMValueRef y;
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMValueRef a0_ptr;
|
|
|
|
LLVMValueRef dadx_ptr;
|
|
|
|
LLVMValueRef dady_ptr;
|
2010-01-10 17:22:09 +00:00
|
|
|
LLVMValueRef color_ptr_ptr;
|
2009-08-19 09:24:20 +01:00
|
|
|
LLVMValueRef depth_ptr;
|
2010-06-17 21:19:09 +01:00
|
|
|
LLVMValueRef mask_input;
|
|
|
|
LLVMValueRef counter = NULL;
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMBasicBlockRef block;
|
|
|
|
LLVMBuilderRef builder;
|
2009-09-06 11:20:14 +01:00
|
|
|
struct lp_build_sampler_soa *sampler;
|
2009-08-23 12:28:34 +01:00
|
|
|
struct lp_build_interp_soa_context interp;
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMValueRef fs_mask[LP_MAX_VECTOR_LENGTH];
|
2012-01-14 13:46:05 +00:00
|
|
|
LLVMValueRef fs_out_color[PIPE_MAX_COLOR_BUFS][TGSI_NUM_CHANNELS][LP_MAX_VECTOR_LENGTH];
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMValueRef blend_mask;
|
2010-01-15 17:25:59 +00:00
|
|
|
LLVMValueRef function;
|
2010-03-18 19:02:53 +00:00
|
|
|
LLVMValueRef facing;
|
2010-10-13 14:28:51 +01:00
|
|
|
const struct util_format_description *zs_format_desc;
|
2009-08-22 12:39:44 +01:00
|
|
|
unsigned num_fs;
|
2009-08-19 09:24:20 +01:00
|
|
|
unsigned i;
|
|
|
|
unsigned chan;
|
2010-01-10 17:22:09 +00:00
|
|
|
unsigned cbuf;
|
2011-01-20 01:45:43 +00:00
|
|
|
boolean cbuf0_write_all;
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-09-05 13:17:43 +01:00
|
|
|
/* Adjust color input interpolation according to flatshade state:
|
|
|
|
*/
|
2010-10-18 03:03:42 +01:00
|
|
|
memcpy(inputs, shader->inputs, shader->info.base.num_inputs * sizeof inputs[0]);
|
|
|
|
for (i = 0; i < shader->info.base.num_inputs; i++) {
|
2010-09-05 13:17:43 +01:00
|
|
|
if (inputs[i].interp == LP_INTERP_COLOR) {
|
|
|
|
if (key->flatshade)
|
|
|
|
inputs[i].interp = LP_INTERP_CONSTANT;
|
|
|
|
else
|
|
|
|
inputs[i].interp = LP_INTERP_LINEAR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-20 01:45:43 +00:00
|
|
|
/* check if writes to cbuf[0] are to be copied to all cbufs */
|
|
|
|
cbuf0_write_all = FALSE;
|
|
|
|
for (i = 0;i < shader->info.base.num_properties; i++) {
|
|
|
|
if (shader->info.base.properties[i].name ==
|
|
|
|
TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS) {
|
|
|
|
cbuf0_write_all = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-19 20:42:50 +01:00
|
|
|
|
2009-08-22 22:26:55 +01:00
|
|
|
/* TODO: actually pick these based on the fs and color buffer
|
|
|
|
* characteristics. */
|
|
|
|
|
2009-09-14 11:05:06 +01:00
|
|
|
memset(&fs_type, 0, sizeof fs_type);
|
2009-08-22 12:39:44 +01:00
|
|
|
fs_type.floating = TRUE; /* floating point values */
|
|
|
|
fs_type.sign = TRUE; /* values are signed */
|
|
|
|
fs_type.norm = FALSE; /* values are not limited to [0,1] or [-1,1] */
|
|
|
|
fs_type.width = 32; /* 32-bit float */
|
2009-12-02 22:13:45 +00:00
|
|
|
fs_type.length = 4; /* 4 elements per vector */
|
|
|
|
num_fs = 4; /* number of quads per block */
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2009-09-14 11:05:06 +01:00
|
|
|
memset(&blend_type, 0, sizeof blend_type);
|
2009-08-22 12:39:44 +01:00
|
|
|
blend_type.floating = FALSE; /* values are integers */
|
|
|
|
blend_type.sign = FALSE; /* values are unsigned */
|
|
|
|
blend_type.norm = TRUE; /* values are in [0,1] or [-1,1] */
|
|
|
|
blend_type.width = 8; /* 8-bit ubyte values */
|
|
|
|
blend_type.length = 16; /* 16 elements per vector */
|
|
|
|
|
2009-08-22 22:26:55 +01:00
|
|
|
/*
|
|
|
|
* Generate the function prototype. Any change here must be reflected in
|
2009-08-23 05:52:20 +01:00
|
|
|
* lp_jit.h's lp_jit_frag_func function pointer type, and vice-versa.
|
2009-08-22 22:26:55 +01:00
|
|
|
*/
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
fs_elem_type = lp_build_elem_type(gallivm, fs_type);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
blend_vec_type = lp_build_vec_type(gallivm, blend_type);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-06-03 14:22:41 +01:00
|
|
|
util_snprintf(func_name, sizeof(func_name), "fs%u_variant%u_%s",
|
2010-06-17 21:19:09 +01:00
|
|
|
shader->no, variant->no, partial_mask ? "partial" : "whole");
|
2010-06-03 14:22:41 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
arg_types[0] = lp_jit_get_context_type(lp); /* context */
|
|
|
|
arg_types[1] = int32_type; /* x */
|
|
|
|
arg_types[2] = int32_type; /* y */
|
|
|
|
arg_types[3] = int32_type; /* facing */
|
2010-03-18 19:02:53 +00:00
|
|
|
arg_types[4] = LLVMPointerType(fs_elem_type, 0); /* a0 */
|
|
|
|
arg_types[5] = LLVMPointerType(fs_elem_type, 0); /* dadx */
|
|
|
|
arg_types[6] = LLVMPointerType(fs_elem_type, 0); /* dady */
|
|
|
|
arg_types[7] = LLVMPointerType(LLVMPointerType(blend_vec_type, 0), 0); /* color */
|
2010-11-30 23:07:52 +00:00
|
|
|
arg_types[8] = LLVMPointerType(int8_type, 0); /* depth */
|
|
|
|
arg_types[9] = int32_type; /* mask_input */
|
|
|
|
arg_types[10] = LLVMPointerType(int32_type, 0); /* counter */
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context),
|
|
|
|
arg_types, Elements(arg_types), 0);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
function = LLVMAddFunction(gallivm->module, func_name, func_type);
|
2010-01-15 17:25:59 +00:00
|
|
|
LLVMSetFunctionCallConv(function, LLVMCCallConv);
|
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
variant->function[partial_mask] = function;
|
2010-01-15 17:25:59 +00:00
|
|
|
|
2010-01-10 17:22:09 +00:00
|
|
|
/* XXX: need to propagate noalias down into color param now we are
|
|
|
|
* passing a pointer-to-pointer?
|
|
|
|
*/
|
2009-08-16 10:02:17 +01:00
|
|
|
for(i = 0; i < Elements(arg_types); ++i)
|
2009-08-19 17:58:04 +01:00
|
|
|
if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind)
|
2010-01-15 17:25:59 +00:00
|
|
|
LLVMAddAttribute(LLVMGetParam(function, i), LLVMNoAliasAttribute);
|
|
|
|
|
|
|
|
context_ptr = LLVMGetParam(function, 0);
|
|
|
|
x = LLVMGetParam(function, 1);
|
|
|
|
y = LLVMGetParam(function, 2);
|
2010-03-18 19:02:53 +00:00
|
|
|
facing = LLVMGetParam(function, 3);
|
|
|
|
a0_ptr = LLVMGetParam(function, 4);
|
|
|
|
dadx_ptr = LLVMGetParam(function, 5);
|
|
|
|
dady_ptr = LLVMGetParam(function, 6);
|
|
|
|
color_ptr_ptr = LLVMGetParam(function, 7);
|
|
|
|
depth_ptr = LLVMGetParam(function, 8);
|
2010-06-17 21:19:09 +01:00
|
|
|
mask_input = LLVMGetParam(function, 9);
|
2009-08-19 17:58:04 +01:00
|
|
|
|
2009-08-23 06:35:09 +01:00
|
|
|
lp_build_name(context_ptr, "context");
|
2009-08-19 17:58:04 +01:00
|
|
|
lp_build_name(x, "x");
|
|
|
|
lp_build_name(y, "y");
|
2009-08-18 20:23:35 +01:00
|
|
|
lp_build_name(a0_ptr, "a0");
|
|
|
|
lp_build_name(dadx_ptr, "dadx");
|
|
|
|
lp_build_name(dady_ptr, "dady");
|
2010-05-11 00:02:06 +01:00
|
|
|
lp_build_name(color_ptr_ptr, "color_ptr_ptr");
|
2009-08-19 09:24:20 +01:00
|
|
|
lp_build_name(depth_ptr, "depth");
|
2010-06-17 21:19:09 +01:00
|
|
|
lp_build_name(mask_input, "mask_input");
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-05-06 18:45:42 +01:00
|
|
|
if (key->occlusion_count) {
|
2010-06-17 21:19:09 +01:00
|
|
|
counter = LLVMGetParam(function, 10);
|
2010-05-06 18:45:42 +01:00
|
|
|
lp_build_name(counter, "counter");
|
|
|
|
}
|
|
|
|
|
2009-08-22 22:26:55 +01:00
|
|
|
/*
|
|
|
|
* Function body
|
|
|
|
*/
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
block = LLVMAppendBasicBlockInContext(gallivm->context, function, "entry");
|
|
|
|
builder = gallivm->builder;
|
|
|
|
assert(builder);
|
2009-08-14 10:27:32 +01:00
|
|
|
LLVMPositionBuilderAtEnd(builder, block);
|
|
|
|
|
2010-06-01 21:27:18 +01:00
|
|
|
/*
|
|
|
|
* The shader input interpolation info is not explicitely baked in the
|
|
|
|
* shader key, but everything it derives from (TGSI, and flatshade) is
|
|
|
|
* already included in the shader key.
|
|
|
|
*/
|
2010-01-11 12:06:51 +00:00
|
|
|
lp_build_interp_soa_init(&interp,
|
2010-11-30 23:07:52 +00:00
|
|
|
gallivm,
|
2010-10-18 03:03:42 +01:00
|
|
|
shader->info.base.num_inputs,
|
2010-09-05 13:17:43 +01:00
|
|
|
inputs,
|
2010-01-11 12:06:51 +00:00
|
|
|
builder, fs_type,
|
2009-08-23 12:28:34 +01:00
|
|
|
a0_ptr, dadx_ptr, dady_ptr,
|
2010-06-02 09:56:05 +01:00
|
|
|
x, y);
|
2009-08-23 12:28:34 +01:00
|
|
|
|
2009-09-07 14:52:39 +01:00
|
|
|
/* code generated texture sampling */
|
|
|
|
sampler = lp_llvm_sampler_soa_create(key->sampler, context_ptr);
|
2009-08-25 08:05:31 +01:00
|
|
|
|
2009-12-02 22:13:45 +00:00
|
|
|
/* loop over quads in the block */
|
2010-10-13 14:28:51 +01:00
|
|
|
zs_format_desc = util_format_description(key->zsbuf_format);
|
|
|
|
|
2009-08-22 12:39:44 +01:00
|
|
|
for(i = 0; i < num_fs; ++i) {
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMValueRef depth_offset = LLVMConstInt(int32_type,
|
2010-10-13 14:28:51 +01:00
|
|
|
i*fs_type.length*zs_format_desc->block.bits/8,
|
|
|
|
0);
|
2012-01-14 13:46:05 +00:00
|
|
|
LLVMValueRef out_color[PIPE_MAX_COLOR_BUFS][TGSI_NUM_CHANNELS];
|
2009-08-22 12:39:44 +01:00
|
|
|
LLVMValueRef depth_ptr_i;
|
|
|
|
|
2010-10-13 14:28:51 +01:00
|
|
|
depth_ptr_i = LLVMBuildGEP(builder, depth_ptr, &depth_offset, 1, "");
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_fs(gallivm,
|
|
|
|
shader, key,
|
2009-08-22 12:39:44 +01:00
|
|
|
builder,
|
|
|
|
fs_type,
|
2009-08-23 07:38:41 +01:00
|
|
|
context_ptr,
|
2009-08-22 12:39:44 +01:00
|
|
|
i,
|
2009-08-23 12:28:34 +01:00
|
|
|
&interp,
|
2009-09-06 11:20:14 +01:00
|
|
|
sampler,
|
2009-12-16 23:02:59 +00:00
|
|
|
&fs_mask[i], /* output */
|
2009-08-22 12:39:44 +01:00
|
|
|
out_color,
|
2009-12-16 23:02:59 +00:00
|
|
|
depth_ptr_i,
|
2010-03-18 19:02:53 +00:00
|
|
|
facing,
|
2010-06-17 21:19:09 +01:00
|
|
|
partial_mask,
|
|
|
|
mask_input,
|
|
|
|
counter);
|
2009-08-22 12:39:44 +01:00
|
|
|
|
2011-01-20 01:45:43 +00:00
|
|
|
for (cbuf = 0; cbuf < key->nr_cbufs; cbuf++)
|
2012-01-14 13:46:05 +00:00
|
|
|
for (chan = 0; chan < TGSI_NUM_CHANNELS; ++chan)
|
2011-01-20 01:45:43 +00:00
|
|
|
fs_out_color[cbuf][chan][i] =
|
|
|
|
out_color[cbuf * !cbuf0_write_all][chan];
|
2009-08-22 12:39:44 +01:00
|
|
|
}
|
2009-08-19 09:24:20 +01:00
|
|
|
|
2009-09-06 11:20:14 +01:00
|
|
|
sampler->destroy(sampler);
|
|
|
|
|
2010-01-10 17:22:09 +00:00
|
|
|
/* Loop over color outputs / color buffers to do blending.
|
2009-08-22 22:26:55 +01:00
|
|
|
*/
|
2010-01-10 17:22:09 +00:00
|
|
|
for(cbuf = 0; cbuf < key->nr_cbufs; cbuf++) {
|
|
|
|
LLVMValueRef color_ptr;
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMValueRef index = lp_build_const_int32(gallivm, cbuf);
|
2012-01-14 13:46:05 +00:00
|
|
|
LLVMValueRef blend_in_color[TGSI_NUM_CHANNELS];
|
2010-05-11 00:02:06 +01:00
|
|
|
unsigned rt;
|
2009-08-22 22:26:55 +01:00
|
|
|
|
2010-01-10 17:22:09 +00:00
|
|
|
/*
|
|
|
|
* Convert the fs's output color and mask to fit to the blending type.
|
|
|
|
*/
|
2012-01-14 13:46:05 +00:00
|
|
|
for(chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) {
|
2010-10-07 18:59:54 +01:00
|
|
|
LLVMValueRef fs_color_vals[LP_MAX_VECTOR_LENGTH];
|
|
|
|
|
|
|
|
for (i = 0; i < num_fs; i++) {
|
|
|
|
fs_color_vals[i] =
|
|
|
|
LLVMBuildLoad(builder, fs_out_color[cbuf][chan][i], "fs_color_vals");
|
|
|
|
}
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_conv(gallivm, fs_type, blend_type,
|
2010-10-07 18:59:54 +01:00
|
|
|
fs_color_vals,
|
|
|
|
num_fs,
|
2010-01-10 17:22:09 +00:00
|
|
|
&blend_in_color[chan], 1);
|
2010-10-07 18:59:54 +01:00
|
|
|
|
2010-01-10 17:22:09 +00:00
|
|
|
lp_build_name(blend_in_color[chan], "color%d.%c", cbuf, "rgba"[chan]);
|
|
|
|
}
|
2009-08-23 07:38:41 +01:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
if (partial_mask || !variant->opaque) {
|
2010-11-30 23:07:52 +00:00
|
|
|
lp_build_conv_mask(lp->gallivm, fs_type, blend_type,
|
2010-06-17 21:19:09 +01:00
|
|
|
fs_mask, num_fs,
|
|
|
|
&blend_mask, 1);
|
|
|
|
} else {
|
2010-11-30 23:07:52 +00:00
|
|
|
blend_mask = lp_build_const_int_vec(lp->gallivm, blend_type, ~0);
|
2010-06-17 21:19:09 +01:00
|
|
|
}
|
2010-01-10 17:22:09 +00:00
|
|
|
|
|
|
|
color_ptr = LLVMBuildLoad(builder,
|
|
|
|
LLVMBuildGEP(builder, color_ptr_ptr, &index, 1, ""),
|
|
|
|
"");
|
|
|
|
lp_build_name(color_ptr, "color_ptr%d", cbuf);
|
|
|
|
|
2010-05-11 00:02:06 +01:00
|
|
|
/* which blend/colormask state to use */
|
|
|
|
rt = key->blend.independent_blend_enable ? cbuf : 0;
|
|
|
|
|
2010-01-10 17:22:09 +00:00
|
|
|
/*
|
|
|
|
* Blending.
|
|
|
|
*/
|
2010-10-07 15:01:07 +01:00
|
|
|
{
|
|
|
|
/* Could the 4x4 have been killed?
|
|
|
|
*/
|
|
|
|
boolean do_branch = ((key->depth.enabled || key->stencil[0].enabled) &&
|
|
|
|
!key->alpha.enabled &&
|
2010-09-02 16:30:23 +01:00
|
|
|
!shader->info.base.uses_kill);
|
2010-10-07 15:01:07 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_blend(lp->gallivm,
|
|
|
|
&key->blend,
|
2010-10-07 15:01:07 +01:00
|
|
|
rt,
|
|
|
|
builder,
|
|
|
|
blend_type,
|
|
|
|
context_ptr,
|
|
|
|
blend_mask,
|
|
|
|
blend_in_color,
|
|
|
|
color_ptr,
|
|
|
|
do_branch);
|
|
|
|
}
|
2009-08-14 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
2009-08-22 22:26:55 +01:00
|
|
|
LLVMBuildRetVoid(builder);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-01-08 21:49:34 +00:00
|
|
|
/* Verify the LLVM IR. If invalid, dump and abort */
|
2009-11-23 11:21:11 +00:00
|
|
|
#ifdef DEBUG
|
2010-01-15 17:25:59 +00:00
|
|
|
if(LLVMVerifyFunction(function, LLVMPrintMessageAction)) {
|
2010-01-08 21:49:34 +00:00
|
|
|
if (1)
|
2010-05-08 23:23:41 +01:00
|
|
|
lp_debug_dump_value(function);
|
2010-01-08 21:49:34 +00:00
|
|
|
abort();
|
2009-09-29 17:22:39 +01:00
|
|
|
}
|
2009-11-23 11:21:11 +00:00
|
|
|
#endif
|
2009-09-29 17:22:39 +01:00
|
|
|
|
2010-01-08 21:49:34 +00:00
|
|
|
/* Apply optimizations to LLVM IR */
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMRunFunctionPassManager(gallivm->passmgr, function);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-10-07 19:01:12 +01:00
|
|
|
if ((gallivm_debug & GALLIVM_DEBUG_IR) || (LP_DEBUG & DEBUG_FS)) {
|
2010-01-08 21:49:34 +00:00
|
|
|
/* Print the LLVM IR to stderr */
|
2010-05-08 23:23:41 +01:00
|
|
|
lp_debug_dump_value(function);
|
2009-12-16 15:06:02 +00:00
|
|
|
debug_printf("\n");
|
|
|
|
}
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-10-14 23:31:54 +01:00
|
|
|
/* Dump byte code to a file */
|
|
|
|
if (0) {
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMWriteBitcodeToFile(gallivm->module, "llvmpipe.bc");
|
2010-10-14 23:31:54 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 17:12:00 +00:00
|
|
|
variant->nr_instrs += lp_build_count_instructions(function);
|
2010-01-08 21:49:34 +00:00
|
|
|
/*
|
|
|
|
* Translate the LLVM IR into machine code.
|
|
|
|
*/
|
2010-03-17 14:34:23 +00:00
|
|
|
{
|
2010-11-30 23:07:52 +00:00
|
|
|
void *f = LLVMGetPointerToGlobal(gallivm->engine, function);
|
2010-03-17 14:34:23 +00:00
|
|
|
|
2010-06-17 21:19:09 +01:00
|
|
|
variant->jit_function[partial_mask] = (lp_jit_frag_func)pointer_to_func(f);
|
2009-08-14 10:27:32 +01:00
|
|
|
|
2010-10-07 19:01:12 +01:00
|
|
|
if ((gallivm_debug & GALLIVM_DEBUG_ASM) || (LP_DEBUG & DEBUG_FS)) {
|
2010-03-17 14:34:23 +00:00
|
|
|
lp_disassemble(f);
|
2010-05-15 11:48:39 +01:00
|
|
|
}
|
2010-07-27 17:26:54 +01:00
|
|
|
lp_func_delete_body(function);
|
2010-03-17 14:34:23 +00:00
|
|
|
}
|
2010-01-11 20:16:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 18:28:29 +01:00
|
|
|
static void
|
|
|
|
dump_fs_variant_key(const struct lp_fragment_shader_variant_key *key)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2010-05-19 19:39:52 +01:00
|
|
|
debug_printf("fs variant %p:\n", (void *) key);
|
|
|
|
|
2010-10-05 10:50:02 +01:00
|
|
|
if (key->flatshade) {
|
|
|
|
debug_printf("flatshade = 1\n");
|
|
|
|
}
|
2010-09-03 20:26:13 +01:00
|
|
|
for (i = 0; i < key->nr_cbufs; ++i) {
|
|
|
|
debug_printf("cbuf_format[%u] = %s\n", i, util_format_name(key->cbuf_format[i]));
|
|
|
|
}
|
2010-05-19 18:28:29 +01:00
|
|
|
if (key->depth.enabled) {
|
|
|
|
debug_printf("depth.format = %s\n", util_format_name(key->zsbuf_format));
|
|
|
|
debug_printf("depth.func = %s\n", util_dump_func(key->depth.func, TRUE));
|
|
|
|
debug_printf("depth.writemask = %u\n", key->depth.writemask);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
if (key->stencil[i].enabled) {
|
|
|
|
debug_printf("stencil[%u].func = %s\n", i, util_dump_func(key->stencil[i].func, TRUE));
|
|
|
|
debug_printf("stencil[%u].fail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].fail_op, TRUE));
|
|
|
|
debug_printf("stencil[%u].zpass_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zpass_op, TRUE));
|
|
|
|
debug_printf("stencil[%u].zfail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zfail_op, TRUE));
|
|
|
|
debug_printf("stencil[%u].valuemask = 0x%x\n", i, key->stencil[i].valuemask);
|
|
|
|
debug_printf("stencil[%u].writemask = 0x%x\n", i, key->stencil[i].writemask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key->alpha.enabled) {
|
|
|
|
debug_printf("alpha.func = %s\n", util_dump_func(key->alpha.func, TRUE));
|
|
|
|
}
|
|
|
|
|
2010-10-05 10:50:02 +01:00
|
|
|
if (key->occlusion_count) {
|
|
|
|
debug_printf("occlusion_count = 1\n");
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:28:29 +01:00
|
|
|
if (key->blend.logicop_enable) {
|
2010-05-19 18:37:42 +01:00
|
|
|
debug_printf("blend.logicop_func = %s\n", util_dump_logicop(key->blend.logicop_func, TRUE));
|
2010-05-19 18:28:29 +01:00
|
|
|
}
|
|
|
|
else if (key->blend.rt[0].blend_enable) {
|
|
|
|
debug_printf("blend.rgb_func = %s\n", util_dump_blend_func (key->blend.rt[0].rgb_func, TRUE));
|
2010-05-19 19:39:52 +01:00
|
|
|
debug_printf("blend.rgb_src_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].rgb_src_factor, TRUE));
|
|
|
|
debug_printf("blend.rgb_dst_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].rgb_dst_factor, TRUE));
|
|
|
|
debug_printf("blend.alpha_func = %s\n", util_dump_blend_func (key->blend.rt[0].alpha_func, TRUE));
|
|
|
|
debug_printf("blend.alpha_src_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_src_factor, TRUE));
|
|
|
|
debug_printf("blend.alpha_dst_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_dst_factor, TRUE));
|
2010-05-19 18:28:29 +01:00
|
|
|
}
|
|
|
|
debug_printf("blend.colormask = 0x%x\n", key->blend.rt[0].colormask);
|
2010-10-03 11:39:02 +01:00
|
|
|
for (i = 0; i < key->nr_samplers; ++i) {
|
|
|
|
debug_printf("sampler[%u] = \n", i);
|
|
|
|
debug_printf(" .format = %s\n",
|
|
|
|
util_format_name(key->sampler[i].format));
|
|
|
|
debug_printf(" .target = %s\n",
|
|
|
|
util_dump_tex_target(key->sampler[i].target, TRUE));
|
|
|
|
debug_printf(" .pot = %u %u %u\n",
|
|
|
|
key->sampler[i].pot_width,
|
|
|
|
key->sampler[i].pot_height,
|
|
|
|
key->sampler[i].pot_depth);
|
|
|
|
debug_printf(" .wrap = %s %s %s\n",
|
|
|
|
util_dump_tex_wrap(key->sampler[i].wrap_s, TRUE),
|
|
|
|
util_dump_tex_wrap(key->sampler[i].wrap_t, TRUE),
|
|
|
|
util_dump_tex_wrap(key->sampler[i].wrap_r, TRUE));
|
|
|
|
debug_printf(" .min_img_filter = %s\n",
|
|
|
|
util_dump_tex_filter(key->sampler[i].min_img_filter, TRUE));
|
|
|
|
debug_printf(" .min_mip_filter = %s\n",
|
|
|
|
util_dump_tex_mipfilter(key->sampler[i].min_mip_filter, TRUE));
|
|
|
|
debug_printf(" .mag_img_filter = %s\n",
|
|
|
|
util_dump_tex_filter(key->sampler[i].mag_img_filter, TRUE));
|
|
|
|
if (key->sampler[i].compare_mode != PIPE_TEX_COMPARE_NONE)
|
|
|
|
debug_printf(" .compare_func = %s\n", util_dump_func(key->sampler[i].compare_func, TRUE));
|
|
|
|
debug_printf(" .normalized_coords = %u\n", key->sampler[i].normalized_coords);
|
2010-10-06 14:53:19 +01:00
|
|
|
debug_printf(" .min_max_lod_equal = %u\n", key->sampler[i].min_max_lod_equal);
|
|
|
|
debug_printf(" .lod_bias_non_zero = %u\n", key->sampler[i].lod_bias_non_zero);
|
|
|
|
debug_printf(" .apply_min_lod = %u\n", key->sampler[i].apply_min_lod);
|
|
|
|
debug_printf(" .apply_max_lod = %u\n", key->sampler[i].apply_max_lod);
|
2010-05-19 18:28:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-24 20:08:13 +01:00
|
|
|
void
|
|
|
|
lp_debug_fs_variant(const struct lp_fragment_shader_variant *variant)
|
|
|
|
{
|
|
|
|
debug_printf("llvmpipe: Fragment shader #%u variant #%u:\n",
|
|
|
|
variant->shader->no, variant->no);
|
|
|
|
tgsi_dump(variant->shader->base.tokens, 0);
|
|
|
|
dump_fs_variant_key(&variant->key);
|
|
|
|
debug_printf("variant->opaque = %u\n", variant->opaque);
|
|
|
|
debug_printf("\n");
|
|
|
|
}
|
2010-05-19 18:28:29 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a new fragment shader variant from the shader code and
|
|
|
|
* other state indicated by the key.
|
|
|
|
*/
|
2010-01-11 20:16:00 +00:00
|
|
|
static struct lp_fragment_shader_variant *
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_variant(struct llvmpipe_context *lp,
|
2010-01-11 20:16:00 +00:00
|
|
|
struct lp_fragment_shader *shader,
|
|
|
|
const struct lp_fragment_shader_variant_key *key)
|
|
|
|
{
|
|
|
|
struct lp_fragment_shader_variant *variant;
|
2012-04-18 15:25:34 +01:00
|
|
|
const struct util_format_description *cbuf0_format_desc;
|
2010-09-03 20:26:13 +01:00
|
|
|
boolean fullcolormask;
|
2010-01-11 20:16:00 +00:00
|
|
|
|
|
|
|
variant = CALLOC_STRUCT(lp_fragment_shader_variant);
|
|
|
|
if(!variant)
|
|
|
|
return NULL;
|
|
|
|
|
2010-06-21 14:11:15 +01:00
|
|
|
variant->shader = shader;
|
2010-06-18 13:52:17 +01:00
|
|
|
variant->list_item_global.base = variant;
|
|
|
|
variant->list_item_local.base = variant;
|
|
|
|
variant->no = shader->variants_created++;
|
2010-06-03 14:22:41 +01:00
|
|
|
|
2010-08-22 12:31:18 +01:00
|
|
|
memcpy(&variant->key, key, shader->variant_key_size);
|
2009-08-16 11:50:17 +01:00
|
|
|
|
2010-09-03 20:26:13 +01:00
|
|
|
/*
|
|
|
|
* Determine whether we are touching all channels in the color buffer.
|
|
|
|
*/
|
|
|
|
fullcolormask = FALSE;
|
|
|
|
if (key->nr_cbufs == 1) {
|
2012-04-18 15:25:34 +01:00
|
|
|
cbuf0_format_desc = util_format_description(key->cbuf_format[0]);
|
|
|
|
fullcolormask = util_format_colormask_full(cbuf0_format_desc, key->blend.rt[0].colormask);
|
2010-09-03 20:26:13 +01:00
|
|
|
}
|
|
|
|
|
2010-05-12 17:12:59 +01:00
|
|
|
variant->opaque =
|
|
|
|
!key->blend.logicop_enable &&
|
|
|
|
!key->blend.rt[0].blend_enable &&
|
2010-09-03 20:26:13 +01:00
|
|
|
fullcolormask &&
|
2010-05-12 17:12:59 +01:00
|
|
|
!key->stencil[0].enabled &&
|
|
|
|
!key->alpha.enabled &&
|
|
|
|
!key->depth.enabled &&
|
2010-09-02 16:30:23 +01:00
|
|
|
!shader->info.base.uses_kill
|
2010-05-12 17:12:59 +01:00
|
|
|
? TRUE : FALSE;
|
|
|
|
|
2010-09-07 14:02:15 +01:00
|
|
|
|
2010-09-16 15:16:27 +01:00
|
|
|
if ((LP_DEBUG & DEBUG_FS) || (gallivm_debug & GALLIVM_DEBUG_IR)) {
|
2010-09-07 14:02:15 +01:00
|
|
|
lp_debug_fs_variant(variant);
|
|
|
|
}
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_fragment(lp, shader, variant, RAST_EDGE_TEST);
|
2010-09-07 14:02:15 +01:00
|
|
|
|
2010-09-12 10:14:50 +01:00
|
|
|
if (variant->opaque) {
|
|
|
|
/* Specialized shader, which doesn't need to read the color buffer. */
|
2010-11-30 23:07:52 +00:00
|
|
|
generate_fragment(lp, shader, variant, RAST_WHOLE);
|
2010-09-12 10:14:50 +01:00
|
|
|
} else {
|
|
|
|
variant->jit_function[RAST_WHOLE] = variant->jit_function[RAST_EDGE_TEST];
|
|
|
|
}
|
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
return variant;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-28 21:13:11 +01:00
|
|
|
static void *
|
2009-08-19 20:42:50 +01:00
|
|
|
llvmpipe_create_fs_state(struct pipe_context *pipe,
|
|
|
|
const struct pipe_shader_state *templ)
|
|
|
|
{
|
2010-09-20 19:52:16 +01:00
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
2009-08-19 20:42:50 +01:00
|
|
|
struct lp_fragment_shader *shader;
|
2010-08-22 12:31:18 +01:00
|
|
|
int nr_samplers;
|
2010-09-05 13:17:43 +01:00
|
|
|
int i;
|
2009-08-19 20:42:50 +01:00
|
|
|
|
|
|
|
shader = CALLOC_STRUCT(lp_fragment_shader);
|
|
|
|
if (!shader)
|
|
|
|
return NULL;
|
|
|
|
|
2010-06-03 14:22:41 +01:00
|
|
|
shader->no = fs_no++;
|
2010-06-18 13:52:17 +01:00
|
|
|
make_empty_list(&shader->variants);
|
2010-06-03 14:22:41 +01:00
|
|
|
|
2009-08-19 20:42:50 +01:00
|
|
|
/* get/save the summary info for this shader */
|
2010-09-02 16:30:23 +01:00
|
|
|
lp_build_tgsi_info(templ->tokens, &shader->info);
|
2009-08-19 20:42:50 +01:00
|
|
|
|
|
|
|
/* we need to keep a local copy of the tokens */
|
|
|
|
shader->base.tokens = tgsi_dup_tokens(templ->tokens);
|
|
|
|
|
2010-09-20 19:52:16 +01:00
|
|
|
shader->draw_data = draw_create_fragment_shader(llvmpipe->draw, templ);
|
|
|
|
if (shader->draw_data == NULL) {
|
|
|
|
FREE((void *) shader->base.tokens);
|
2010-09-21 17:51:06 +01:00
|
|
|
FREE(shader);
|
2010-09-20 19:52:16 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-02 16:30:23 +01:00
|
|
|
nr_samplers = shader->info.base.file_max[TGSI_FILE_SAMPLER] + 1;
|
2010-08-22 12:31:18 +01:00
|
|
|
|
|
|
|
shader->variant_key_size = Offset(struct lp_fragment_shader_variant_key,
|
|
|
|
sampler[nr_samplers]);
|
|
|
|
|
2010-10-18 03:03:42 +01:00
|
|
|
for (i = 0; i < shader->info.base.num_inputs; i++) {
|
|
|
|
shader->inputs[i].usage_mask = shader->info.base.input_usage_mask[i];
|
2010-09-05 13:17:43 +01:00
|
|
|
|
2010-10-18 03:03:42 +01:00
|
|
|
switch (shader->info.base.input_interpolate[i]) {
|
2010-09-05 13:17:43 +01:00
|
|
|
case TGSI_INTERPOLATE_CONSTANT:
|
|
|
|
shader->inputs[i].interp = LP_INTERP_CONSTANT;
|
|
|
|
break;
|
|
|
|
case TGSI_INTERPOLATE_LINEAR:
|
|
|
|
shader->inputs[i].interp = LP_INTERP_LINEAR;
|
|
|
|
break;
|
|
|
|
case TGSI_INTERPOLATE_PERSPECTIVE:
|
|
|
|
shader->inputs[i].interp = LP_INTERP_PERSPECTIVE;
|
|
|
|
break;
|
2012-01-11 17:14:26 +00:00
|
|
|
case TGSI_INTERPOLATE_COLOR:
|
|
|
|
shader->inputs[i].interp = LP_INTERP_COLOR;
|
|
|
|
break;
|
2010-09-05 13:17:43 +01:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-10-18 03:03:42 +01:00
|
|
|
switch (shader->info.base.input_semantic_name[i]) {
|
2010-09-05 13:17:43 +01:00
|
|
|
case TGSI_SEMANTIC_FACE:
|
|
|
|
shader->inputs[i].interp = LP_INTERP_FACING;
|
|
|
|
break;
|
|
|
|
case TGSI_SEMANTIC_POSITION:
|
|
|
|
/* Position was already emitted above
|
|
|
|
*/
|
|
|
|
shader->inputs[i].interp = LP_INTERP_POSITION;
|
|
|
|
shader->inputs[i].src_index = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
shader->inputs[i].src_index = i+1;
|
|
|
|
}
|
|
|
|
|
2010-05-31 20:01:29 +01:00
|
|
|
if (LP_DEBUG & DEBUG_TGSI) {
|
2010-06-01 16:28:45 +01:00
|
|
|
unsigned attrib;
|
2010-11-30 23:07:52 +00:00
|
|
|
debug_printf("llvmpipe: Create fragment shader #%u %p:\n",
|
|
|
|
shader->no, (void *) shader);
|
2010-04-28 20:18:51 +01:00
|
|
|
tgsi_dump(templ->tokens, 0);
|
2010-06-01 16:28:45 +01:00
|
|
|
debug_printf("usage masks:\n");
|
2010-09-02 16:30:23 +01:00
|
|
|
for (attrib = 0; attrib < shader->info.base.num_inputs; ++attrib) {
|
|
|
|
unsigned usage_mask = shader->info.base.input_usage_mask[attrib];
|
2010-06-01 16:28:45 +01:00
|
|
|
debug_printf(" IN[%u].%s%s%s%s\n",
|
|
|
|
attrib,
|
|
|
|
usage_mask & TGSI_WRITEMASK_X ? "x" : "",
|
|
|
|
usage_mask & TGSI_WRITEMASK_Y ? "y" : "",
|
|
|
|
usage_mask & TGSI_WRITEMASK_Z ? "z" : "",
|
|
|
|
usage_mask & TGSI_WRITEMASK_W ? "w" : "");
|
|
|
|
}
|
|
|
|
debug_printf("\n");
|
2010-04-28 20:18:51 +01:00
|
|
|
}
|
|
|
|
|
2009-08-14 10:27:32 +01:00
|
|
|
return shader;
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-28 21:13:11 +01:00
|
|
|
static void
|
2009-07-26 23:44:38 +01:00
|
|
|
llvmpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
|
|
|
|
{
|
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
|
|
|
|
2009-12-26 15:21:16 +00:00
|
|
|
if (llvmpipe->fs == fs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
draw_flush(llvmpipe->draw);
|
|
|
|
|
2010-11-02 17:53:14 +00:00
|
|
|
llvmpipe->fs = (struct lp_fragment_shader *) fs;
|
2010-11-02 17:49:10 +00:00
|
|
|
|
2010-09-20 19:52:16 +01:00
|
|
|
draw_bind_fragment_shader(llvmpipe->draw,
|
|
|
|
(llvmpipe->fs ? llvmpipe->fs->draw_data : NULL));
|
|
|
|
|
2009-07-27 11:36:24 +01:00
|
|
|
llvmpipe->dirty |= LP_NEW_FS;
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove shader variant from two lists: the shader's variant list
|
|
|
|
* and the context's variant list.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
llvmpipe_remove_shader_variant(struct llvmpipe_context *lp,
|
|
|
|
struct lp_fragment_shader_variant *variant)
|
2010-06-18 13:52:17 +01:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (gallivm_debug & GALLIVM_DEBUG_IR) {
|
2010-11-30 23:07:52 +00:00
|
|
|
debug_printf("llvmpipe: del fs #%u var #%u v created #%u v cached"
|
|
|
|
" #%u v total cached #%u\n",
|
|
|
|
variant->shader->no,
|
|
|
|
variant->no,
|
|
|
|
variant->shader->variants_created,
|
|
|
|
variant->shader->variants_cached,
|
|
|
|
lp->nr_fs_variants);
|
2010-06-18 13:52:17 +01:00
|
|
|
}
|
2010-11-30 23:07:52 +00:00
|
|
|
|
|
|
|
/* free all the variant's JIT'd functions */
|
2010-06-18 13:52:17 +01:00
|
|
|
for (i = 0; i < Elements(variant->function); i++) {
|
|
|
|
if (variant->function[i]) {
|
|
|
|
if (variant->jit_function[i])
|
2010-11-30 23:07:52 +00:00
|
|
|
LLVMFreeMachineCodeForFunction(lp->gallivm->engine,
|
2010-06-18 13:52:17 +01:00
|
|
|
variant->function[i]);
|
|
|
|
LLVMDeleteFunction(variant->function[i]);
|
|
|
|
}
|
|
|
|
}
|
2010-11-30 23:07:52 +00:00
|
|
|
|
|
|
|
/* remove from shader's list */
|
2010-06-18 13:52:17 +01:00
|
|
|
remove_from_list(&variant->list_item_local);
|
2010-06-21 14:11:15 +01:00
|
|
|
variant->shader->variants_cached--;
|
2010-11-30 23:07:52 +00:00
|
|
|
|
|
|
|
/* remove from context's list */
|
2010-06-18 13:52:17 +01:00
|
|
|
remove_from_list(&variant->list_item_global);
|
|
|
|
lp->nr_fs_variants--;
|
2011-11-30 17:12:00 +00:00
|
|
|
lp->nr_fs_instrs -= variant->nr_instrs;
|
2010-11-30 23:07:52 +00:00
|
|
|
|
2010-06-18 13:52:17 +01:00
|
|
|
FREE(variant);
|
|
|
|
}
|
2009-07-26 23:44:38 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
|
2010-04-28 21:13:11 +01:00
|
|
|
static void
|
2009-07-26 23:44:38 +01:00
|
|
|
llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
|
|
|
|
{
|
2009-08-21 07:48:04 +01:00
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
2009-08-14 10:27:32 +01:00
|
|
|
struct lp_fragment_shader *shader = fs;
|
2010-06-18 13:52:17 +01:00
|
|
|
struct lp_fs_variant_list_item *li;
|
2009-07-26 23:44:38 +01:00
|
|
|
|
2009-08-21 07:48:04 +01:00
|
|
|
assert(fs != llvmpipe->fs);
|
2009-08-19 20:42:50 +01:00
|
|
|
|
2010-03-03 18:47:29 +00:00
|
|
|
/*
|
|
|
|
* XXX: we need to flush the context until we have some sort of reference
|
|
|
|
* counting in fragment shaders as they may still be binned
|
2010-06-18 13:52:17 +01:00
|
|
|
* Flushing alone might not sufficient we need to wait on it too.
|
2010-03-03 18:47:29 +00:00
|
|
|
*/
|
2010-08-20 15:14:19 +01:00
|
|
|
llvmpipe_finish(pipe, __FUNCTION__);
|
2009-08-19 20:42:50 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
/* Delete all the variants */
|
2010-06-18 13:52:17 +01:00
|
|
|
li = first_elem(&shader->variants);
|
|
|
|
while(!at_end(&shader->variants, li)) {
|
2010-06-18 17:37:37 +01:00
|
|
|
struct lp_fs_variant_list_item *next = next_elem(li);
|
2010-11-30 23:07:52 +00:00
|
|
|
llvmpipe_remove_shader_variant(llvmpipe, li->base);
|
2010-06-18 17:37:37 +01:00
|
|
|
li = next;
|
2009-08-14 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
/* Delete draw module's data */
|
2010-09-20 19:52:16 +01:00
|
|
|
draw_delete_fragment_shader(llvmpipe->draw, shader->draw_data);
|
|
|
|
|
2010-06-18 13:52:17 +01:00
|
|
|
assert(shader->variants_cached == 0);
|
2009-08-14 10:27:32 +01:00
|
|
|
FREE((void *) shader->base.tokens);
|
|
|
|
FREE(shader);
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-28 21:13:11 +01:00
|
|
|
static void
|
2009-07-26 23:44:38 +01:00
|
|
|
llvmpipe_set_constant_buffer(struct pipe_context *pipe,
|
|
|
|
uint shader, uint index,
|
2012-04-24 18:52:26 +01:00
|
|
|
struct pipe_constant_buffer *cb)
|
2009-07-26 23:44:38 +01:00
|
|
|
{
|
|
|
|
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
2012-04-24 18:52:26 +01:00
|
|
|
struct pipe_resource *constants = cb ? cb->buffer : NULL;
|
2012-04-24 21:53:05 +01:00
|
|
|
unsigned size;
|
|
|
|
const void *data;
|
|
|
|
|
|
|
|
if (cb && cb->user_buffer) {
|
2012-05-11 23:16:11 +01:00
|
|
|
constants = llvmpipe_user_buffer_create(pipe->screen,
|
|
|
|
(void *) cb->user_buffer,
|
2012-04-24 21:53:05 +01:00
|
|
|
cb->buffer_size,
|
|
|
|
PIPE_BIND_CONSTANT_BUFFER);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = constants ? constants->width0 : 0;
|
|
|
|
data = constants ? llvmpipe_resource_data(constants) : NULL;
|
2009-07-26 23:44:38 +01:00
|
|
|
|
|
|
|
assert(shader < PIPE_SHADER_TYPES);
|
2010-05-28 16:54:35 +01:00
|
|
|
assert(index < PIPE_MAX_CONSTANT_BUFFERS);
|
2009-07-26 23:44:38 +01:00
|
|
|
|
2010-05-28 16:54:35 +01:00
|
|
|
if(llvmpipe->constants[shader][index] == constants)
|
2009-10-09 13:41:33 +01:00
|
|
|
return;
|
|
|
|
|
2009-12-26 15:21:16 +00:00
|
|
|
draw_flush(llvmpipe->draw);
|
2009-10-09 11:29:33 +01:00
|
|
|
|
2009-07-26 23:44:38 +01:00
|
|
|
/* note: reference counting */
|
2010-05-28 16:54:35 +01:00
|
|
|
pipe_resource_reference(&llvmpipe->constants[shader][index], constants);
|
2009-10-09 11:29:33 +01:00
|
|
|
|
2010-06-22 17:56:54 +01:00
|
|
|
if(shader == PIPE_SHADER_VERTEX ||
|
|
|
|
shader == PIPE_SHADER_GEOMETRY) {
|
|
|
|
draw_set_mapped_constant_buffer(llvmpipe->draw, shader,
|
|
|
|
index, data, size);
|
2009-10-09 11:29:33 +01:00
|
|
|
}
|
2009-07-26 23:44:38 +01:00
|
|
|
|
2009-07-27 11:36:24 +01:00
|
|
|
llvmpipe->dirty |= LP_NEW_CONSTANTS;
|
2012-04-24 21:53:05 +01:00
|
|
|
|
|
|
|
if (cb && cb->user_buffer) {
|
|
|
|
pipe_resource_reference(&constants, NULL);
|
|
|
|
}
|
2009-07-26 23:44:38 +01:00
|
|
|
}
|
2009-08-19 20:42:50 +01:00
|
|
|
|
|
|
|
|
2010-05-02 21:36:12 +01:00
|
|
|
/**
|
|
|
|
* Return the blend factor equivalent to a destination alpha of one.
|
|
|
|
*/
|
|
|
|
static INLINE unsigned
|
2010-09-22 15:02:10 +01:00
|
|
|
force_dst_alpha_one(unsigned factor)
|
2010-05-02 21:36:12 +01:00
|
|
|
{
|
|
|
|
switch(factor) {
|
|
|
|
case PIPE_BLENDFACTOR_DST_ALPHA:
|
|
|
|
return PIPE_BLENDFACTOR_ONE;
|
|
|
|
case PIPE_BLENDFACTOR_INV_DST_ALPHA:
|
|
|
|
return PIPE_BLENDFACTOR_ZERO;
|
|
|
|
case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
|
|
|
|
return PIPE_BLENDFACTOR_ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-23 07:38:41 +01:00
|
|
|
/**
|
|
|
|
* We need to generate several variants of the fragment pipeline to match
|
|
|
|
* all the combinations of the contributing state atoms.
|
|
|
|
*
|
|
|
|
* TODO: there is actually no reason to tie this to context state -- the
|
|
|
|
* generated code could be cached globally in the screen.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
make_variant_key(struct llvmpipe_context *lp,
|
2009-09-07 14:52:39 +01:00
|
|
|
struct lp_fragment_shader *shader,
|
2009-08-23 07:38:41 +01:00
|
|
|
struct lp_fragment_shader_variant_key *key)
|
|
|
|
{
|
2009-09-07 14:52:39 +01:00
|
|
|
unsigned i;
|
|
|
|
|
2010-08-22 12:31:18 +01:00
|
|
|
memset(key, 0, shader->variant_key_size);
|
2009-08-23 07:38:41 +01:00
|
|
|
|
2010-03-16 20:32:18 +00:00
|
|
|
if (lp->framebuffer.zsbuf) {
|
|
|
|
if (lp->depth_stencil->depth.enabled) {
|
|
|
|
key->zsbuf_format = lp->framebuffer.zsbuf->format;
|
|
|
|
memcpy(&key->depth, &lp->depth_stencil->depth, sizeof key->depth);
|
|
|
|
}
|
|
|
|
if (lp->depth_stencil->stencil[0].enabled) {
|
|
|
|
key->zsbuf_format = lp->framebuffer.zsbuf->format;
|
|
|
|
memcpy(&key->stencil, &lp->depth_stencil->stencil, sizeof key->stencil);
|
|
|
|
}
|
2009-09-09 21:16:06 +01:00
|
|
|
}
|
2009-08-23 07:38:41 +01:00
|
|
|
|
|
|
|
key->alpha.enabled = lp->depth_stencil->alpha.enabled;
|
|
|
|
if(key->alpha.enabled)
|
|
|
|
key->alpha.func = lp->depth_stencil->alpha.func;
|
|
|
|
/* alpha.ref_value is passed in jit_context */
|
|
|
|
|
2010-01-11 12:06:51 +00:00
|
|
|
key->flatshade = lp->rasterizer->flatshade;
|
2010-05-06 18:45:42 +01:00
|
|
|
if (lp->active_query_count) {
|
|
|
|
key->occlusion_count = TRUE;
|
|
|
|
}
|
2009-09-10 12:37:44 +01:00
|
|
|
|
2010-01-10 17:22:09 +00:00
|
|
|
if (lp->framebuffer.nr_cbufs) {
|
2009-09-10 12:37:44 +01:00
|
|
|
memcpy(&key->blend, lp->blend, sizeof key->blend);
|
2010-01-10 17:22:09 +00:00
|
|
|
}
|
2009-09-10 12:37:44 +01:00
|
|
|
|
2010-01-10 17:22:09 +00:00
|
|
|
key->nr_cbufs = lp->framebuffer.nr_cbufs;
|
|
|
|
for (i = 0; i < lp->framebuffer.nr_cbufs; i++) {
|
2010-09-03 20:26:13 +01:00
|
|
|
enum pipe_format format = lp->framebuffer.cbufs[i]->format;
|
2010-05-02 21:36:12 +01:00
|
|
|
struct pipe_rt_blend_state *blend_rt = &key->blend.rt[i];
|
2009-09-10 12:37:44 +01:00
|
|
|
const struct util_format_description *format_desc;
|
|
|
|
|
2010-09-03 20:26:13 +01:00
|
|
|
key->cbuf_format[i] = format;
|
|
|
|
|
|
|
|
format_desc = util_format_description(format);
|
2010-04-22 15:11:57 +01:00
|
|
|
assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB ||
|
|
|
|
format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB);
|
2009-09-10 12:37:44 +01:00
|
|
|
|
2010-05-02 21:36:12 +01:00
|
|
|
blend_rt->colormask = lp->blend->rt[i].colormask;
|
2010-04-16 21:08:15 +01:00
|
|
|
|
2010-09-03 20:26:13 +01:00
|
|
|
/*
|
|
|
|
* Mask out color channels not present in the color buffer.
|
2010-01-10 17:22:09 +00:00
|
|
|
*/
|
2010-09-03 20:26:13 +01:00
|
|
|
blend_rt->colormask &= util_format_colormask(format_desc);
|
2010-05-02 21:36:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Our swizzled render tiles always have an alpha channel, but the linear
|
|
|
|
* render target format often does not, so force here the dst alpha to be
|
|
|
|
* one.
|
|
|
|
*
|
|
|
|
* This is not a mere optimization. Wrong results will be produced if the
|
|
|
|
* dst alpha is used, the dst format does not have alpha, and the previous
|
|
|
|
* rendering was not flushed from the swizzled to linear buffer. For
|
|
|
|
* example, NonPowTwo DCT.
|
|
|
|
*
|
|
|
|
* TODO: This should be generalized to all channels for better
|
|
|
|
* performance, but only alpha causes correctness issues.
|
2010-09-22 15:02:10 +01:00
|
|
|
*
|
|
|
|
* Also, force rgb/alpha func/factors match, to make AoS blending easier.
|
2010-05-02 21:36:12 +01:00
|
|
|
*/
|
2011-12-30 20:10:26 +00:00
|
|
|
if (format_desc->swizzle[3] > UTIL_FORMAT_SWIZZLE_W ||
|
|
|
|
format_desc->swizzle[3] == format_desc->swizzle[0]) {
|
2010-09-22 15:02:10 +01:00
|
|
|
blend_rt->rgb_src_factor = force_dst_alpha_one(blend_rt->rgb_src_factor);
|
|
|
|
blend_rt->rgb_dst_factor = force_dst_alpha_one(blend_rt->rgb_dst_factor);
|
|
|
|
blend_rt->alpha_func = blend_rt->rgb_func;
|
|
|
|
blend_rt->alpha_src_factor = blend_rt->rgb_src_factor;
|
|
|
|
blend_rt->alpha_dst_factor = blend_rt->rgb_dst_factor;
|
2009-09-10 12:37:44 +01:00
|
|
|
}
|
|
|
|
}
|
2009-09-07 14:52:39 +01:00
|
|
|
|
2010-08-22 12:31:18 +01:00
|
|
|
/* This value will be the same for all the variants of a given shader:
|
|
|
|
*/
|
2010-09-02 16:30:23 +01:00
|
|
|
key->nr_samplers = shader->info.base.file_max[TGSI_FILE_SAMPLER] + 1;
|
2010-08-22 12:31:18 +01:00
|
|
|
|
|
|
|
for(i = 0; i < key->nr_samplers; ++i) {
|
2010-09-02 16:30:23 +01:00
|
|
|
if(shader->info.base.file_mask[TGSI_FILE_SAMPLER] & (1 << i)) {
|
2010-08-22 12:31:18 +01:00
|
|
|
lp_sampler_static_state(&key->sampler[i],
|
|
|
|
lp->fragment_sampler_views[i],
|
|
|
|
lp->sampler[i]);
|
|
|
|
}
|
|
|
|
}
|
2009-08-23 07:38:41 +01:00
|
|
|
}
|
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
|
|
|
|
|
2010-01-13 17:58:36 +00:00
|
|
|
/**
|
2010-11-30 23:07:52 +00:00
|
|
|
* Update fragment shader state. This is called just prior to drawing
|
2010-01-13 17:58:36 +00:00
|
|
|
* something when some fragment-related state has changed.
|
|
|
|
*/
|
2009-08-22 22:26:55 +01:00
|
|
|
void
|
|
|
|
llvmpipe_update_fs(struct llvmpipe_context *lp)
|
2009-08-19 20:42:50 +01:00
|
|
|
{
|
|
|
|
struct lp_fragment_shader *shader = lp->fs;
|
2009-08-21 07:48:04 +01:00
|
|
|
struct lp_fragment_shader_variant_key key;
|
2010-06-18 13:52:17 +01:00
|
|
|
struct lp_fragment_shader_variant *variant = NULL;
|
|
|
|
struct lp_fs_variant_list_item *li;
|
2009-08-19 20:42:50 +01:00
|
|
|
|
2009-09-07 14:52:39 +01:00
|
|
|
make_variant_key(lp, shader, &key);
|
2009-08-21 07:48:04 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
/* Search the variants for one which matches the key */
|
2010-06-18 13:52:17 +01:00
|
|
|
li = first_elem(&shader->variants);
|
|
|
|
while(!at_end(&shader->variants, li)) {
|
2010-08-22 12:31:18 +01:00
|
|
|
if(memcmp(&li->base->key, &key, shader->variant_key_size) == 0) {
|
2010-06-18 13:52:17 +01:00
|
|
|
variant = li->base;
|
2009-08-19 20:42:50 +01:00
|
|
|
break;
|
2010-06-18 13:52:17 +01:00
|
|
|
}
|
|
|
|
li = next_elem(li);
|
2009-08-19 20:42:50 +01:00
|
|
|
}
|
|
|
|
|
2010-06-18 13:52:17 +01:00
|
|
|
if (variant) {
|
2010-11-30 23:07:52 +00:00
|
|
|
/* Move this variant to the head of the list to implement LRU
|
|
|
|
* deletion of shader's when we have too many.
|
|
|
|
*/
|
2010-06-18 13:52:17 +01:00
|
|
|
move_to_head(&lp->fs_variants_list, &variant->list_item_global);
|
|
|
|
}
|
|
|
|
else {
|
2010-11-30 23:07:52 +00:00
|
|
|
/* variant not found, create it now */
|
|
|
|
int64_t t0, t1, dt;
|
2010-06-18 13:52:17 +01:00
|
|
|
unsigned i;
|
2011-11-30 17:12:00 +00:00
|
|
|
unsigned variants_to_cull;
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
debug_printf("%u variants,\t%u instrs,\t%u instrs/variant\n",
|
|
|
|
lp->nr_fs_variants,
|
|
|
|
lp->nr_fs_instrs,
|
|
|
|
lp->nr_fs_variants ? lp->nr_fs_instrs / lp->nr_fs_variants : 0);
|
|
|
|
}
|
2010-11-30 23:07:52 +00:00
|
|
|
|
|
|
|
/* First, check if we've exceeded the max number of shader variants.
|
|
|
|
* If so, free 25% of them (the least recently used ones).
|
|
|
|
*/
|
2011-11-30 17:12:00 +00:00
|
|
|
variants_to_cull = lp->nr_fs_variants >= LP_MAX_SHADER_VARIANTS ? LP_MAX_SHADER_VARIANTS / 4 : 0;
|
|
|
|
|
|
|
|
if (variants_to_cull ||
|
|
|
|
lp->nr_fs_instrs >= LP_MAX_SHADER_INSTRUCTIONS) {
|
2010-06-18 13:52:17 +01:00
|
|
|
struct pipe_context *pipe = &lp->pipe;
|
|
|
|
|
|
|
|
/*
|
2010-11-30 23:07:52 +00:00
|
|
|
* XXX: we need to flush the context until we have some sort of
|
|
|
|
* reference counting in fragment shaders as they may still be binned
|
2010-06-18 13:52:17 +01:00
|
|
|
* Flushing alone might not be sufficient we need to wait on it too.
|
|
|
|
*/
|
2010-08-20 15:14:19 +01:00
|
|
|
llvmpipe_finish(pipe, __FUNCTION__);
|
2010-06-18 13:52:17 +01:00
|
|
|
|
2011-09-28 20:23:13 +01:00
|
|
|
/*
|
|
|
|
* We need to re-check lp->nr_fs_variants because an arbitrarliy large
|
|
|
|
* number of shader variants (potentially all of them) could be
|
|
|
|
* pending for destruction on flush.
|
|
|
|
*/
|
|
|
|
|
2011-11-30 17:12:00 +00:00
|
|
|
for (i = 0; i < variants_to_cull || lp->nr_fs_instrs >= LP_MAX_SHADER_INSTRUCTIONS; i++) {
|
|
|
|
struct lp_fs_variant_list_item *item;
|
|
|
|
if (is_empty_list(&lp->fs_variants_list)) {
|
|
|
|
break;
|
2011-09-28 20:23:13 +01:00
|
|
|
}
|
2011-11-30 17:12:00 +00:00
|
|
|
item = last_elem(&lp->fs_variants_list);
|
|
|
|
assert(item);
|
|
|
|
assert(item->base);
|
|
|
|
llvmpipe_remove_shader_variant(lp, item->base);
|
2010-06-18 13:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
2009-08-19 20:42:50 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
/*
|
|
|
|
* Generate the new variant.
|
|
|
|
*/
|
|
|
|
t0 = os_time_get();
|
|
|
|
variant = generate_variant(lp, shader, &key);
|
2010-02-08 20:07:31 +00:00
|
|
|
t1 = os_time_get();
|
|
|
|
dt = t1 - t0;
|
2010-01-27 20:49:43 +00:00
|
|
|
LP_COUNT_ADD(llvm_compile_time, dt);
|
|
|
|
LP_COUNT_ADD(nr_llvm_compiles, 2); /* emit vs. omit in/out test */
|
2010-06-18 13:52:17 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
llvmpipe_variant_count++;
|
|
|
|
|
|
|
|
/* Put the new variant into the list */
|
2010-06-18 13:52:17 +01:00
|
|
|
if (variant) {
|
|
|
|
insert_at_head(&shader->variants, &variant->list_item_local);
|
|
|
|
insert_at_head(&lp->fs_variants_list, &variant->list_item_global);
|
|
|
|
lp->nr_fs_variants++;
|
2011-11-30 17:12:00 +00:00
|
|
|
lp->nr_fs_instrs += variant->nr_instrs;
|
2010-06-18 13:52:17 +01:00
|
|
|
shader->variants_cached++;
|
|
|
|
}
|
2010-01-27 20:49:43 +00:00
|
|
|
}
|
2009-08-19 20:42:50 +01:00
|
|
|
|
2010-11-30 23:07:52 +00:00
|
|
|
/* Bind this variant */
|
2010-05-26 15:11:17 +01:00
|
|
|
lp_setup_set_fs_variant(lp->setup, variant);
|
2009-08-19 20:42:50 +01:00
|
|
|
}
|
2010-04-28 21:13:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-05 13:17:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-28 21:13:11 +01:00
|
|
|
void
|
|
|
|
llvmpipe_init_fs_funcs(struct llvmpipe_context *llvmpipe)
|
|
|
|
{
|
|
|
|
llvmpipe->pipe.create_fs_state = llvmpipe_create_fs_state;
|
|
|
|
llvmpipe->pipe.bind_fs_state = llvmpipe_bind_fs_state;
|
|
|
|
llvmpipe->pipe.delete_fs_state = llvmpipe_delete_fs_state;
|
|
|
|
|
|
|
|
llvmpipe->pipe.set_constant_buffer = llvmpipe_set_constant_buffer;
|
|
|
|
}
|