#include "lp_rast.h"
#include "nir/nir_to_tgsi_info.h"
+#include "lp_screen.h"
+#include "compiler/nir/nir_serialize.h"
+#include "util/mesa-sha1.h"
/** Fragment shader number (for debugging) */
static unsigned fs_no = 0;
s_mask = LLVMBuildAnd(builder, s_mask, test, "");
LLVMBuildStore(builder, s_mask, s_mask_ptr);
}
+};
+
+struct lp_build_fs_llvm_iface {
+ struct lp_build_fs_iface base;
+ struct lp_build_interp_soa_context *interp;
+ struct lp_build_for_loop_state *loop_state;
+ LLVMValueRef mask_store;
+};
+
+static LLVMValueRef fs_interp(const struct lp_build_fs_iface *iface,
+ struct lp_build_context *bld,
+ unsigned attrib, unsigned chan,
+ bool centroid, bool sample,
+ LLVMValueRef attrib_indir,
+ LLVMValueRef offsets[2])
+{
+ struct lp_build_fs_llvm_iface *fs_iface = (struct lp_build_fs_llvm_iface *)iface;
+ struct lp_build_interp_soa_context *interp = fs_iface->interp;
+ unsigned loc = TGSI_INTERPOLATE_LOC_CENTER;
+ if (centroid)
+ loc = TGSI_INTERPOLATE_LOC_CENTROID;
+ if (sample)
+ loc = TGSI_INTERPOLATE_LOC_SAMPLE;
+
+ return lp_build_interp_soa(interp, bld->gallivm, fs_iface->loop_state->counter,
+ fs_iface->mask_store,
+ attrib, chan, loc, attrib_indir, offsets);
}
/**
num_loop,
lp_build_const_int32(gallivm, 1));
+ LLVMValueRef sample_mask_in;
if (key->multisample) {
+ sample_mask_in = lp_build_const_int_vec(gallivm, type, 0);
/* create shader execution mask by combining all sample masks. */
for (unsigned s = 0; s < key->coverage_samples; s++) {
LLVMValueRef s_mask_idx = LLVMBuildMul(builder, num_loop, lp_build_const_int32(gallivm, s), "");
mask_val = s_mask;
else
mask_val = LLVMBuildOr(builder, s_mask, mask_val, "");
+
+ LLVMValueRef mask_in = LLVMBuildAnd(builder, s_mask, lp_build_const_int_vec(gallivm, type, (1 << s)), "");
+ sample_mask_in = LLVMBuildOr(builder, sample_mask_in, mask_in, "");
}
} else {
+ sample_mask_in = lp_build_const_int_vec(gallivm, type, 1);
mask_ptr = LLVMBuildGEP(builder, mask_store,
&loop_state.counter, 1, "mask_ptr");
mask_val = LLVMBuildLoad(builder, mask_ptr, "");
+
+ LLVMValueRef mask_in = LLVMBuildAnd(builder, mask_val, lp_build_const_int_vec(gallivm, type, 1), "");
+ sample_mask_in = LLVMBuildOr(builder, sample_mask_in, mask_in, "");
}
/* 'mask' will control execution based on quad's pixel alive/killed state */
} else
system_values.sample_id = lp_build_const_int32(gallivm, 0);
+ system_values.sample_mask_in = sample_mask_in;
system_values.sample_pos = sample_pos_array;
- lp_build_interp_soa_update_inputs_dyn(interp, gallivm, loop_state.counter, mask_store, system_values.sample_id);
+ lp_build_interp_soa_update_inputs_dyn(interp, gallivm, loop_state.counter, mask_store, sample_loop_state.counter);
+
+ struct lp_build_fs_llvm_iface fs_iface = {
+ .base.interp_fn = fs_interp,
+ .interp = interp,
+ .loop_state = &loop_state,
+ .mask_store = mask_store,
+ };
struct lp_build_tgsi_params params;
memset(¶ms, 0, sizeof(params));
params.type = type;
params.mask = &mask;
+ params.fs_iface = &fs_iface.base;
params.consts_ptr = consts_ptr;
params.const_sizes_ptr = num_consts_ptr;
params.system_values = &system_values;
assert(smaski >= 0);
output_smask = LLVMBuildLoad(builder, outputs[smaski][0], "smask");
- /*
- * Pixel is alive according to the first sample in the mask.
- */
output_smask = LLVMBuildBitCast(builder, output_smask, smask_bld.vec_type, "");
- if (!key->multisample) {
- output_smask = lp_build_and(&smask_bld, output_smask, smask_bld.one);
- output_smask = lp_build_cmp(&smask_bld, PIPE_FUNC_NOTEQUAL, output_smask, smask_bld.zero);
- lp_build_mask_update(&mask, output_smask);
- }
if (key->min_samples > 1) {
/* only the bit corresponding to this sample is to be used. */
blend_vec_type = lp_build_vec_type(gallivm, blend_type);
- snprintf(func_name, sizeof(func_name), "fs%u_variant%u_%s",
- shader->no, variant->no, partial_mask ? "partial" : "whole");
+ snprintf(func_name, sizeof(func_name), "fs_variant_%s",
+ partial_mask ? "partial" : "whole");
arg_types[0] = variant->jit_context_ptr_type; /* context */
arg_types[1] = int32_type; /* x */
if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind)
lp_add_function_attr(function, i + 1, LP_FUNC_ATTR_NOALIAS);
+ if (variant->gallivm->cache->data_size)
+ return;
+
context_ptr = LLVMGetParam(function, 0);
x = LLVMGetParam(function, 1);
y = LLVMGetParam(function, 2);
}
/* code generated texture sampling */
- sampler = lp_llvm_sampler_soa_create(key->samplers);
+ sampler = lp_llvm_sampler_soa_create(key->samplers, key->nr_samplers);
image = lp_llvm_image_soa_create(lp_fs_variant_key_images(key));
num_fs = 16 / fs_type.length; /* number of loops per 4x4 stamp */
num_loop_samp, "mask_store");
LLVMTypeRef flt_type = LLVMFloatTypeInContext(gallivm->context);
- LLVMValueRef glob_sample_pos = LLVMAddGlobal(gallivm->module, flt_type, "");
+ LLVMValueRef glob_sample_pos = LLVMAddGlobal(gallivm->module, LLVMArrayType(flt_type, key->coverage_samples * 2), "");
LLVMValueRef sample_pos_array;
if (key->multisample && key->coverage_samples == 4) {
debug_printf("\n");
}
+static void
+lp_fs_get_ir_cache_key(struct lp_fragment_shader_variant *variant,
+ unsigned char ir_sha1_cache_key[20])
+{
+ struct blob blob = { 0 };
+ unsigned ir_size;
+ void *ir_binary;
+
+ blob_init(&blob);
+ nir_serialize(&blob, variant->shader->base.ir.nir, true);
+ ir_binary = blob.data;
+ ir_size = blob.size;
+
+ struct mesa_sha1 ctx;
+ _mesa_sha1_init(&ctx);
+ _mesa_sha1_update(&ctx, &variant->key, variant->shader->variant_key_size);
+ _mesa_sha1_update(&ctx, ir_binary, ir_size);
+ _mesa_sha1_final(&ctx, ir_sha1_cache_key);
+
+ blob_finish(&blob);
+}
/**
* Generate a new fragment shader variant from the shader code and
struct lp_fragment_shader *shader,
const struct lp_fragment_shader_variant_key *key)
{
+ struct llvmpipe_screen *screen = llvmpipe_screen(lp->pipe.screen);
struct lp_fragment_shader_variant *variant;
const struct util_format_description *cbuf0_format_desc = NULL;
boolean fullcolormask;
char module_name[64];
-
+ unsigned char ir_sha1_cache_key[20];
+ struct lp_cached_code cached = { 0 };
+ bool needs_caching = false;
variant = MALLOC(sizeof *variant + shader->variant_key_size - sizeof variant->key);
if (!variant)
return NULL;
snprintf(module_name, sizeof(module_name), "fs%u_variant%u",
shader->no, shader->variants_created);
- variant->gallivm = gallivm_create(module_name, lp->context);
+ variant->shader = shader;
+ memcpy(&variant->key, key, shader->variant_key_size);
+
+ if (shader->base.ir.nir) {
+ lp_fs_get_ir_cache_key(variant, ir_sha1_cache_key);
+
+ lp_disk_cache_find_shader(screen, &cached, ir_sha1_cache_key);
+ if (!cached.data_size)
+ needs_caching = true;
+ }
+ variant->gallivm = gallivm_create(module_name, lp->context, &cached);
if (!variant->gallivm) {
FREE(variant);
return NULL;
}
- variant->shader = shader;
variant->list_item_global.base = variant;
variant->list_item_local.base = variant;
variant->no = shader->variants_created++;
- memcpy(&variant->key, key, shader->variant_key_size);
+
/*
* Determine whether we are touching all channels in the color buffer.
variant->jit_function[RAST_WHOLE] = variant->jit_function[RAST_EDGE_TEST];
}
+ if (needs_caching) {
+ lp_disk_cache_insert_shader(screen, &cached, ir_sha1_cache_key);
+ }
+
gallivm_free_ir(variant->gallivm);
return variant;