1 /**************************************************************************
3 * Copyright 2019 Red Hat.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **************************************************************************/
25 #include "util/u_memory.h"
26 #include "util/simple_list.h"
28 #include "tgsi/tgsi_parse.h"
29 #include "gallivm/lp_bld_debug.h"
30 #include "lp_state_cs.h"
31 #include "lp_context.h"
36 llvmpipe_create_compute_state(struct pipe_context
*pipe
,
37 const struct pipe_compute_state
*templ
)
39 struct lp_compute_shader
*shader
;
41 shader
= CALLOC_STRUCT(lp_compute_shader
);
45 assert(templ
->ir_type
== PIPE_SHADER_IR_TGSI
);
46 shader
->base
.tokens
= tgsi_dup_tokens(templ
->prog
);
48 lp_build_tgsi_info(shader
->base
.tokens
, &shader
->info
);
49 make_empty_list(&shader
->variants
);
55 llvmpipe_bind_compute_state(struct pipe_context
*pipe
,
58 struct llvmpipe_context
*llvmpipe
= llvmpipe_context(pipe
);
60 if (llvmpipe
->cs
== cs
)
63 llvmpipe
->cs
= (struct lp_compute_shader
*)cs
;
64 llvmpipe
->cs_dirty
|= LP_CSNEW_CS
;
68 * Remove shader variant from two lists: the shader's variant list
69 * and the context's variant list.
72 llvmpipe_remove_cs_shader_variant(struct llvmpipe_context
*lp
,
73 struct lp_compute_shader_variant
*variant
)
75 if ((LP_DEBUG
& DEBUG_CS
) || (gallivm_debug
& GALLIVM_DEBUG_IR
)) {
76 debug_printf("llvmpipe: del cs #%u var %u v created %u v cached %u "
77 "v total cached %u inst %u total inst %u\n",
78 variant
->shader
->no
, variant
->no
,
79 variant
->shader
->variants_created
,
80 variant
->shader
->variants_cached
,
81 lp
->nr_cs_variants
, variant
->nr_instrs
, lp
->nr_cs_instrs
);
84 gallivm_destroy(variant
->gallivm
);
86 /* remove from shader's list */
87 remove_from_list(&variant
->list_item_local
);
88 variant
->shader
->variants_cached
--;
90 /* remove from context's list */
91 remove_from_list(&variant
->list_item_global
);
93 lp
->nr_fs_instrs
-= variant
->nr_instrs
;
99 llvmpipe_delete_compute_state(struct pipe_context
*pipe
,
102 struct llvmpipe_context
*llvmpipe
= llvmpipe_context(pipe
);
103 struct lp_compute_shader
*shader
= cs
;
104 struct lp_cs_variant_list_item
*li
;
106 /* Delete all the variants */
107 li
= first_elem(&shader
->variants
);
108 while(!at_end(&shader
->variants
, li
)) {
109 struct lp_cs_variant_list_item
*next
= next_elem(li
);
110 llvmpipe_remove_cs_shader_variant(llvmpipe
, li
->base
);
113 tgsi_free_tokens(shader
->base
.tokens
);
118 llvmpipe_init_compute_funcs(struct llvmpipe_context
*llvmpipe
)
120 llvmpipe
->pipe
.create_compute_state
= llvmpipe_create_compute_state
;
121 llvmpipe
->pipe
.bind_compute_state
= llvmpipe_bind_compute_state
;
122 llvmpipe
->pipe
.delete_compute_state
= llvmpipe_delete_compute_state
;
126 lp_csctx_destroy(struct lp_cs_context
*csctx
)
131 struct lp_cs_context
*lp_csctx_create(struct pipe_context
*pipe
)
133 struct lp_cs_context
*csctx
;
135 csctx
= CALLOC_STRUCT(lp_cs_context
);