#include "draw/draw_vs.h"
#include "draw/draw_llvm.h"
#include "gallivm/lp_bld_init.h"
+#include "gallivm/lp_bld_debug.h"
struct llvm_middle_end {
llvm_middle_end_prepare_gs(struct llvm_middle_end *fpme)
{
struct draw_context *draw = fpme->draw;
+ struct draw_llvm *llvm = fpme->llvm;
struct draw_geometry_shader *gs = draw->gs.geometry_shader;
struct draw_gs_llvm_variant_key *key;
struct draw_gs_llvm_variant *variant = NULL;
char store[DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE];
unsigned i;
- key = draw_gs_llvm_make_variant_key(fpme->llvm, store);
+ key = draw_gs_llvm_make_variant_key(llvm, store);
/* Search shader's list of variants for the key */
li = first_elem(&shader->variants);
if (variant) {
/* found the variant, move to head of global list (for LRU) */
- move_to_head(&fpme->llvm->gs_variants_list,
- &variant->list_item_global);
+ move_to_head(&llvm->gs_variants_list, &variant->list_item_global);
}
else {
/* Need to create new variant */
/* First check if we've created too many variants. If so, free
- * 25% of the LRU to avoid using too much memory.
+ * 3.125% of the LRU to avoid using too much memory.
*/
- if (fpme->llvm->nr_gs_variants >= DRAW_MAX_SHADER_VARIANTS) {
+ if (llvm->nr_gs_variants >= DRAW_MAX_SHADER_VARIANTS) {
+ if (gallivm_debug & GALLIVM_DEBUG_PERF) {
+ debug_printf("Evicting GS: %u gs variants,\t%u total variants\n",
+ shader->variants_cached, llvm->nr_gs_variants);
+ }
+
/*
* XXX: should we flush here ?
*/
- for (i = 0; i < DRAW_MAX_SHADER_VARIANTS / 4; i++) {
+ for (i = 0; i < DRAW_MAX_SHADER_VARIANTS / 32; i++) {
struct draw_gs_llvm_variant_list_item *item;
- if (is_empty_list(&fpme->llvm->gs_variants_list)) {
+ if (is_empty_list(&llvm->gs_variants_list)) {
break;
}
- item = last_elem(&fpme->llvm->gs_variants_list);
+ item = last_elem(&llvm->gs_variants_list);
assert(item);
assert(item->base);
draw_gs_llvm_destroy_variant(item->base);
}
}
- variant = draw_gs_llvm_create_variant(fpme->llvm, gs->info.num_outputs, key);
+ variant = draw_gs_llvm_create_variant(llvm, gs->info.num_outputs, key);
if (variant) {
insert_at_head(&shader->variants, &variant->list_item_local);
- insert_at_head(&fpme->llvm->gs_variants_list,
+ insert_at_head(&llvm->gs_variants_list,
&variant->list_item_global);
- fpme->llvm->nr_gs_variants++;
+ llvm->nr_gs_variants++;
shader->variants_cached++;
}
}
{
struct llvm_middle_end *fpme = llvm_middle_end(middle);
struct draw_context *draw = fpme->draw;
+ struct draw_llvm *llvm = fpme->llvm;
struct draw_vertex_shader *vs = draw->vs.vertex_shader;
struct draw_geometry_shader *gs = draw->gs.geometry_shader;
const unsigned out_prim = gs ? gs->output_primitive :
char store[DRAW_LLVM_MAX_VARIANT_KEY_SIZE];
unsigned i;
- key = draw_llvm_make_variant_key(fpme->llvm, store);
+ key = draw_llvm_make_variant_key(llvm, store);
/* Search shader's list of variants for the key */
li = first_elem(&shader->variants);
if (variant) {
/* found the variant, move to head of global list (for LRU) */
- move_to_head(&fpme->llvm->vs_variants_list,
- &variant->list_item_global);
+ move_to_head(&llvm->vs_variants_list, &variant->list_item_global);
}
else {
/* Need to create new variant */
/* First check if we've created too many variants. If so, free
- * 25% of the LRU to avoid using too much memory.
+ * 3.125% of the LRU to avoid using too much memory.
*/
- if (fpme->llvm->nr_variants >= DRAW_MAX_SHADER_VARIANTS) {
+ if (llvm->nr_variants >= DRAW_MAX_SHADER_VARIANTS) {
+ if (gallivm_debug & GALLIVM_DEBUG_PERF) {
+ debug_printf("Evicting VS: %u vs variants,\t%u total variants\n",
+ shader->variants_cached, llvm->nr_variants);
+ }
+
/*
* XXX: should we flush here ?
*/
- for (i = 0; i < DRAW_MAX_SHADER_VARIANTS / 4; i++) {
+ for (i = 0; i < DRAW_MAX_SHADER_VARIANTS / 32; i++) {
struct draw_llvm_variant_list_item *item;
- if (is_empty_list(&fpme->llvm->vs_variants_list)) {
+ if (is_empty_list(&llvm->vs_variants_list)) {
break;
}
- item = last_elem(&fpme->llvm->vs_variants_list);
+ item = last_elem(&llvm->vs_variants_list);
assert(item);
assert(item->base);
draw_llvm_destroy_variant(item->base);
}
}
- variant = draw_llvm_create_variant(fpme->llvm, nr, key);
+ variant = draw_llvm_create_variant(llvm, nr, key);
if (variant) {
insert_at_head(&shader->variants, &variant->list_item_local);
- insert_at_head(&fpme->llvm->vs_variants_list,
+ insert_at_head(&llvm->vs_variants_list,
&variant->list_item_global);
- fpme->llvm->nr_variants++;
+ llvm->nr_variants++;
shader->variants_cached++;
}
}
llvmpipe_remove_shader_variant(struct llvmpipe_context *lp,
struct lp_fragment_shader_variant *variant)
{
- if (gallivm_debug & GALLIVM_DEBUG_IR) {
- debug_printf("llvmpipe: del fs #%u var #%u v created #%u v cached"
- " #%u v total cached #%u\n",
- variant->shader->no,
- variant->no,
+ if ((LP_DEBUG & DEBUG_FS) || (gallivm_debug & GALLIVM_DEBUG_IR)) {
+ debug_printf("llvmpipe: del fs #%u var %u v created %u v cached %u "
+ "v total cached %u inst %u total inst %u\n",
+ variant->shader->no, variant->no,
variant->shader->variants_created,
variant->shader->variants_cached,
- lp->nr_fs_variants);
+ lp->nr_fs_variants, variant->nr_instrs, lp->nr_fs_instrs);
}
gallivm_destroy(variant->gallivm);
unsigned i;
unsigned variants_to_cull;
- if (0) {
+ if (LP_DEBUG & DEBUG_FS) {
debug_printf("%u variants,\t%u instrs,\t%u instrs/variant\n",
lp->nr_fs_variants,
lp->nr_fs_instrs,
}
/* First, check if we've exceeded the max number of shader variants.
- * If so, free 25% of them (the least recently used ones).
+ * If so, free 6.25% of them (the least recently used ones).
*/
- variants_to_cull = lp->nr_fs_variants >= LP_MAX_SHADER_VARIANTS ? LP_MAX_SHADER_VARIANTS / 4 : 0;
+ variants_to_cull = lp->nr_fs_variants >= LP_MAX_SHADER_VARIANTS ? LP_MAX_SHADER_VARIANTS / 16 : 0;
if (variants_to_cull ||
lp->nr_fs_instrs >= LP_MAX_SHADER_INSTRUCTIONS) {
struct pipe_context *pipe = &lp->pipe;
+ if (gallivm_debug & GALLIVM_DEBUG_PERF) {
+ debug_printf("Evicting FS: %u fs variants,\t%u total variants,"
+ "\t%u instrs,\t%u instrs/variant\n",
+ shader->variants_cached,
+ lp->nr_fs_variants, lp->nr_fs_instrs,
+ lp->nr_fs_instrs / lp->nr_fs_variants);
+ }
+
/*
* XXX: we need to flush the context until we have some sort of
* reference counting in fragment shaders as they may still be binned