blob: 39b7b968662d40f7bc77bd169d4567931d079ab3 [file] [log] [blame]
Chad Versace16b2a482015-11-03 14:19:45 -08001/*
2 * Copyright © 2015 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24#include "anv_meta.h"
25#include "anv_meta_clear.h"
Chad Versace16b2a482015-11-03 14:19:45 -080026#include "anv_private.h"
Jason Ekstranda33fcc02015-12-29 13:47:37 -080027#include "glsl/nir/nir_builder.h"
Chad Versace16b2a482015-11-03 14:19:45 -080028
Chad Versacea9a30712015-11-03 14:55:58 -080029/** Vertex attributes for color clears. */
30struct color_clear_vattrs {
Chad Versace16b2a482015-11-03 14:19:45 -080031 struct anv_vue_header vue_header;
Chad Versacea9a30712015-11-03 14:55:58 -080032 float position[2]; /**< 3DPRIM_RECTLIST */
Chad Versace16b2a482015-11-03 14:19:45 -080033 VkClearColorValue color;
34};
35
Chad Versace16119ad2015-11-04 17:00:01 -080036/** Vertex attributes for depthstencil clears. */
37struct depthstencil_clear_vattrs {
Chad Versacea9a30712015-11-03 14:55:58 -080038 struct anv_vue_header vue_header;
39 float position[2]; /*<< 3DPRIM_RECTLIST */
40};
41
Chad Versace16b2a482015-11-03 14:19:45 -080042static void
Chad Versacea9a30712015-11-03 14:55:58 -080043meta_clear_begin(struct anv_meta_saved_state *saved_state,
44 struct anv_cmd_buffer *cmd_buffer)
Chad Versace16b2a482015-11-03 14:19:45 -080045{
Chad Versacea9a30712015-11-03 14:55:58 -080046 anv_meta_save(saved_state, cmd_buffer,
47 (1 << VK_DYNAMIC_STATE_VIEWPORT) |
Chad Versace16119ad2015-11-04 17:00:01 -080048 (1 << VK_DYNAMIC_STATE_SCISSOR) |
49 (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE));
Chad Versace16b2a482015-11-03 14:19:45 -080050
Chad Versace16b2a482015-11-03 14:19:45 -080051 cmd_buffer->state.dynamic.viewport.count = 0;
Chad Versacea9a30712015-11-03 14:55:58 -080052 cmd_buffer->state.dynamic.scissor.count = 0;
Chad Versace16b2a482015-11-03 14:19:45 -080053}
54
Chad Versacea9a30712015-11-03 14:55:58 -080055static void
56meta_clear_end(struct anv_meta_saved_state *saved_state,
57 struct anv_cmd_buffer *cmd_buffer)
Chad Versace16b2a482015-11-03 14:19:45 -080058{
Chad Versacea9a30712015-11-03 14:55:58 -080059 anv_meta_restore(saved_state, cmd_buffer);
Chad Versace16b2a482015-11-03 14:19:45 -080060}
61
Chad Versacea9a30712015-11-03 14:55:58 -080062static void
63build_color_shaders(struct nir_shader **out_vs,
Chad Versace0679bef2016-01-13 16:29:45 -080064 struct nir_shader **out_fs,
65 uint32_t frag_output)
Chad Versace16b2a482015-11-03 14:19:45 -080066{
Chad Versacea9a30712015-11-03 14:55:58 -080067 nir_builder vs_b;
68 nir_builder fs_b;
Chad Versace16b2a482015-11-03 14:19:45 -080069
Jason Ekstranda33fcc02015-12-29 13:47:37 -080070 nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL);
71 nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL);
Chad Versacea9a30712015-11-03 14:55:58 -080072
Chad Versace13610c02016-01-13 18:09:01 -080073 vs_b.shader->info.name = ralloc_strdup(vs_b.shader, "meta_clear_color_vs");
74 fs_b.shader->info.name = ralloc_strdup(fs_b.shader, "meta_clear_color_fs");
75
Chad Versacea9a30712015-11-03 14:55:58 -080076 const struct glsl_type *position_type = glsl_vec4_type();
Chad Versace16b2a482015-11-03 14:19:45 -080077 const struct glsl_type *color_type = glsl_vec4_type();
78
Chad Versacea9a30712015-11-03 14:55:58 -080079 nir_variable *vs_in_pos =
80 nir_variable_create(vs_b.shader, nir_var_shader_in, position_type,
81 "a_position");
82 vs_in_pos->data.location = VERT_ATTRIB_GENERIC0;
Chad Versace16b2a482015-11-03 14:19:45 -080083
Chad Versacea9a30712015-11-03 14:55:58 -080084 nir_variable *vs_out_pos =
85 nir_variable_create(vs_b.shader, nir_var_shader_out, position_type,
86 "gl_Position");
87 vs_out_pos->data.location = VARYING_SLOT_POS;
Chad Versace16b2a482015-11-03 14:19:45 -080088
Chad Versacea9a30712015-11-03 14:55:58 -080089 nir_variable *vs_in_color =
90 nir_variable_create(vs_b.shader, nir_var_shader_in, color_type,
91 "a_color");
92 vs_in_color->data.location = VERT_ATTRIB_GENERIC1;
93
94 nir_variable *vs_out_color =
95 nir_variable_create(vs_b.shader, nir_var_shader_out, color_type,
96 "v_color");
97 vs_out_color->data.location = VARYING_SLOT_VAR0;
98 vs_out_color->data.interpolation = INTERP_QUALIFIER_FLAT;
99
100 nir_variable *fs_in_color =
101 nir_variable_create(fs_b.shader, nir_var_shader_in, color_type,
102 "v_color");
103 fs_in_color->data.location = vs_out_color->data.location;
104 fs_in_color->data.interpolation = vs_out_color->data.interpolation;
105
106 nir_variable *fs_out_color =
107 nir_variable_create(fs_b.shader, nir_var_shader_out, color_type,
108 "f_color");
Chad Versace0679bef2016-01-13 16:29:45 -0800109 fs_out_color->data.location = FRAG_RESULT_DATA0 + frag_output;
Chad Versacea9a30712015-11-03 14:55:58 -0800110
111 nir_copy_var(&vs_b, vs_out_pos, vs_in_pos);
112 nir_copy_var(&vs_b, vs_out_color, vs_in_color);
113 nir_copy_var(&fs_b, fs_out_color, fs_in_color);
114
115 *out_vs = vs_b.shader;
116 *out_fs = fs_b.shader;
Chad Versace16b2a482015-11-03 14:19:45 -0800117}
118
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800119static VkResult
Chad Versacea9a30712015-11-03 14:55:58 -0800120create_pipeline(struct anv_device *device,
121 struct nir_shader *vs_nir,
122 struct nir_shader *fs_nir,
123 const VkPipelineVertexInputStateCreateInfo *vi_state,
124 const VkPipelineDepthStencilStateCreateInfo *ds_state,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800125 const VkPipelineColorBlendStateCreateInfo *cb_state,
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800126 const VkAllocationCallbacks *alloc,
Chad Versace0679bef2016-01-13 16:29:45 -0800127 bool use_repclear,
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800128 struct anv_pipeline **pipeline)
Chad Versace16b2a482015-11-03 14:19:45 -0800129{
Chad Versacea9a30712015-11-03 14:55:58 -0800130 VkDevice device_h = anv_device_to_handle(device);
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800131 VkResult result;
Chad Versace16b2a482015-11-03 14:19:45 -0800132
Chad Versacea9a30712015-11-03 14:55:58 -0800133 struct anv_shader_module vs_m = { .nir = vs_nir };
134 struct anv_shader_module fs_m = { .nir = fs_nir };
Chad Versace16b2a482015-11-03 14:19:45 -0800135
Chad Versacea9a30712015-11-03 14:55:58 -0800136 VkPipeline pipeline_h;
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800137 result = anv_graphics_pipeline_create(device_h,
Kristian Høgsberg Kristensen30521fb2016-01-05 12:00:54 -0800138 VK_NULL_HANDLE,
Chad Versace16b2a482015-11-03 14:19:45 -0800139 &(VkGraphicsPipelineCreateInfo) {
140 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
Chad Versace16b2a482015-11-03 14:19:45 -0800141 .stageCount = 2,
142 .pStages = (VkPipelineShaderStageCreateInfo[]) {
143 {
144 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
Jason Ekstranda5f19f62015-12-02 16:08:13 -0800145 .stage = VK_SHADER_STAGE_VERTEX_BIT,
Jason Ekstrande10dc002015-12-02 14:35:07 -0800146 .module = anv_shader_module_to_handle(&vs_m),
147 .pName = "main",
Chad Versacea9a30712015-11-03 14:55:58 -0800148 },
149 {
Chad Versace16b2a482015-11-03 14:19:45 -0800150 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
Jason Ekstranda5f19f62015-12-02 16:08:13 -0800151 .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
Jason Ekstrande10dc002015-12-02 14:35:07 -0800152 .module = anv_shader_module_to_handle(&fs_m),
153 .pName = "main",
Chad Versacea9a30712015-11-03 14:55:58 -0800154 },
Chad Versace16b2a482015-11-03 14:19:45 -0800155 },
Chad Versacea9a30712015-11-03 14:55:58 -0800156 .pVertexInputState = vi_state,
Chad Versace16b2a482015-11-03 14:19:45 -0800157 .pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) {
158 .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
159 .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
160 .primitiveRestartEnable = false,
161 },
162 .pViewportState = &(VkPipelineViewportStateCreateInfo) {
163 .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
164 .viewportCount = 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800165 .pViewports = NULL, /* dynamic */
Chad Versace16b2a482015-11-03 14:19:45 -0800166 .scissorCount = 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800167 .pScissors = NULL, /* dynamic */
Chad Versace16b2a482015-11-03 14:19:45 -0800168 },
Jason Ekstrand7f228402015-11-30 18:05:00 -0800169 .pRasterizationState = &(VkPipelineRasterizationStateCreateInfo) {
170 .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
Chad Versace16b2a482015-11-03 14:19:45 -0800171 .rasterizerDiscardEnable = false,
Jason Ekstrand9b1cb8f2015-11-30 13:28:09 -0800172 .polygonMode = VK_POLYGON_MODE_FILL,
Chad Versace16b2a482015-11-03 14:19:45 -0800173 .cullMode = VK_CULL_MODE_NONE,
Jason Ekstrand9b1cb8f2015-11-30 13:28:09 -0800174 .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
Chad Versacea9a30712015-11-03 14:55:58 -0800175 .depthBiasEnable = false,
Chad Versace16b2a482015-11-03 14:19:45 -0800176 },
177 .pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) {
178 .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
Jason Ekstrand7f228402015-11-30 18:05:00 -0800179 .rasterizationSamples = 1, /* FINISHME: Multisampling */
Chad Versace16b2a482015-11-03 14:19:45 -0800180 .sampleShadingEnable = false,
181 .pSampleMask = (VkSampleMask[]) { UINT32_MAX },
Jason Ekstrand9fa6e322015-11-30 17:20:49 -0800182 .alphaToCoverageEnable = false,
183 .alphaToOneEnable = false,
Chad Versace16b2a482015-11-03 14:19:45 -0800184 },
Chad Versacea9a30712015-11-03 14:55:58 -0800185 .pDepthStencilState = ds_state,
186 .pColorBlendState = cb_state,
Chad Versace16b2a482015-11-03 14:19:45 -0800187 .pDynamicState = &(VkPipelineDynamicStateCreateInfo) {
Chad Versacea9a30712015-11-03 14:55:58 -0800188 /* The meta clear pipeline declares all state as dynamic.
189 * As a consequence, vkCmdBindPipeline writes no dynamic state
190 * to the cmd buffer. Therefore, at the end of the meta clear,
191 * we need only restore dynamic state was vkCmdSet.
192 */
Chad Versace16b2a482015-11-03 14:19:45 -0800193 .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
194 .dynamicStateCount = 9,
195 .pDynamicStates = (VkDynamicState[]) {
196 VK_DYNAMIC_STATE_VIEWPORT,
197 VK_DYNAMIC_STATE_SCISSOR,
198 VK_DYNAMIC_STATE_LINE_WIDTH,
199 VK_DYNAMIC_STATE_DEPTH_BIAS,
200 VK_DYNAMIC_STATE_BLEND_CONSTANTS,
201 VK_DYNAMIC_STATE_DEPTH_BOUNDS,
202 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
203 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK,
204 VK_DYNAMIC_STATE_STENCIL_REFERENCE,
205 },
206 },
207 .flags = 0,
208 .renderPass = anv_render_pass_to_handle(&anv_meta_dummy_renderpass),
209 .subpass = 0,
210 },
211 &(struct anv_graphics_pipeline_create_info) {
Chad Versace2997b0d2016-01-13 18:24:18 -0800212 .color_attachment_count = MAX_RTS,
Chad Versace0679bef2016-01-13 16:29:45 -0800213 .use_repclear = use_repclear,
Chad Versace16b2a482015-11-03 14:19:45 -0800214 .disable_viewport = true,
215 .disable_vs = true,
216 .use_rectlist = true
217 },
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800218 alloc,
Chad Versacea9a30712015-11-03 14:55:58 -0800219 &pipeline_h);
Chad Versace16b2a482015-11-03 14:19:45 -0800220
Chad Versacea9a30712015-11-03 14:55:58 -0800221 ralloc_free(vs_nir);
222 ralloc_free(fs_nir);
223
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800224 *pipeline = anv_pipeline_from_handle(pipeline_h);
225
226 return result;
Chad Versacea9a30712015-11-03 14:55:58 -0800227}
228
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800229static VkResult
Chad Versace0679bef2016-01-13 16:29:45 -0800230create_color_pipeline(struct anv_device *device, uint32_t frag_output,
231 struct anv_pipeline **pipeline)
Chad Versacea9a30712015-11-03 14:55:58 -0800232{
233 struct nir_shader *vs_nir;
234 struct nir_shader *fs_nir;
Chad Versace0679bef2016-01-13 16:29:45 -0800235 build_color_shaders(&vs_nir, &fs_nir, frag_output);
Chad Versacea9a30712015-11-03 14:55:58 -0800236
237 const VkPipelineVertexInputStateCreateInfo vi_state = {
238 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
Jason Ekstrande673d642015-11-30 17:00:30 -0800239 .vertexBindingDescriptionCount = 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800240 .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) {
241 {
242 .binding = 0,
Jason Ekstrande673d642015-11-30 17:00:30 -0800243 .stride = sizeof(struct color_clear_vattrs),
Jason Ekstrand9b1cb8f2015-11-30 13:28:09 -0800244 .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
Chad Versacea9a30712015-11-03 14:55:58 -0800245 },
246 },
Jason Ekstrande673d642015-11-30 17:00:30 -0800247 .vertexAttributeDescriptionCount = 3,
Chad Versacea9a30712015-11-03 14:55:58 -0800248 .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) {
249 {
250 /* VUE Header */
251 .location = 0,
252 .binding = 0,
253 .format = VK_FORMAT_R32G32B32A32_UINT,
Jason Ekstrande673d642015-11-30 17:00:30 -0800254 .offset = offsetof(struct color_clear_vattrs, vue_header),
Chad Versacea9a30712015-11-03 14:55:58 -0800255 },
256 {
257 /* Position */
258 .location = 1,
259 .binding = 0,
260 .format = VK_FORMAT_R32G32_SFLOAT,
Jason Ekstrande673d642015-11-30 17:00:30 -0800261 .offset = offsetof(struct color_clear_vattrs, position),
Chad Versacea9a30712015-11-03 14:55:58 -0800262 },
263 {
264 /* Color */
265 .location = 2,
266 .binding = 0,
267 .format = VK_FORMAT_R32G32B32A32_SFLOAT,
Jason Ekstrande673d642015-11-30 17:00:30 -0800268 .offset = offsetof(struct color_clear_vattrs, color),
Chad Versacea9a30712015-11-03 14:55:58 -0800269 },
270 },
271 };
272
273 const VkPipelineDepthStencilStateCreateInfo ds_state = {
274 .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
275 .depthTestEnable = false,
276 .depthWriteEnable = false,
277 .depthBoundsTestEnable = false,
278 .stencilTestEnable = false,
279 };
280
281 const VkPipelineColorBlendStateCreateInfo cb_state = {
282 .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
Chad Versacea9a30712015-11-03 14:55:58 -0800283 .logicOpEnable = false,
284 .attachmentCount = 1,
285 .pAttachments = (VkPipelineColorBlendAttachmentState []) {
286 {
287 .blendEnable = false,
Jason Ekstrand4cf0b572015-11-30 18:12:55 -0800288 .colorWriteMask = VK_COLOR_COMPONENT_A_BIT |
289 VK_COLOR_COMPONENT_R_BIT |
290 VK_COLOR_COMPONENT_G_BIT |
291 VK_COLOR_COMPONENT_B_BIT,
Chad Versacea9a30712015-11-03 14:55:58 -0800292 },
293 },
294 };
295
Chad Versace0679bef2016-01-13 16:29:45 -0800296 /* Disable repclear because we do not want the compiler to replace the
297 * shader. We need the shader to write to the specified color attachment,
298 * but the repclear shader writes to all color attachments.
299 */
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800300 return
Chad Versacea9a30712015-11-03 14:55:58 -0800301 create_pipeline(device, vs_nir, fs_nir, &vi_state, &ds_state,
Chad Versace0679bef2016-01-13 16:29:45 -0800302 &cb_state, NULL, /*use_repclear*/ false,
303 pipeline);
304}
305
306static VkResult
307init_color_pipelines(struct anv_device *device)
308{
309 VkResult result;
310 struct anv_pipeline **pipelines = device->meta_state.clear.color_pipelines;
311 uint32_t n = ARRAY_SIZE(device->meta_state.clear.color_pipelines);
312
313 zero(device->meta_state.clear.color_pipelines);
314
315 for (uint32_t i = 0; i < n; ++i) {
316 result = create_color_pipeline(device, i, &pipelines[i]);
317 if (result < 0)
318 goto fail;
319 }
320
321 return VK_SUCCESS;
322
323fail:
324 for (uint32_t i = 0; i < n; ++i) {
325 if (pipelines[i] == NULL)
326 break;
327
328 anv_DestroyPipeline(anv_device_to_handle(device),
329 anv_pipeline_to_handle(pipelines[i]),
330 NULL);
331 }
332
333 return result;
Chad Versacea9a30712015-11-03 14:55:58 -0800334}
335
336static void
Chad Versacef2700d62016-01-13 14:09:36 -0800337emit_color_clear(struct anv_cmd_buffer *cmd_buffer,
Chad Versacedeb8dd82016-01-13 14:47:51 -0800338 const VkClearAttachment *clear_att)
Chad Versacea9a30712015-11-03 14:55:58 -0800339{
340 struct anv_device *device = cmd_buffer->device;
Chad Versacedeb8dd82016-01-13 14:47:51 -0800341 const struct anv_subpass *subpass = cmd_buffer->state.subpass;
Chad Versacea9a30712015-11-03 14:55:58 -0800342 const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
Chad Versacedeb8dd82016-01-13 14:47:51 -0800343 VkClearColorValue clear_value = clear_att->clearValue.color;
344 struct anv_pipeline *pipeline =
345 device->meta_state.clear.color_pipelines[clear_att->colorAttachment];
346
347 VkCommandBuffer cmd_buffer_h = anv_cmd_buffer_to_handle(cmd_buffer);
Chad Versace0679bef2016-01-13 16:29:45 -0800348 VkPipeline pipeline_h = anv_pipeline_to_handle(pipeline);
Chad Versacea9a30712015-11-03 14:55:58 -0800349
Chad Versacedeb8dd82016-01-13 14:47:51 -0800350 assert(clear_att->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
351 assert(clear_att->colorAttachment < subpass->color_count);
352
Chad Versacea9a30712015-11-03 14:55:58 -0800353 const struct color_clear_vattrs vertex_data[3] = {
354 {
355 .vue_header = { 0 },
356 .position = { 0.0, 0.0 },
357 .color = clear_value,
358 },
359 {
360 .vue_header = { 0 },
361 .position = { fb->width, 0.0 },
362 .color = clear_value,
363 },
364 {
365 .vue_header = { 0 },
366 .position = { fb->width, fb->height },
367 .color = clear_value,
368 },
369 };
370
371 struct anv_state state =
Kristian Høgsberg77359202015-12-01 15:37:12 -0800372 anv_cmd_buffer_emit_dynamic(cmd_buffer, vertex_data, sizeof(vertex_data), 16);
Chad Versacea9a30712015-11-03 14:55:58 -0800373
374 struct anv_buffer vertex_buffer = {
375 .device = device,
376 .size = sizeof(vertex_data),
377 .bo = &device->dynamic_state_block_pool.bo,
378 .offset = state.offset,
379 };
380
BogDan Vatra102c7422016-01-05 21:44:16 +0200381 ANV_CALL(CmdSetViewport)(cmd_buffer_h, 0, 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800382 (VkViewport[]) {
383 {
Jason Ekstrand5f348bd2015-11-30 17:26:32 -0800384 .x = 0,
385 .y = 0,
Chad Versacea9a30712015-11-03 14:55:58 -0800386 .width = fb->width,
387 .height = fb->height,
388 .minDepth = 0.0,
389 .maxDepth = 1.0,
390 },
391 });
392
BogDan Vatra102c7422016-01-05 21:44:16 +0200393 ANV_CALL(CmdSetScissor)(cmd_buffer_h, 0, 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800394 (VkRect2D[]) {
395 {
396 .offset = { 0, 0 },
397 .extent = { fb->width, fb->height },
398 }
399 });
400
401 ANV_CALL(CmdBindVertexBuffers)(cmd_buffer_h, 0, 1,
402 (VkBuffer[]) { anv_buffer_to_handle(&vertex_buffer) },
403 (VkDeviceSize[]) { 0 });
404
Chad Versace0679bef2016-01-13 16:29:45 -0800405 if (cmd_buffer->state.pipeline != pipeline) {
Chad Versacea9a30712015-11-03 14:55:58 -0800406 ANV_CALL(CmdBindPipeline)(cmd_buffer_h, VK_PIPELINE_BIND_POINT_GRAPHICS,
407 pipeline_h);
408 }
409
410 ANV_CALL(CmdDraw)(cmd_buffer_h, 3, 1, 0, 0);
411}
412
413
414static void
415build_depthstencil_shaders(struct nir_shader **out_vs,
416 struct nir_shader **out_fs)
417{
418 nir_builder vs_b;
419 nir_builder fs_b;
420
Jason Ekstranda33fcc02015-12-29 13:47:37 -0800421 nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL);
422 nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL);
Chad Versacea9a30712015-11-03 14:55:58 -0800423
Chad Versace13610c02016-01-13 18:09:01 -0800424 vs_b.shader->info.name = ralloc_strdup(vs_b.shader, "meta_clear_depthstencil_vs");
425 fs_b.shader->info.name = ralloc_strdup(fs_b.shader, "meta_clear_depthstencil_fs");
426
Chad Versacea9a30712015-11-03 14:55:58 -0800427 const struct glsl_type *position_type = glsl_vec4_type();
428
429 nir_variable *vs_in_pos =
430 nir_variable_create(vs_b.shader, nir_var_shader_in, position_type,
431 "a_position");
432 vs_in_pos->data.location = VERT_ATTRIB_GENERIC0;
433
434 nir_variable *vs_out_pos =
435 nir_variable_create(vs_b.shader, nir_var_shader_out, position_type,
436 "gl_Position");
437 vs_out_pos->data.location = VARYING_SLOT_POS;
438
439 nir_copy_var(&vs_b, vs_out_pos, vs_in_pos);
440
441 *out_vs = vs_b.shader;
442 *out_fs = fs_b.shader;
443}
444
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800445static VkResult
Chad Versace16119ad2015-11-04 17:00:01 -0800446create_depthstencil_pipeline(struct anv_device *device,
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800447 VkImageAspectFlags aspects,
448 struct anv_pipeline **pipeline)
Chad Versacea9a30712015-11-03 14:55:58 -0800449{
450 struct nir_shader *vs_nir;
451 struct nir_shader *fs_nir;
Chad Versace16119ad2015-11-04 17:00:01 -0800452
Chad Versacea9a30712015-11-03 14:55:58 -0800453 build_depthstencil_shaders(&vs_nir, &fs_nir);
454
455 const VkPipelineVertexInputStateCreateInfo vi_state = {
456 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
Jason Ekstrande673d642015-11-30 17:00:30 -0800457 .vertexBindingDescriptionCount = 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800458 .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) {
459 {
460 .binding = 0,
Jason Ekstrande673d642015-11-30 17:00:30 -0800461 .stride = sizeof(struct depthstencil_clear_vattrs),
Jason Ekstrand9b1cb8f2015-11-30 13:28:09 -0800462 .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
Chad Versacea9a30712015-11-03 14:55:58 -0800463 },
464 },
Jason Ekstrande673d642015-11-30 17:00:30 -0800465 .vertexAttributeDescriptionCount = 2,
Chad Versacea9a30712015-11-03 14:55:58 -0800466 .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) {
467 {
468 /* VUE Header */
469 .location = 0,
470 .binding = 0,
471 .format = VK_FORMAT_R32G32B32A32_UINT,
Jason Ekstrande673d642015-11-30 17:00:30 -0800472 .offset = offsetof(struct depthstencil_clear_vattrs, vue_header),
Chad Versacea9a30712015-11-03 14:55:58 -0800473 },
474 {
475 /* Position */
476 .location = 1,
477 .binding = 0,
478 .format = VK_FORMAT_R32G32_SFLOAT,
Jason Ekstrande673d642015-11-30 17:00:30 -0800479 .offset = offsetof(struct depthstencil_clear_vattrs, position),
Chad Versacea9a30712015-11-03 14:55:58 -0800480 },
481 },
482 };
483
484 const VkPipelineDepthStencilStateCreateInfo ds_state = {
485 .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
Chad Versace16119ad2015-11-04 17:00:01 -0800486 .depthTestEnable = (aspects & VK_IMAGE_ASPECT_DEPTH_BIT),
Chad Versacea9a30712015-11-03 14:55:58 -0800487 .depthCompareOp = VK_COMPARE_OP_ALWAYS,
Chad Versace16119ad2015-11-04 17:00:01 -0800488 .depthWriteEnable = (aspects & VK_IMAGE_ASPECT_DEPTH_BIT),
Chad Versacea9a30712015-11-03 14:55:58 -0800489 .depthBoundsTestEnable = false,
Chad Versace16119ad2015-11-04 17:00:01 -0800490 .stencilTestEnable = (aspects & VK_IMAGE_ASPECT_STENCIL_BIT),
491 .front = {
Jason Ekstrand4ab93912015-11-30 14:19:41 -0800492 .passOp = VK_STENCIL_OP_REPLACE,
493 .compareOp = VK_COMPARE_OP_ALWAYS,
494 .writeMask = UINT32_MAX,
495 .reference = 0, /* dynamic */
Chad Versace16119ad2015-11-04 17:00:01 -0800496 },
497 .back = { 0 /* dont care */ },
Chad Versacea9a30712015-11-03 14:55:58 -0800498 };
499
500 const VkPipelineColorBlendStateCreateInfo cb_state = {
501 .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
Chad Versacea9a30712015-11-03 14:55:58 -0800502 .logicOpEnable = false,
503 .attachmentCount = 0,
504 .pAttachments = NULL,
505 };
506
Chad Versace16119ad2015-11-04 17:00:01 -0800507 return create_pipeline(device, vs_nir, fs_nir, &vi_state, &ds_state,
Chad Versace0679bef2016-01-13 16:29:45 -0800508 &cb_state, NULL, /*use_repclear*/ true, pipeline);
Chad Versacea9a30712015-11-03 14:55:58 -0800509}
510
511static void
Chad Versacef2700d62016-01-13 14:09:36 -0800512emit_depthstencil_clear(struct anv_cmd_buffer *cmd_buffer,
Chad Versacedeb8dd82016-01-13 14:47:51 -0800513 const VkClearAttachment *clear_att)
Chad Versacea9a30712015-11-03 14:55:58 -0800514{
515 struct anv_device *device = cmd_buffer->device;
Chad Versacedeb8dd82016-01-13 14:47:51 -0800516 const struct anv_subpass *subpass = cmd_buffer->state.subpass;
Chad Versacea9a30712015-11-03 14:55:58 -0800517 const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
Chad Versacedeb8dd82016-01-13 14:47:51 -0800518 uint32_t attachment = subpass->depth_stencil_attachment;
519 VkClearDepthStencilValue clear_value = clear_att->clearValue.depthStencil;
520 VkImageAspectFlags aspects = clear_att->aspectMask;
521
522 VkCommandBuffer cmd_buffer_h = anv_cmd_buffer_to_handle(cmd_buffer);
523
524 assert(aspects == VK_IMAGE_ASPECT_DEPTH_BIT ||
525 aspects == VK_IMAGE_ASPECT_STENCIL_BIT ||
526 aspects == (VK_IMAGE_ASPECT_DEPTH_BIT |
527 VK_IMAGE_ASPECT_STENCIL_BIT));
528 assert(attachment != VK_ATTACHMENT_UNUSED);
Chad Versacea9a30712015-11-03 14:55:58 -0800529
Chad Versace16119ad2015-11-04 17:00:01 -0800530 const struct depthstencil_clear_vattrs vertex_data[3] = {
Chad Versacea9a30712015-11-03 14:55:58 -0800531 {
532 .vue_header = { 0 },
533 .position = { 0.0, 0.0 },
534 },
535 {
536 .vue_header = { 0 },
537 .position = { fb->width, 0.0 },
538 },
539 {
540 .vue_header = { 0 },
541 .position = { fb->width, fb->height },
542 },
543 };
544
545 struct anv_state state =
Kristian Høgsberg77359202015-12-01 15:37:12 -0800546 anv_cmd_buffer_emit_dynamic(cmd_buffer, vertex_data, sizeof(vertex_data), 16);
Chad Versacea9a30712015-11-03 14:55:58 -0800547
548 struct anv_buffer vertex_buffer = {
549 .device = device,
550 .size = sizeof(vertex_data),
551 .bo = &device->dynamic_state_block_pool.bo,
552 .offset = state.offset,
553 };
554
BogDan Vatra102c7422016-01-05 21:44:16 +0200555 ANV_CALL(CmdSetViewport)(cmd_buffer_h, 0, 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800556 (VkViewport[]) {
557 {
Jason Ekstrand5f348bd2015-11-30 17:26:32 -0800558 .x = 0,
559 .y = 0,
Chad Versacea9a30712015-11-03 14:55:58 -0800560 .width = fb->width,
561 .height = fb->height,
Chad Versace16119ad2015-11-04 17:00:01 -0800562
563 /* Ignored when clearing only stencil. */
564 .minDepth = clear_value.depth,
565 .maxDepth = clear_value.depth,
Chad Versacea9a30712015-11-03 14:55:58 -0800566 },
567 });
568
BogDan Vatra102c7422016-01-05 21:44:16 +0200569 ANV_CALL(CmdSetScissor)(cmd_buffer_h, 0, 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800570 (VkRect2D[]) {
571 {
572 .offset = { 0, 0 },
573 .extent = { fb->width, fb->height },
574 }
575 });
576
Chad Versace16119ad2015-11-04 17:00:01 -0800577 if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
578 ANV_CALL(CmdSetStencilReference)(cmd_buffer_h, VK_STENCIL_FACE_FRONT_BIT,
579 clear_value.stencil);
580 }
581
Chad Versacea9a30712015-11-03 14:55:58 -0800582 ANV_CALL(CmdBindVertexBuffers)(cmd_buffer_h, 0, 1,
583 (VkBuffer[]) { anv_buffer_to_handle(&vertex_buffer) },
584 (VkDeviceSize[]) { 0 });
585
Chad Versace16119ad2015-11-04 17:00:01 -0800586 struct anv_pipeline *pipeline;
587 switch (aspects) {
588 case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT:
589 pipeline = device->meta_state.clear.depthstencil_pipeline;
590 break;
591 case VK_IMAGE_ASPECT_DEPTH_BIT:
592 pipeline = device->meta_state.clear.depth_only_pipeline;
593 break;
594 case VK_IMAGE_ASPECT_STENCIL_BIT:
595 pipeline = device->meta_state.clear.stencil_only_pipeline;
596 break;
597 default:
598 unreachable("expected depth or stencil aspect");
599 }
600
601 if (cmd_buffer->state.pipeline != pipeline) {
Chad Versacea9a30712015-11-03 14:55:58 -0800602 ANV_CALL(CmdBindPipeline)(cmd_buffer_h, VK_PIPELINE_BIND_POINT_GRAPHICS,
Chad Versace16119ad2015-11-04 17:00:01 -0800603 anv_pipeline_to_handle(pipeline));
Chad Versacea9a30712015-11-03 14:55:58 -0800604 }
605
606 ANV_CALL(CmdDraw)(cmd_buffer_h, 3, 1, 0, 0);
607}
608
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800609static VkResult
Chad Versace16119ad2015-11-04 17:00:01 -0800610init_depthstencil_pipelines(struct anv_device *device)
611{
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800612 VkResult result;
613 struct anv_meta_state *state = &device->meta_state;
Chad Versace16119ad2015-11-04 17:00:01 -0800614
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800615 result =
616 create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_DEPTH_BIT,
617 &state->clear.depth_only_pipeline);
618 if (result != VK_SUCCESS)
619 goto fail;
Chad Versace16119ad2015-11-04 17:00:01 -0800620
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800621 result =
622 create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_STENCIL_BIT,
623 &state->clear.stencil_only_pipeline);
624 if (result != VK_SUCCESS)
625 goto fail_depth_only;
626
627 result =
628 create_depthstencil_pipeline(device,
629 VK_IMAGE_ASPECT_DEPTH_BIT |
630 VK_IMAGE_ASPECT_STENCIL_BIT,
631 &state->clear.depthstencil_pipeline);
632 if (result != VK_SUCCESS)
633 goto fail_stencil_only;
634
635 return result;
636
637 fail_stencil_only:
638 anv_DestroyPipeline(anv_device_to_handle(device),
639 anv_pipeline_to_handle(state->clear.stencil_only_pipeline),
640 NULL);
641 fail_depth_only:
642 anv_DestroyPipeline(anv_device_to_handle(device),
643 anv_pipeline_to_handle(state->clear.depth_only_pipeline),
644 NULL);
645 fail:
646 return result;
Chad Versace16119ad2015-11-04 17:00:01 -0800647}
648
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800649VkResult
Chad Versacea9a30712015-11-03 14:55:58 -0800650anv_device_init_meta_clear_state(struct anv_device *device)
651{
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800652 VkResult result;
653
Chad Versace0679bef2016-01-13 16:29:45 -0800654 result = init_color_pipelines(device);
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800655 if (result != VK_SUCCESS)
Chad Versace0679bef2016-01-13 16:29:45 -0800656 return result;
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800657
658 result = init_depthstencil_pipelines(device);
659 if (result != VK_SUCCESS)
Chad Versace0679bef2016-01-13 16:29:45 -0800660 return result;
Kristian Høgsberg Kristensen5526c172016-01-03 22:43:47 -0800661
662 return VK_SUCCESS;
Chad Versacea9a30712015-11-03 14:55:58 -0800663}
664
665void
666anv_device_finish_meta_clear_state(struct anv_device *device)
667{
Chad Versace16119ad2015-11-04 17:00:01 -0800668 VkDevice device_h = anv_device_to_handle(device);
669
Chad Versace0679bef2016-01-13 16:29:45 -0800670 for (uint32_t i = 0;
671 i < ARRAY_SIZE(device->meta_state.clear.color_pipelines); ++i) {
672 ANV_CALL(DestroyPipeline)(device_h,
673 anv_pipeline_to_handle(device->meta_state.clear.color_pipelines[i]),
674 NULL);
675 }
676
Chad Versace16119ad2015-11-04 17:00:01 -0800677 ANV_CALL(DestroyPipeline)(device_h,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800678 anv_pipeline_to_handle(device->meta_state.clear.depth_only_pipeline),
679 NULL);
Chad Versace16119ad2015-11-04 17:00:01 -0800680 ANV_CALL(DestroyPipeline)(device_h,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800681 anv_pipeline_to_handle(device->meta_state.clear.stencil_only_pipeline),
682 NULL);
Chad Versace16119ad2015-11-04 17:00:01 -0800683 ANV_CALL(DestroyPipeline)(device_h,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800684 anv_pipeline_to_handle(device->meta_state.clear.depthstencil_pipeline),
685 NULL);
Chad Versacea9a30712015-11-03 14:55:58 -0800686}
687
Chad Versace356f9522016-01-13 11:52:23 -0800688/**
Chad Versacedeb8dd82016-01-13 14:47:51 -0800689 * The parameters mean that same as those in vkCmdClearAttachments.
Chad Versace356f9522016-01-13 11:52:23 -0800690 */
691static void
692emit_clear(struct anv_cmd_buffer *cmd_buffer,
Chad Versacedeb8dd82016-01-13 14:47:51 -0800693 const VkClearAttachment *clear_att)
Chad Versacea9a30712015-11-03 14:55:58 -0800694{
Chad Versacedeb8dd82016-01-13 14:47:51 -0800695 if (clear_att->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
696 emit_color_clear(cmd_buffer, clear_att);
Chad Versace356f9522016-01-13 11:52:23 -0800697 } else {
Chad Versacedeb8dd82016-01-13 14:47:51 -0800698 assert(clear_att->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT |
699 VK_IMAGE_ASPECT_STENCIL_BIT));
700 emit_depthstencil_clear(cmd_buffer, clear_att);
Chad Versace356f9522016-01-13 11:52:23 -0800701 }
702}
Chad Versacea9a30712015-11-03 14:55:58 -0800703
Chad Versace356f9522016-01-13 11:52:23 -0800704static bool
Chad Versacedeb8dd82016-01-13 14:47:51 -0800705subpass_needs_clear(const struct anv_cmd_buffer *cmd_buffer)
Chad Versace356f9522016-01-13 11:52:23 -0800706{
707 const struct anv_cmd_state *cmd_state = &cmd_buffer->state;
Chad Versacedeb8dd82016-01-13 14:47:51 -0800708 uint32_t ds = cmd_state->subpass->depth_stencil_attachment;
Jason Ekstrande14b2c72015-11-21 11:39:12 -0800709
Chad Versacedeb8dd82016-01-13 14:47:51 -0800710 for (uint32_t i = 0; i < cmd_state->subpass->color_count; ++i) {
711 uint32_t a = cmd_state->subpass->color_attachments[i];
712 if (cmd_state->attachments[a].pending_clear_aspects) {
Chad Versace356f9522016-01-13 11:52:23 -0800713 return true;
Jason Ekstrande14b2c72015-11-21 11:39:12 -0800714 }
715 }
716
Chad Versacedeb8dd82016-01-13 14:47:51 -0800717 if (ds != VK_ATTACHMENT_UNUSED &&
718 cmd_state->attachments[ds].pending_clear_aspects) {
719 return true;
720 }
721
Chad Versace356f9522016-01-13 11:52:23 -0800722 return false;
723}
724
Chad Versacedeb8dd82016-01-13 14:47:51 -0800725/**
726 * Emit any pending attachment clears for the current subpass.
727 *
728 * @see anv_attachment_state::pending_clear_aspects
729 */
Chad Versace356f9522016-01-13 11:52:23 -0800730void
Chad Versacedeb8dd82016-01-13 14:47:51 -0800731anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer *cmd_buffer)
Chad Versace356f9522016-01-13 11:52:23 -0800732{
733 struct anv_cmd_state *cmd_state = &cmd_buffer->state;
734 struct anv_meta_saved_state saved_state;
735
Chad Versacedeb8dd82016-01-13 14:47:51 -0800736 if (!subpass_needs_clear(cmd_buffer))
Jason Ekstrande14b2c72015-11-21 11:39:12 -0800737 return;
738
Chad Versacea9a30712015-11-03 14:55:58 -0800739 meta_clear_begin(&saved_state, cmd_buffer);
740
Chad Versace356f9522016-01-13 11:52:23 -0800741 if (cmd_state->framebuffer->layers > 1)
Chad Versace0415dfc2016-01-11 15:05:47 -0800742 anv_finishme("clearing multi-layer framebuffer");
743
Chad Versacedeb8dd82016-01-13 14:47:51 -0800744 for (uint32_t i = 0; i < cmd_state->subpass->color_count; ++i) {
745 uint32_t a = cmd_state->subpass->color_attachments[i];
746
Chad Versace356f9522016-01-13 11:52:23 -0800747 if (!cmd_state->attachments[a].pending_clear_aspects)
748 continue;
Chad Versacea9a30712015-11-03 14:55:58 -0800749
Chad Versacedeb8dd82016-01-13 14:47:51 -0800750 assert(cmd_state->attachments[a].pending_clear_aspects ==
751 VK_IMAGE_ASPECT_COLOR_BIT);
Chad Versace16119ad2015-11-04 17:00:01 -0800752
Chad Versacedeb8dd82016-01-13 14:47:51 -0800753 VkClearAttachment clear_att = {
754 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
755 .colorAttachment = i, /* Use attachment index relative to subpass */
756 .clearValue = cmd_state->attachments[a].clear_value,
757 };
758
759 emit_clear(cmd_buffer, &clear_att);
Chad Versace356f9522016-01-13 11:52:23 -0800760 cmd_state->attachments[a].pending_clear_aspects = 0;
Chad Versacea9a30712015-11-03 14:55:58 -0800761 }
762
Chad Versacedeb8dd82016-01-13 14:47:51 -0800763 uint32_t ds = cmd_state->subpass->depth_stencil_attachment;
764
765 if (ds != VK_ATTACHMENT_UNUSED &&
766 cmd_state->attachments[ds].pending_clear_aspects) {
767
768 VkClearAttachment clear_att = {
769 .aspectMask = cmd_state->attachments[ds].pending_clear_aspects,
770 .clearValue = cmd_state->attachments[ds].clear_value,
771 };
772
773 emit_clear(cmd_buffer, &clear_att);
774 cmd_state->attachments[ds].pending_clear_aspects = 0;
775 }
776
Chad Versacea9a30712015-11-03 14:55:58 -0800777 meta_clear_end(&saved_state, cmd_buffer);
Chad Versace16b2a482015-11-03 14:19:45 -0800778}
779
780void anv_CmdClearColorImage(
Jason Ekstranda89a4852015-11-30 11:48:08 -0800781 VkCommandBuffer commandBuffer,
Chad Versace16b2a482015-11-03 14:19:45 -0800782 VkImage _image,
783 VkImageLayout imageLayout,
784 const VkClearColorValue* pColor,
785 uint32_t rangeCount,
786 const VkImageSubresourceRange* pRanges)
787{
Jason Ekstranda89a4852015-11-30 11:48:08 -0800788 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
Chad Versace16b2a482015-11-03 14:19:45 -0800789 ANV_FROM_HANDLE(anv_image, image, _image);
790 struct anv_meta_saved_state saved_state;
791
Chad Versacea9a30712015-11-03 14:55:58 -0800792 meta_clear_begin(&saved_state, cmd_buffer);
Chad Versace16b2a482015-11-03 14:19:45 -0800793
794 for (uint32_t r = 0; r < rangeCount; r++) {
Jason Ekstrand299f8f12015-12-01 12:52:56 -0800795 for (uint32_t l = 0; l < pRanges[r].levelCount; l++) {
796 for (uint32_t s = 0; s < pRanges[r].layerCount; s++) {
Chad Versace16b2a482015-11-03 14:19:45 -0800797 struct anv_image_view iview;
798 anv_image_view_init(&iview, cmd_buffer->device,
799 &(VkImageViewCreateInfo) {
800 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
801 .image = _image,
Chad Versacef0d11d52015-12-09 17:03:14 -0800802 .viewType = anv_meta_get_view_type(image),
Jason Ekstrand3200a812015-12-31 12:39:34 -0800803 .format = image->vk_format,
Chad Versace16b2a482015-11-03 14:19:45 -0800804 .subresourceRange = {
805 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
806 .baseMipLevel = pRanges[r].baseMipLevel + l,
Jason Ekstrand299f8f12015-12-01 12:52:56 -0800807 .levelCount = 1,
Chad Versace16b2a482015-11-03 14:19:45 -0800808 .baseArrayLayer = pRanges[r].baseArrayLayer + s,
Jason Ekstrand299f8f12015-12-01 12:52:56 -0800809 .layerCount = 1
Chad Versace16b2a482015-11-03 14:19:45 -0800810 },
811 },
812 cmd_buffer);
813
814 VkFramebuffer fb;
815 anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer->device),
816 &(VkFramebufferCreateInfo) {
817 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
818 .attachmentCount = 1,
819 .pAttachments = (VkImageView[]) {
820 anv_image_view_to_handle(&iview),
821 },
822 .width = iview.extent.width,
823 .height = iview.extent.height,
824 .layers = 1
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800825 }, &cmd_buffer->pool->alloc, &fb);
Chad Versace16b2a482015-11-03 14:19:45 -0800826
827 VkRenderPass pass;
828 anv_CreateRenderPass(anv_device_to_handle(cmd_buffer->device),
829 &(VkRenderPassCreateInfo) {
830 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
831 .attachmentCount = 1,
832 .pAttachments = &(VkAttachmentDescription) {
Jason Ekstrandf665fdf2016-01-01 14:09:17 -0800833 .format = iview.vk_format,
Chad Versace16b2a482015-11-03 14:19:45 -0800834 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
835 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
836 .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
837 .finalLayout = VK_IMAGE_LAYOUT_GENERAL,
838 },
839 .subpassCount = 1,
840 .pSubpasses = &(VkSubpassDescription) {
Chad Versace16b2a482015-11-03 14:19:45 -0800841 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
Jason Ekstrand43f3e922015-12-01 13:09:22 -0800842 .inputAttachmentCount = 0,
843 .colorAttachmentCount = 1,
Chad Versace16b2a482015-11-03 14:19:45 -0800844 .pColorAttachments = &(VkAttachmentReference) {
845 .attachment = 0,
846 .layout = VK_IMAGE_LAYOUT_GENERAL,
847 },
848 .pResolveAttachments = NULL,
Jason Ekstrand43f3e922015-12-01 13:09:22 -0800849 .pDepthStencilAttachment = &(VkAttachmentReference) {
Chad Versace16b2a482015-11-03 14:19:45 -0800850 .attachment = VK_ATTACHMENT_UNUSED,
851 .layout = VK_IMAGE_LAYOUT_GENERAL,
852 },
Jason Ekstrand43f3e922015-12-01 13:09:22 -0800853 .preserveAttachmentCount = 1,
Jason Ekstrand7b816372016-01-14 07:29:58 -0800854 .pPreserveAttachments = (uint32_t[]) { 0 },
Chad Versace16b2a482015-11-03 14:19:45 -0800855 },
856 .dependencyCount = 0,
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800857 }, &cmd_buffer->pool->alloc, &pass);
Chad Versace16b2a482015-11-03 14:19:45 -0800858
859 ANV_CALL(CmdBeginRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer),
860 &(VkRenderPassBeginInfo) {
861 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
862 .renderArea = {
863 .offset = { 0, 0, },
864 .extent = {
865 .width = iview.extent.width,
866 .height = iview.extent.height,
867 },
868 },
869 .renderPass = pass,
870 .framebuffer = fb,
871 .clearValueCount = 1,
Chad Versacea9a30712015-11-03 14:55:58 -0800872 .pClearValues = (VkClearValue[]) {
873 { .color = *pColor },
874 },
Jason Ekstranda89a4852015-11-30 11:48:08 -0800875 }, VK_SUBPASS_CONTENTS_INLINE);
Chad Versace16b2a482015-11-03 14:19:45 -0800876
Chad Versace16b2a482015-11-03 14:19:45 -0800877 ANV_CALL(CmdEndRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer));
Jason Ekstrandfcfb4042015-12-02 03:28:27 -0800878
879 /* XXX: We're leaking the render pass and framebuffer */
Chad Versace16b2a482015-11-03 14:19:45 -0800880 }
881 }
882 }
883
Chad Versacea9a30712015-11-03 14:55:58 -0800884 meta_clear_end(&saved_state, cmd_buffer);
Chad Versace16b2a482015-11-03 14:19:45 -0800885}
886
887void anv_CmdClearDepthStencilImage(
Jason Ekstranda89a4852015-11-30 11:48:08 -0800888 VkCommandBuffer commandBuffer,
Chad Versace16b2a482015-11-03 14:19:45 -0800889 VkImage image,
890 VkImageLayout imageLayout,
891 const VkClearDepthStencilValue* pDepthStencil,
892 uint32_t rangeCount,
893 const VkImageSubresourceRange* pRanges)
894{
895 stub();
896}
897
Jason Ekstrand569f70b2015-11-30 14:52:38 -0800898void anv_CmdClearAttachments(
Jason Ekstranda89a4852015-11-30 11:48:08 -0800899 VkCommandBuffer commandBuffer,
Jason Ekstrand569f70b2015-11-30 14:52:38 -0800900 uint32_t attachmentCount,
901 const VkClearAttachment* pAttachments,
Chad Versace16b2a482015-11-03 14:19:45 -0800902 uint32_t rectCount,
Jason Ekstrand569f70b2015-11-30 14:52:38 -0800903 const VkClearRect* pRects)
Chad Versace16b2a482015-11-03 14:19:45 -0800904{
905 stub();
906}