2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "pipe/p_defines.h"
26 #include "pipe/p_state.h"
27 #include "pipe/p_context.h"
28 #include "pipe/p_screen.h"
29 #include "util/u_atomic.h"
30 #include "compiler/nir/nir.h"
31 #include "compiler/nir/nir_builder.h"
32 #include "intel/compiler/brw_compiler.h"
33 #include "intel/compiler/brw_nir.h"
34 #include "iris_context.h"
37 get_new_program_id(struct iris_screen
*screen
)
39 return p_atomic_inc_return(&screen
->program_id
);
42 struct iris_uncompiled_shader
{
43 struct pipe_shader_state base
;
48 iris_create_shader_state(struct pipe_context
*ctx
,
49 const struct pipe_shader_state
*state
)
51 struct iris_context
*ice
= (struct iris_context
*)ctx
;
52 struct iris_screen
*screen
= (struct iris_screen
*)ctx
->screen
;
54 assert(state
->type
== PIPE_SHADER_IR_NIR
);
56 nir_shader
*nir
= state
->ir
.nir
;
58 struct iris_uncompiled_shader
*cso
=
59 calloc(1, sizeof(struct iris_uncompiled_shader
));
63 nir
= brw_preprocess_nir(screen
->compiler
, nir
);
65 cso
->program_id
= get_new_program_id(screen
);
66 cso
->base
.type
= PIPE_SHADER_IR_NIR
;
67 cso
->base
.ir
.nir
= nir
;
73 iris_delete_shader_state(struct pipe_context
*ctx
, void *hwcso
)
75 struct iris_uncompiled_shader
*cso
= hwcso
;
77 ralloc_free(cso
->base
.ir
.nir
);
82 iris_init_program_functions(struct pipe_context
*ctx
)
84 ctx
->create_vs_state
= iris_create_shader_state
;
85 ctx
->create_tcs_state
= iris_create_shader_state
;
86 ctx
->create_tes_state
= iris_create_shader_state
;
87 ctx
->create_gs_state
= iris_create_shader_state
;
88 ctx
->create_fs_state
= iris_create_shader_state
;
90 ctx
->delete_vs_state
= iris_delete_shader_state
;
91 ctx
->delete_tcs_state
= iris_delete_shader_state
;
92 ctx
->delete_tes_state
= iris_delete_shader_state
;
93 ctx
->delete_gs_state
= iris_delete_shader_state
;
94 ctx
->delete_fs_state
= iris_delete_shader_state
;