2 * Copyright © 2013 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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "util/ralloc.h"
26 #include "blorp_priv.h"
27 #include "brw_meta_util.h"
28 #include "brw_defines.h"
30 #include "nir_builder.h"
32 #define FILE_DEBUG_FLAG DEBUG_BLORP
34 struct brw_blorp_const_color_prog_key
36 bool use_simd16_replicated_data
;
41 brw_blorp_params_get_clear_kernel(struct blorp_context
*blorp
,
42 struct brw_blorp_params
*params
,
43 bool use_replicated_data
)
45 struct brw_blorp_const_color_prog_key blorp_key
;
46 memset(&blorp_key
, 0, sizeof(blorp_key
));
47 blorp_key
.use_simd16_replicated_data
= use_replicated_data
;
49 if (blorp
->lookup_shader(blorp
, &blorp_key
, sizeof(blorp_key
),
50 ¶ms
->wm_prog_kernel
, ¶ms
->wm_prog_data
))
53 void *mem_ctx
= ralloc_context(NULL
);
56 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
57 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, "BLORP-clear");
59 nir_variable
*v_color
= nir_variable_create(b
.shader
, nir_var_shader_in
,
60 glsl_vec4_type(), "v_color");
61 v_color
->data
.location
= VARYING_SLOT_VAR0
;
62 v_color
->data
.interpolation
= INTERP_MODE_FLAT
;
64 nir_variable
*frag_color
= nir_variable_create(b
.shader
, nir_var_shader_out
,
67 frag_color
->data
.location
= FRAG_RESULT_COLOR
;
69 nir_copy_var(&b
, frag_color
, v_color
);
71 struct brw_wm_prog_key wm_key
;
72 brw_blorp_init_wm_prog_key(&wm_key
);
74 struct brw_blorp_prog_data prog_data
;
75 unsigned program_size
;
76 const unsigned *program
=
77 brw_blorp_compile_nir_shader(blorp
, b
.shader
, &wm_key
, use_replicated_data
,
78 &prog_data
, &program_size
);
80 blorp
->upload_shader(blorp
, &blorp_key
, sizeof(blorp_key
),
81 program
, program_size
,
82 &prog_data
, sizeof(prog_data
),
83 ¶ms
->wm_prog_kernel
, ¶ms
->wm_prog_data
);
89 blorp_fast_clear(struct blorp_batch
*batch
,
90 const struct brw_blorp_surf
*surf
,
91 uint32_t level
, uint32_t layer
,
92 uint32_t x0
, uint32_t y0
, uint32_t x1
, uint32_t y1
)
94 struct brw_blorp_params params
;
95 brw_blorp_params_init(¶ms
);
102 memset(¶ms
.wm_inputs
, 0xff, 4*sizeof(float));
103 params
.fast_clear_op
= BLORP_FAST_CLEAR_OP_CLEAR
;
105 brw_get_fast_clear_rect(batch
->blorp
->isl_dev
, surf
->aux_surf
,
106 ¶ms
.x0
, ¶ms
.y0
, ¶ms
.x1
, ¶ms
.y1
);
108 brw_blorp_params_get_clear_kernel(batch
->blorp
, ¶ms
, true);
110 brw_blorp_surface_info_init(batch
->blorp
, ¶ms
.dst
, surf
, level
, layer
,
111 surf
->surf
->format
, true);
113 batch
->blorp
->exec(batch
, ¶ms
);
118 blorp_clear(struct blorp_batch
*batch
,
119 const struct brw_blorp_surf
*surf
,
120 uint32_t level
, uint32_t layer
,
121 uint32_t x0
, uint32_t y0
, uint32_t x1
, uint32_t y1
,
122 enum isl_format format
, union isl_color_value clear_color
,
123 bool color_write_disable
[4])
125 struct brw_blorp_params params
;
126 brw_blorp_params_init(¶ms
);
133 memcpy(¶ms
.wm_inputs
, clear_color
.f32
, sizeof(float) * 4);
135 bool use_simd16_replicated_data
= true;
137 /* From the SNB PRM (Vol4_Part1):
139 * "Replicated data (Message Type = 111) is only supported when
140 * accessing tiled memory. Using this Message Type to access linear
141 * (untiled) memory is UNDEFINED."
143 if (surf
->surf
->tiling
== ISL_TILING_LINEAR
)
144 use_simd16_replicated_data
= false;
146 /* Constant color writes ignore everyting in blend and color calculator
147 * state. This is not documented.
149 for (unsigned i
= 0; i
< 4; i
++) {
150 params
.color_write_disable
[i
] = color_write_disable
[i
];
151 if (color_write_disable
[i
])
152 use_simd16_replicated_data
= false;
155 brw_blorp_params_get_clear_kernel(batch
->blorp
, ¶ms
,
156 use_simd16_replicated_data
);
158 brw_blorp_surface_info_init(batch
->blorp
, ¶ms
.dst
, surf
, level
, layer
,
161 batch
->blorp
->exec(batch
, ¶ms
);
165 brw_blorp_ccs_resolve(struct blorp_batch
*batch
,
166 struct brw_blorp_surf
*surf
, enum isl_format format
)
168 struct brw_blorp_params params
;
169 brw_blorp_params_init(¶ms
);
171 brw_blorp_surface_info_init(batch
->blorp
, ¶ms
.dst
, surf
,
172 0 /* level */, 0 /* layer */, format
, true);
174 brw_get_ccs_resolve_rect(batch
->blorp
->isl_dev
, ¶ms
.dst
.aux_surf
,
175 ¶ms
.x0
, ¶ms
.y0
,
176 ¶ms
.x1
, ¶ms
.y1
);
178 if (batch
->blorp
->isl_dev
->info
->gen
>= 9) {
179 if (params
.dst
.aux_usage
== ISL_AUX_USAGE_CCS_E
)
180 params
.fast_clear_op
= BLORP_FAST_CLEAR_OP_RESOLVE_FULL
;
182 params
.fast_clear_op
= BLORP_FAST_CLEAR_OP_RESOLVE_PARTIAL
;
184 /* Broadwell and earlier do not have a partial resolve */
185 params
.fast_clear_op
= BLORP_FAST_CLEAR_OP_RESOLVE_FULL
;
188 /* Note: there is no need to initialize push constants because it doesn't
189 * matter what data gets dispatched to the render target. However, we must
190 * ensure that the fragment shader delivers the data using the "replicated
194 brw_blorp_params_get_clear_kernel(batch
->blorp
, ¶ms
, true);
196 batch
->blorp
->exec(batch
, ¶ms
);