2015-07-15 12:09:52 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
2015-07-17 15:04:27 -07:00
|
|
|
#include "anv_private.h"
|
2021-01-05 19:34:51 -08:00
|
|
|
#include "anv_measure.h"
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2019-02-12 16:56:24 -06:00
|
|
|
#include "vk_util.h"
|
2016-05-13 14:07:21 -07:00
|
|
|
|
2015-07-15 12:09:52 -07:00
|
|
|
/** \file anv_cmd_buffer.c
|
|
|
|
|
*
|
2015-07-30 14:59:02 -07:00
|
|
|
* This file contains all of the stuff for emitting commands into a command
|
|
|
|
|
* buffer. This includes implementations of most of the vkCmd*
|
|
|
|
|
* entrypoints. This file is concerned entirely with state emission and
|
|
|
|
|
* not with the command buffer data structure itself. As far as this file
|
|
|
|
|
* is concerned, most of anv_cmd_buffer is magic.
|
2015-07-15 12:09:52 -07:00
|
|
|
*/
|
|
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
static void
|
2017-12-15 09:23:08 -08:00
|
|
|
anv_cmd_state_init(struct anv_cmd_buffer *cmd_buffer)
|
2015-07-15 12:09:52 -07:00
|
|
|
{
|
2016-01-13 11:28:35 -08:00
|
|
|
struct anv_cmd_state *state = &cmd_buffer->state;
|
|
|
|
|
|
2017-12-15 09:23:08 -08:00
|
|
|
memset(state, 0, sizeof(*state));
|
2017-03-08 12:45:37 +01:00
|
|
|
|
2018-02-12 08:17:57 -08:00
|
|
|
state->current_pipeline = UINT32_MAX;
|
2022-07-04 10:05:21 +03:00
|
|
|
state->gfx.restart_index = UINT32_MAX;
|
2022-12-27 15:30:23 +02:00
|
|
|
state->gfx.object_preemption = true;
|
2022-07-14 15:09:46 -05:00
|
|
|
state->gfx.dirty = 0;
|
2023-08-02 11:36:39 +03:00
|
|
|
|
|
|
|
|
memcpy(state->gfx.dyn_state.dirty,
|
|
|
|
|
cmd_buffer->device->gfx_dirty_state,
|
|
|
|
|
sizeof(state->gfx.dyn_state.dirty));
|
2017-12-15 09:23:08 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 14:02:27 -08:00
|
|
|
static void
|
|
|
|
|
anv_cmd_pipeline_state_finish(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
struct anv_cmd_pipeline_state *pipe_state)
|
|
|
|
|
{
|
2023-10-09 15:30:23 -07:00
|
|
|
anv_push_descriptor_set_finish(&pipe_state->push_descriptor);
|
2017-12-15 14:02:27 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 09:23:08 -08:00
|
|
|
static void
|
|
|
|
|
anv_cmd_state_finish(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
|
|
|
|
struct anv_cmd_state *state = &cmd_buffer->state;
|
|
|
|
|
|
2017-12-15 14:02:27 -08:00
|
|
|
anv_cmd_pipeline_state_finish(cmd_buffer, &state->gfx.base);
|
|
|
|
|
anv_cmd_pipeline_state_finish(cmd_buffer, &state->compute.base);
|
2017-12-15 09:23:08 -08:00
|
|
|
}
|
2016-01-13 11:28:35 -08:00
|
|
|
|
2017-12-15 09:23:08 -08:00
|
|
|
static void
|
|
|
|
|
anv_cmd_state_reset(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
|
|
|
|
anv_cmd_state_finish(cmd_buffer);
|
|
|
|
|
anv_cmd_state_init(cmd_buffer);
|
2023-05-19 17:01:23 +03:00
|
|
|
|
|
|
|
|
cmd_buffer->last_compute_walker = NULL;
|
2023-11-20 15:33:33 +01:00
|
|
|
cmd_buffer->last_indirect_dispatch = NULL;
|
2015-07-30 14:59:02 -07:00
|
|
|
}
|
2015-07-29 14:05:06 -07:00
|
|
|
|
2023-05-11 11:41:39 -07:00
|
|
|
VkResult
|
2023-12-12 11:54:28 +01:00
|
|
|
anv_cmd_buffer_ensure_rcs_companion(struct anv_cmd_buffer *cmd_buffer)
|
2023-05-11 11:41:39 -07:00
|
|
|
{
|
2023-12-12 11:54:28 +01:00
|
|
|
if (cmd_buffer->companion_rcs_cmd_buffer)
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
2023-05-11 11:41:39 -07:00
|
|
|
VkResult result = VK_SUCCESS;
|
|
|
|
|
pthread_mutex_lock(&cmd_buffer->device->mutex);
|
2023-12-12 11:54:28 +01:00
|
|
|
VK_FROM_HANDLE(vk_command_pool, pool,
|
|
|
|
|
cmd_buffer->device->companion_rcs_cmd_pool);
|
|
|
|
|
assert(pool != NULL);
|
2023-05-11 11:41:39 -07:00
|
|
|
|
2023-12-12 11:54:28 +01:00
|
|
|
struct vk_command_buffer *tmp_cmd_buffer = NULL;
|
|
|
|
|
result = pool->command_buffer_ops->create(pool, &tmp_cmd_buffer);
|
|
|
|
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
goto unlock_and_return;
|
|
|
|
|
|
|
|
|
|
cmd_buffer->companion_rcs_cmd_buffer =
|
|
|
|
|
container_of(tmp_cmd_buffer, struct anv_cmd_buffer, vk);
|
|
|
|
|
cmd_buffer->companion_rcs_cmd_buffer->vk.level = cmd_buffer->vk.level;
|
|
|
|
|
cmd_buffer->companion_rcs_cmd_buffer->is_companion_rcs_cmd_buffer = true;
|
|
|
|
|
|
|
|
|
|
unlock_and_return:
|
|
|
|
|
pthread_mutex_unlock(&cmd_buffer->device->mutex);
|
2023-05-11 11:41:39 -07:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 13:42:58 -05:00
|
|
|
static VkResult
|
|
|
|
|
anv_create_cmd_buffer(struct vk_command_pool *pool,
|
|
|
|
|
struct vk_command_buffer **cmd_buffer_out)
|
2015-07-30 14:59:02 -07:00
|
|
|
{
|
2022-08-30 13:42:58 -05:00
|
|
|
struct anv_device *device =
|
|
|
|
|
container_of(pool->base.device, struct anv_device, vk);
|
2015-07-30 14:59:02 -07:00
|
|
|
struct anv_cmd_buffer *cmd_buffer;
|
|
|
|
|
VkResult result;
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2023-05-11 11:41:39 -07:00
|
|
|
cmd_buffer = vk_zalloc(&pool->alloc, sizeof(*cmd_buffer), 8,
|
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2015-07-30 14:59:02 -07:00
|
|
|
if (cmd_buffer == NULL)
|
2021-09-24 12:06:32 -05:00
|
|
|
return vk_error(pool, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2022-08-30 12:41:48 -05:00
|
|
|
result = vk_command_buffer_init(pool, &cmd_buffer->vk,
|
2022-08-30 13:42:58 -05:00
|
|
|
&anv_cmd_buffer_ops, 0);
|
2021-04-02 17:57:54 +03:00
|
|
|
if (result != VK_SUCCESS)
|
2022-02-08 16:04:34 -06:00
|
|
|
goto fail_alloc;
|
2021-04-02 17:57:54 +03:00
|
|
|
|
2022-07-14 15:09:46 -05:00
|
|
|
cmd_buffer->vk.dynamic_graphics_state.ms.sample_locations =
|
|
|
|
|
&cmd_buffer->state.gfx.sample_locations;
|
2023-01-31 22:15:11 +01:00
|
|
|
cmd_buffer->vk.dynamic_graphics_state.vi =
|
|
|
|
|
&cmd_buffer->state.gfx.vertex_input;
|
2022-07-14 15:09:46 -05:00
|
|
|
|
2017-03-08 12:45:37 +01:00
|
|
|
cmd_buffer->batch.status = VK_SUCCESS;
|
2023-09-17 11:46:18 +03:00
|
|
|
cmd_buffer->generation.batch.status = VK_SUCCESS;
|
2017-03-08 12:45:37 +01:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
cmd_buffer->device = device;
|
2022-02-07 15:22:54 -06:00
|
|
|
|
2022-02-07 15:24:34 -06:00
|
|
|
assert(pool->queue_family_index < device->physical->queue.family_count);
|
2022-02-07 15:22:54 -06:00
|
|
|
cmd_buffer->queue_family =
|
2022-02-07 15:24:34 -06:00
|
|
|
&device->physical->queue.families[pool->queue_family_index];
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
result = anv_cmd_buffer_init_batch_bo_chain(cmd_buffer);
|
|
|
|
|
if (result != VK_SUCCESS)
|
2022-02-08 16:04:34 -06:00
|
|
|
goto fail_vk;
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
anv_state_stream_init(&cmd_buffer->surface_state_stream,
|
2022-10-24 14:12:28 +03:00
|
|
|
&device->internal_surface_state_pool, 4096);
|
2015-07-30 14:59:02 -07:00
|
|
|
anv_state_stream_init(&cmd_buffer->dynamic_state_stream,
|
2017-04-23 17:22:26 -07:00
|
|
|
&device->dynamic_state_pool, 16384);
|
2020-05-04 17:08:00 -05:00
|
|
|
anv_state_stream_init(&cmd_buffer->general_state_stream,
|
|
|
|
|
&device->general_state_pool, 16384);
|
2023-10-11 23:48:01 +03:00
|
|
|
anv_state_stream_init(&cmd_buffer->indirect_push_descriptor_stream,
|
|
|
|
|
&device->indirect_push_descriptor_pool, 4096);
|
2015-07-30 14:59:02 -07:00
|
|
|
|
2022-02-17 14:22:57 +02:00
|
|
|
int success = u_vector_init_pow2(&cmd_buffer->dynamic_bos, 8,
|
|
|
|
|
sizeof(struct anv_bo *));
|
|
|
|
|
if (!success)
|
|
|
|
|
goto fail_batch_bo;
|
|
|
|
|
|
2020-08-26 15:44:07 +03:00
|
|
|
cmd_buffer->self_mod_locations = NULL;
|
2023-05-11 11:41:39 -07:00
|
|
|
cmd_buffer->companion_rcs_cmd_buffer = NULL;
|
|
|
|
|
cmd_buffer->is_companion_rcs_cmd_buffer = false;
|
2020-08-26 15:44:07 +03:00
|
|
|
|
2023-09-17 11:46:18 +03:00
|
|
|
cmd_buffer->generation.jump_addr = ANV_NULL_ADDRESS;
|
|
|
|
|
cmd_buffer->generation.return_addr = ANV_NULL_ADDRESS;
|
2022-02-26 14:00:07 +02:00
|
|
|
|
2023-05-19 17:01:23 +03:00
|
|
|
cmd_buffer->last_compute_walker = NULL;
|
2023-11-20 15:33:33 +01:00
|
|
|
cmd_buffer->last_indirect_dispatch = NULL;
|
2023-05-19 17:01:23 +03:00
|
|
|
|
2023-09-17 11:46:18 +03:00
|
|
|
memset(&cmd_buffer->generation.shader_state, 0,
|
|
|
|
|
sizeof(cmd_buffer->generation.shader_state));
|
2023-05-16 12:54:39 +03:00
|
|
|
|
2017-12-15 09:23:08 -08:00
|
|
|
anv_cmd_state_init(cmd_buffer);
|
2017-01-12 16:12:46 +00:00
|
|
|
|
2021-01-05 19:34:51 -08:00
|
|
|
anv_measure_init(cmd_buffer);
|
|
|
|
|
|
2021-11-21 18:23:57 +02:00
|
|
|
u_trace_init(&cmd_buffer->trace, &device->ds.trace_context);
|
2021-11-18 17:45:57 +02:00
|
|
|
|
2022-08-30 13:42:58 -05:00
|
|
|
*cmd_buffer_out = &cmd_buffer->vk;
|
2015-07-29 14:05:06 -07:00
|
|
|
|
2015-07-15 12:09:52 -07:00
|
|
|
return VK_SUCCESS;
|
2015-07-30 14:59:02 -07:00
|
|
|
|
2022-02-17 14:22:57 +02:00
|
|
|
fail_batch_bo:
|
|
|
|
|
anv_cmd_buffer_fini_batch_bo_chain(cmd_buffer);
|
2022-02-08 16:04:34 -06:00
|
|
|
fail_vk:
|
|
|
|
|
vk_command_buffer_finish(&cmd_buffer->vk);
|
|
|
|
|
fail_alloc:
|
2022-02-07 15:24:34 -06:00
|
|
|
vk_free2(&device->vk.alloc, &pool->alloc, cmd_buffer);
|
2015-07-30 14:59:02 -07:00
|
|
|
|
|
|
|
|
return result;
|
2015-07-15 12:09:52 -07:00
|
|
|
}
|
|
|
|
|
|
2015-12-02 03:48:58 -08:00
|
|
|
static void
|
2023-05-18 23:15:38 -07:00
|
|
|
destroy_cmd_buffer(struct anv_cmd_buffer *cmd_buffer)
|
2015-12-02 03:48:58 -08:00
|
|
|
{
|
2021-11-18 17:45:57 +02:00
|
|
|
u_trace_fini(&cmd_buffer->trace);
|
|
|
|
|
|
2021-01-05 19:34:51 -08:00
|
|
|
anv_measure_destroy(cmd_buffer);
|
|
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
anv_cmd_buffer_fini_batch_bo_chain(cmd_buffer);
|
|
|
|
|
|
|
|
|
|
anv_state_stream_finish(&cmd_buffer->surface_state_stream);
|
|
|
|
|
anv_state_stream_finish(&cmd_buffer->dynamic_state_stream);
|
2020-05-04 17:08:00 -05:00
|
|
|
anv_state_stream_finish(&cmd_buffer->general_state_stream);
|
2023-10-11 23:48:01 +03:00
|
|
|
anv_state_stream_finish(&cmd_buffer->indirect_push_descriptor_stream);
|
2015-12-02 03:28:27 -08:00
|
|
|
|
2022-02-17 14:22:57 +02:00
|
|
|
while (u_vector_length(&cmd_buffer->dynamic_bos) > 0) {
|
|
|
|
|
struct anv_bo **bo = u_vector_remove(&cmd_buffer->dynamic_bos);
|
2023-10-05 17:54:35 +03:00
|
|
|
anv_bo_pool_free((*bo)->map != NULL ?
|
|
|
|
|
&cmd_buffer->device->batch_bo_pool :
|
|
|
|
|
&cmd_buffer->device->bvh_bo_pool, *bo);
|
2022-02-17 14:22:57 +02:00
|
|
|
}
|
|
|
|
|
u_vector_finish(&cmd_buffer->dynamic_bos);
|
|
|
|
|
|
2017-12-15 09:23:08 -08:00
|
|
|
anv_cmd_state_finish(cmd_buffer);
|
2017-09-27 14:16:04 +01:00
|
|
|
|
2022-02-07 15:22:54 -06:00
|
|
|
vk_free(&cmd_buffer->vk.pool->alloc, cmd_buffer->self_mod_locations);
|
2020-08-26 15:44:07 +03:00
|
|
|
|
2021-04-02 17:57:54 +03:00
|
|
|
vk_command_buffer_finish(&cmd_buffer->vk);
|
2022-02-07 15:22:54 -06:00
|
|
|
vk_free(&cmd_buffer->vk.pool->alloc, cmd_buffer);
|
2015-07-30 14:59:02 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-18 23:15:38 -07:00
|
|
|
static void
|
|
|
|
|
anv_cmd_buffer_destroy(struct vk_command_buffer *vk_cmd_buffer)
|
2015-07-30 14:59:02 -07:00
|
|
|
{
|
2022-08-30 13:42:58 -05:00
|
|
|
struct anv_cmd_buffer *cmd_buffer =
|
|
|
|
|
container_of(vk_cmd_buffer, struct anv_cmd_buffer, vk);
|
2023-09-25 10:41:44 +09:00
|
|
|
struct anv_device *device = cmd_buffer->device;
|
2022-08-30 13:42:58 -05:00
|
|
|
|
2023-09-25 10:41:44 +09:00
|
|
|
pthread_mutex_lock(&device->mutex);
|
2023-07-14 12:10:40 -07:00
|
|
|
if (cmd_buffer->companion_rcs_cmd_buffer) {
|
|
|
|
|
destroy_cmd_buffer(cmd_buffer->companion_rcs_cmd_buffer);
|
|
|
|
|
cmd_buffer->companion_rcs_cmd_buffer = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 12:27:05 +02:00
|
|
|
ANV_RMV(cmd_buffer_destroy, cmd_buffer->device, cmd_buffer);
|
|
|
|
|
|
2023-05-18 23:15:38 -07:00
|
|
|
destroy_cmd_buffer(cmd_buffer);
|
2023-09-25 10:41:44 +09:00
|
|
|
pthread_mutex_unlock(&device->mutex);
|
2023-05-18 23:15:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
reset_cmd_buffer(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
UNUSED VkCommandBufferResetFlags flags)
|
|
|
|
|
{
|
2021-04-02 17:57:54 +03:00
|
|
|
vk_command_buffer_reset(&cmd_buffer->vk);
|
|
|
|
|
|
2016-01-14 13:12:35 -08:00
|
|
|
cmd_buffer->usage_flags = 0;
|
2018-10-06 19:12:34 +01:00
|
|
|
cmd_buffer->perf_query_pool = NULL;
|
2023-05-11 11:41:39 -07:00
|
|
|
cmd_buffer->is_companion_rcs_cmd_buffer = false;
|
2015-07-30 14:59:02 -07:00
|
|
|
anv_cmd_buffer_reset_batch_bo_chain(cmd_buffer);
|
2016-01-13 11:28:35 -08:00
|
|
|
anv_cmd_state_reset(cmd_buffer);
|
2015-07-30 14:59:02 -07:00
|
|
|
|
2023-09-17 11:46:18 +03:00
|
|
|
memset(&cmd_buffer->generation.shader_state, 0,
|
|
|
|
|
sizeof(cmd_buffer->generation.shader_state));
|
2023-05-16 12:54:39 +03:00
|
|
|
|
2023-09-17 11:46:18 +03:00
|
|
|
cmd_buffer->generation.jump_addr = ANV_NULL_ADDRESS;
|
|
|
|
|
cmd_buffer->generation.return_addr = ANV_NULL_ADDRESS;
|
2023-01-05 15:30:33 +02:00
|
|
|
|
2016-03-04 12:42:03 -08:00
|
|
|
anv_state_stream_finish(&cmd_buffer->surface_state_stream);
|
|
|
|
|
anv_state_stream_init(&cmd_buffer->surface_state_stream,
|
2022-10-24 14:12:28 +03:00
|
|
|
&cmd_buffer->device->internal_surface_state_pool, 4096);
|
2016-03-04 12:42:03 -08:00
|
|
|
|
|
|
|
|
anv_state_stream_finish(&cmd_buffer->dynamic_state_stream);
|
|
|
|
|
anv_state_stream_init(&cmd_buffer->dynamic_state_stream,
|
2017-04-23 17:22:26 -07:00
|
|
|
&cmd_buffer->device->dynamic_state_pool, 16384);
|
2020-05-04 17:08:00 -05:00
|
|
|
|
|
|
|
|
anv_state_stream_finish(&cmd_buffer->general_state_stream);
|
|
|
|
|
anv_state_stream_init(&cmd_buffer->general_state_stream,
|
|
|
|
|
&cmd_buffer->device->general_state_pool, 16384);
|
|
|
|
|
|
2023-10-11 23:48:01 +03:00
|
|
|
anv_state_stream_finish(&cmd_buffer->indirect_push_descriptor_stream);
|
|
|
|
|
anv_state_stream_init(&cmd_buffer->indirect_push_descriptor_stream,
|
|
|
|
|
&cmd_buffer->device->indirect_push_descriptor_pool,
|
|
|
|
|
4096);
|
2023-02-22 09:00:35 +02:00
|
|
|
|
2022-02-17 14:22:57 +02:00
|
|
|
while (u_vector_length(&cmd_buffer->dynamic_bos) > 0) {
|
|
|
|
|
struct anv_bo **bo = u_vector_remove(&cmd_buffer->dynamic_bos);
|
|
|
|
|
anv_device_release_bo(cmd_buffer->device, *bo);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 19:34:51 -08:00
|
|
|
anv_measure_reset(cmd_buffer);
|
2021-11-18 17:45:57 +02:00
|
|
|
|
|
|
|
|
u_trace_fini(&cmd_buffer->trace);
|
2021-11-21 18:23:57 +02:00
|
|
|
u_trace_init(&cmd_buffer->trace, &cmd_buffer->device->ds.trace_context);
|
2015-07-29 14:05:06 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-18 23:15:38 -07:00
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_reset(struct vk_command_buffer *vk_cmd_buffer,
|
|
|
|
|
UNUSED VkCommandBufferResetFlags flags)
|
|
|
|
|
{
|
|
|
|
|
struct anv_cmd_buffer *cmd_buffer =
|
|
|
|
|
container_of(vk_cmd_buffer, struct anv_cmd_buffer, vk);
|
|
|
|
|
|
2023-07-14 12:10:40 -07:00
|
|
|
if (cmd_buffer->companion_rcs_cmd_buffer) {
|
|
|
|
|
reset_cmd_buffer(cmd_buffer->companion_rcs_cmd_buffer, flags);
|
|
|
|
|
destroy_cmd_buffer(cmd_buffer->companion_rcs_cmd_buffer);
|
|
|
|
|
cmd_buffer->companion_rcs_cmd_buffer = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 12:27:05 +02:00
|
|
|
ANV_RMV(cmd_buffer_destroy, cmd_buffer->device, cmd_buffer);
|
|
|
|
|
|
2023-05-18 23:15:38 -07:00
|
|
|
reset_cmd_buffer(cmd_buffer, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 13:42:58 -05:00
|
|
|
const struct vk_command_buffer_ops anv_cmd_buffer_ops = {
|
|
|
|
|
.create = anv_create_cmd_buffer,
|
|
|
|
|
.reset = anv_cmd_buffer_reset,
|
|
|
|
|
.destroy = anv_cmd_buffer_destroy,
|
|
|
|
|
};
|
2016-05-27 17:32:44 -07:00
|
|
|
|
2016-10-21 16:53:46 -07:00
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
2022-08-04 12:56:17 -07:00
|
|
|
const struct intel_device_info *devinfo = cmd_buffer->device->info;
|
2021-01-23 21:09:18 -06:00
|
|
|
anv_genX(devinfo, cmd_buffer_emit_state_base_address)(cmd_buffer);
|
2016-10-21 16:53:46 -07:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 08:35:12 -08:00
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
const struct anv_image *image,
|
|
|
|
|
VkImageAspectFlagBits aspect,
|
|
|
|
|
enum isl_aux_usage aux_usage,
|
|
|
|
|
uint32_t level,
|
|
|
|
|
uint32_t base_layer,
|
|
|
|
|
uint32_t layer_count)
|
|
|
|
|
{
|
2022-08-04 12:56:17 -07:00
|
|
|
const struct intel_device_info *devinfo = cmd_buffer->device->info;
|
2021-01-23 21:09:18 -06:00
|
|
|
anv_genX(devinfo, cmd_buffer_mark_image_written)(cmd_buffer, image,
|
|
|
|
|
aspect, aux_usage,
|
|
|
|
|
level, base_layer,
|
|
|
|
|
layer_count);
|
2017-11-27 08:35:12 -08:00
|
|
|
}
|
|
|
|
|
|
2022-12-05 15:52:09 -08:00
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_mark_image_fast_cleared(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
const struct anv_image *image,
|
|
|
|
|
const enum isl_format format,
|
|
|
|
|
union isl_color_value clear_color)
|
|
|
|
|
{
|
|
|
|
|
const struct intel_device_info *devinfo = cmd_buffer->device->info;
|
|
|
|
|
anv_genX(devinfo, set_fast_clear_state)(cmd_buffer, image, format,
|
|
|
|
|
clear_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_load_clear_color_from_image(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
struct anv_state state,
|
|
|
|
|
const struct anv_image *image)
|
|
|
|
|
{
|
|
|
|
|
const struct intel_device_info *devinfo = cmd_buffer->device->info;
|
|
|
|
|
anv_genX(devinfo, load_image_clear_color)(cmd_buffer, state, image);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-05 17:54:07 +03:00
|
|
|
void
|
|
|
|
|
anv_cmd_emit_conditional_render_predicate(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
2022-08-04 12:56:17 -07:00
|
|
|
const struct intel_device_info *devinfo = cmd_buffer->device->info;
|
2021-01-23 21:09:18 -06:00
|
|
|
anv_genX(devinfo, cmd_emit_conditional_render_predicate)(cmd_buffer);
|
2018-10-05 17:54:07 +03:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 13:44:44 +03:00
|
|
|
static void
|
|
|
|
|
clear_pending_query_bits(enum anv_query_bits *query_bits,
|
|
|
|
|
enum anv_pipe_bits flushed_bits)
|
2023-06-15 13:33:28 +03:00
|
|
|
{
|
|
|
|
|
if (flushed_bits & ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
|
2023-06-15 13:44:44 +03:00
|
|
|
*query_bits &= ~ANV_QUERY_WRITES_RT_FLUSH;
|
2023-06-15 13:33:28 +03:00
|
|
|
|
|
|
|
|
if (flushed_bits & ANV_PIPE_TILE_CACHE_FLUSH_BIT)
|
2023-06-15 13:44:44 +03:00
|
|
|
*query_bits &= ~ANV_QUERY_WRITES_TILE_FLUSH;
|
2023-06-15 13:33:28 +03:00
|
|
|
|
|
|
|
|
if ((flushed_bits & ANV_PIPE_DATA_CACHE_FLUSH_BIT) &&
|
|
|
|
|
(flushed_bits & ANV_PIPE_HDC_PIPELINE_FLUSH_BIT) &&
|
|
|
|
|
(flushed_bits & ANV_PIPE_UNTYPED_DATAPORT_CACHE_FLUSH_BIT))
|
2023-06-15 13:44:44 +03:00
|
|
|
*query_bits &= ~ANV_QUERY_WRITES_TILE_FLUSH;
|
2023-06-15 13:33:28 +03:00
|
|
|
|
|
|
|
|
/* Once RT/TILE have been flushed, we can consider the CS_STALL flush */
|
2023-06-15 13:44:44 +03:00
|
|
|
if ((*query_bits & (ANV_QUERY_WRITES_TILE_FLUSH |
|
|
|
|
|
ANV_QUERY_WRITES_RT_FLUSH |
|
|
|
|
|
ANV_QUERY_WRITES_DATA_FLUSH)) == 0 &&
|
2023-06-15 13:33:28 +03:00
|
|
|
(flushed_bits & (ANV_PIPE_END_OF_PIPE_SYNC_BIT | ANV_PIPE_CS_STALL_BIT)))
|
2023-06-15 13:44:44 +03:00
|
|
|
*query_bits &= ~ANV_QUERY_WRITES_CS_STALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_update_pending_query_bits(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
enum anv_pipe_bits flushed_bits)
|
|
|
|
|
{
|
|
|
|
|
clear_pending_query_bits(&cmd_buffer->state.queries.clear_bits, flushed_bits);
|
|
|
|
|
clear_pending_query_bits(&cmd_buffer->state.queries.buffer_write_bits, flushed_bits);
|
2023-06-15 13:33:28 +03:00
|
|
|
}
|
|
|
|
|
|
2019-11-07 11:28:47 -06:00
|
|
|
static bool
|
|
|
|
|
mem_update(void *dst, const void *src, size_t size)
|
|
|
|
|
{
|
|
|
|
|
if (memcmp(dst, src, size) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
memcpy(dst, src, size);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_dirty_for_bind_map(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
gl_shader_stage stage,
|
|
|
|
|
const struct anv_pipeline_bind_map *map)
|
|
|
|
|
{
|
2021-01-21 16:58:50 -06:00
|
|
|
assert(stage < ARRAY_SIZE(cmd_buffer->state.surface_sha1s));
|
2019-11-07 11:28:47 -06:00
|
|
|
if (mem_update(cmd_buffer->state.surface_sha1s[stage],
|
|
|
|
|
map->surface_sha1, sizeof(map->surface_sha1)))
|
|
|
|
|
cmd_buffer->state.descriptors_dirty |= mesa_to_vk_shader_stage(stage);
|
|
|
|
|
|
2021-01-21 16:58:50 -06:00
|
|
|
assert(stage < ARRAY_SIZE(cmd_buffer->state.sampler_sha1s));
|
2019-11-07 11:28:47 -06:00
|
|
|
if (mem_update(cmd_buffer->state.sampler_sha1s[stage],
|
|
|
|
|
map->sampler_sha1, sizeof(map->sampler_sha1)))
|
|
|
|
|
cmd_buffer->state.descriptors_dirty |= mesa_to_vk_shader_stage(stage);
|
|
|
|
|
|
2021-01-21 16:58:50 -06:00
|
|
|
assert(stage < ARRAY_SIZE(cmd_buffer->state.push_sha1s));
|
2019-11-07 11:28:47 -06:00
|
|
|
if (mem_update(cmd_buffer->state.push_sha1s[stage],
|
|
|
|
|
map->push_sha1, sizeof(map->push_sha1)))
|
|
|
|
|
cmd_buffer->state.push_constants_dirty |= mesa_to_vk_shader_stage(stage);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 16:24:54 +03:00
|
|
|
static void
|
|
|
|
|
anv_cmd_buffer_set_ray_query_buffer(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
struct anv_cmd_pipeline_state *pipeline_state,
|
|
|
|
|
struct anv_pipeline *pipeline,
|
|
|
|
|
VkShaderStageFlags stages)
|
|
|
|
|
{
|
|
|
|
|
struct anv_device *device = cmd_buffer->device;
|
|
|
|
|
|
|
|
|
|
uint64_t ray_shadow_size =
|
2022-12-02 14:37:31 +05:30
|
|
|
align64(brw_rt_ray_queries_shadow_stacks_size(device->info,
|
|
|
|
|
pipeline->ray_queries),
|
|
|
|
|
4096);
|
2021-06-08 16:24:54 +03:00
|
|
|
if (ray_shadow_size > 0 &&
|
|
|
|
|
(!cmd_buffer->state.ray_query_shadow_bo ||
|
|
|
|
|
cmd_buffer->state.ray_query_shadow_bo->size < ray_shadow_size)) {
|
2022-11-16 20:34:24 +02:00
|
|
|
unsigned shadow_size_log2 = MAX2(util_logbase2_ceil(ray_shadow_size), 16);
|
2021-06-08 16:24:54 +03:00
|
|
|
unsigned bucket = shadow_size_log2 - 16;
|
|
|
|
|
assert(bucket < ARRAY_SIZE(device->ray_query_shadow_bos));
|
|
|
|
|
|
|
|
|
|
struct anv_bo *bo = p_atomic_read(&device->ray_query_shadow_bos[bucket]);
|
|
|
|
|
if (bo == NULL) {
|
|
|
|
|
struct anv_bo *new_bo;
|
|
|
|
|
VkResult result = anv_device_alloc_bo(device, "RT queries shadow",
|
|
|
|
|
ray_shadow_size,
|
2022-08-02 16:17:31 +03:00
|
|
|
0, /* alloc_flags */
|
2021-06-08 16:24:54 +03:00
|
|
|
0, /* explicit_address */
|
|
|
|
|
&new_bo);
|
|
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
|
anv_batch_set_error(&cmd_buffer->batch, result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bo = p_atomic_cmpxchg(&device->ray_query_shadow_bos[bucket], NULL, new_bo);
|
|
|
|
|
if (bo != NULL) {
|
|
|
|
|
anv_device_release_bo(device, bo);
|
|
|
|
|
} else {
|
|
|
|
|
bo = new_bo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cmd_buffer->state.ray_query_shadow_bo = bo;
|
|
|
|
|
|
|
|
|
|
/* Add the ray query buffers to the batch list. */
|
|
|
|
|
anv_reloc_list_add_bo(cmd_buffer->batch.relocs,
|
|
|
|
|
cmd_buffer->state.ray_query_shadow_bo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add the HW buffer to the list of BO used. */
|
|
|
|
|
anv_reloc_list_add_bo(cmd_buffer->batch.relocs,
|
|
|
|
|
device->ray_query_bo);
|
|
|
|
|
|
|
|
|
|
/* Fill the push constants & mark them dirty. */
|
|
|
|
|
struct anv_state ray_query_global_state =
|
2022-08-04 12:56:17 -07:00
|
|
|
anv_genX(device->info, cmd_buffer_ray_query_globals)(cmd_buffer);
|
2021-06-08 16:24:54 +03:00
|
|
|
|
2022-11-23 12:02:41 +02:00
|
|
|
struct anv_address ray_query_globals_addr =
|
|
|
|
|
anv_state_pool_state_address(&device->dynamic_state_pool,
|
|
|
|
|
ray_query_global_state);
|
2021-06-08 16:24:54 +03:00
|
|
|
pipeline_state->push_constants.ray_query_globals =
|
|
|
|
|
anv_address_physical(ray_query_globals_addr);
|
|
|
|
|
cmd_buffer->state.push_constants_dirty |= stages;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 11:36:39 +03:00
|
|
|
/**
|
|
|
|
|
* This function compute changes between 2 pipelines and flags the dirty HW
|
|
|
|
|
* state appropriately.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
anv_cmd_buffer_flush_pipeline_state(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
struct anv_graphics_pipeline *old_pipeline,
|
|
|
|
|
struct anv_graphics_pipeline *new_pipeline)
|
|
|
|
|
{
|
|
|
|
|
struct anv_cmd_graphics_state *gfx = &cmd_buffer->state.gfx;
|
|
|
|
|
struct anv_gfx_dynamic_state *hw_state = &gfx->dyn_state;
|
|
|
|
|
|
|
|
|
|
#define diff_fix_state(bit, name) \
|
|
|
|
|
do { \
|
|
|
|
|
/* Fixed states should always have matching sizes */ \
|
|
|
|
|
assert(old_pipeline == NULL || \
|
|
|
|
|
old_pipeline->name.len == new_pipeline->name.len); \
|
|
|
|
|
/* Don't bother memcmp if the state is already dirty */ \
|
|
|
|
|
if (!BITSET_TEST(hw_state->dirty, ANV_GFX_STATE_##bit) && \
|
|
|
|
|
(old_pipeline == NULL || \
|
|
|
|
|
memcmp(&old_pipeline->batch_data[old_pipeline->name.offset], \
|
|
|
|
|
&new_pipeline->batch_data[new_pipeline->name.offset], \
|
|
|
|
|
4 * new_pipeline->name.len) != 0)) \
|
|
|
|
|
BITSET_SET(hw_state->dirty, ANV_GFX_STATE_##bit); \
|
|
|
|
|
} while (0)
|
|
|
|
|
#define diff_var_state(bit, name) \
|
|
|
|
|
do { \
|
|
|
|
|
/* Don't bother memcmp if the state is already dirty */ \
|
|
|
|
|
/* Also if the new state is empty, avoid marking dirty */ \
|
|
|
|
|
if (!BITSET_TEST(hw_state->dirty, ANV_GFX_STATE_##bit) && \
|
|
|
|
|
new_pipeline->name.len != 0 && \
|
|
|
|
|
(old_pipeline == NULL || \
|
|
|
|
|
old_pipeline->name.len != new_pipeline->name.len || \
|
|
|
|
|
memcmp(&old_pipeline->batch_data[old_pipeline->name.offset], \
|
|
|
|
|
&new_pipeline->batch_data[new_pipeline->name.offset], \
|
|
|
|
|
4 * new_pipeline->name.len) != 0)) \
|
|
|
|
|
BITSET_SET(hw_state->dirty, ANV_GFX_STATE_##bit); \
|
|
|
|
|
} while (0)
|
|
|
|
|
#define assert_identical(bit, name) \
|
|
|
|
|
do { \
|
|
|
|
|
/* Fixed states should always have matching sizes */ \
|
|
|
|
|
assert(old_pipeline == NULL || \
|
|
|
|
|
old_pipeline->name.len == new_pipeline->name.len); \
|
|
|
|
|
assert(old_pipeline == NULL || \
|
|
|
|
|
memcmp(&old_pipeline->batch_data[old_pipeline->name.offset], \
|
|
|
|
|
&new_pipeline->batch_data[new_pipeline->name.offset], \
|
|
|
|
|
4 * new_pipeline->name.len) == 0); \
|
|
|
|
|
} while (0)
|
|
|
|
|
#define assert_empty(name) assert(new_pipeline->name.len == 0)
|
|
|
|
|
|
|
|
|
|
/* Compare all states, including partial packed ones, the dynamic part is
|
|
|
|
|
* left at 0 but the static part could still change.
|
|
|
|
|
*/
|
|
|
|
|
diff_fix_state(URB, final.urb);
|
|
|
|
|
diff_fix_state(VF_SGVS, final.vf_sgvs);
|
|
|
|
|
if (cmd_buffer->device->info->ver >= 11)
|
|
|
|
|
diff_fix_state(VF_SGVS_2, final.vf_sgvs_2);
|
|
|
|
|
if (cmd_buffer->device->info->ver >= 12)
|
|
|
|
|
diff_fix_state(PRIMITIVE_REPLICATION, final.primitive_replication);
|
|
|
|
|
diff_fix_state(SBE, final.sbe);
|
|
|
|
|
diff_fix_state(SBE_SWIZ, final.sbe_swiz);
|
|
|
|
|
diff_fix_state(MULTISAMPLE, final.ms);
|
|
|
|
|
diff_fix_state(VS, final.vs);
|
|
|
|
|
diff_fix_state(HS, final.hs);
|
|
|
|
|
diff_fix_state(DS, final.ds);
|
|
|
|
|
diff_fix_state(PS, final.ps);
|
|
|
|
|
|
|
|
|
|
diff_fix_state(CLIP, partial.clip);
|
|
|
|
|
diff_fix_state(SF, partial.sf);
|
|
|
|
|
diff_fix_state(RASTER, partial.raster);
|
|
|
|
|
diff_fix_state(WM, partial.wm);
|
|
|
|
|
diff_fix_state(STREAMOUT, partial.so);
|
|
|
|
|
diff_fix_state(GS, partial.gs);
|
|
|
|
|
diff_fix_state(TE, partial.te);
|
|
|
|
|
diff_fix_state(VFG, partial.vfg);
|
2023-06-07 13:31:56 +03:00
|
|
|
diff_fix_state(PS_EXTRA, partial.ps_extra);
|
2023-08-02 11:36:39 +03:00
|
|
|
|
|
|
|
|
if (cmd_buffer->device->vk.enabled_extensions.EXT_mesh_shader) {
|
|
|
|
|
diff_fix_state(TASK_CONTROL, final.task_control);
|
|
|
|
|
diff_fix_state(TASK_SHADER, final.task_shader);
|
|
|
|
|
diff_fix_state(TASK_REDISTRIB, final.task_redistrib);
|
|
|
|
|
diff_fix_state(MESH_CONTROL, final.mesh_control);
|
|
|
|
|
diff_fix_state(MESH_SHADER, final.mesh_shader);
|
|
|
|
|
diff_fix_state(MESH_DISTRIB, final.mesh_distrib);
|
|
|
|
|
diff_fix_state(CLIP_MESH, final.clip_mesh);
|
|
|
|
|
diff_fix_state(SBE_MESH, final.sbe_mesh);
|
|
|
|
|
} else {
|
|
|
|
|
assert_empty(final.task_control);
|
|
|
|
|
assert_empty(final.task_shader);
|
|
|
|
|
assert_empty(final.task_redistrib);
|
|
|
|
|
assert_empty(final.mesh_control);
|
|
|
|
|
assert_empty(final.mesh_shader);
|
|
|
|
|
assert_empty(final.mesh_distrib);
|
|
|
|
|
assert_empty(final.clip_mesh);
|
|
|
|
|
assert_empty(final.sbe_mesh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* States that should never vary between pipelines, but can be affected by
|
|
|
|
|
* blorp etc...
|
|
|
|
|
*/
|
|
|
|
|
assert_identical(VF_STATISTICS, final.vf_statistics);
|
|
|
|
|
|
|
|
|
|
/* States that can vary in length */
|
|
|
|
|
diff_var_state(VF_SGVS_INSTANCING, final.vf_sgvs_instancing);
|
|
|
|
|
diff_var_state(SO_DECL_LIST, final.so_decl_list);
|
|
|
|
|
|
|
|
|
|
#undef diff_fix_state
|
|
|
|
|
#undef diff_var_state
|
|
|
|
|
#undef assert_identical
|
|
|
|
|
#undef assert_empty
|
|
|
|
|
|
|
|
|
|
/* We're not diffing the following :
|
|
|
|
|
* - anv_graphics_pipeline::vertex_input_data
|
|
|
|
|
* - anv_graphics_pipeline::final::vf_instancing
|
|
|
|
|
*
|
|
|
|
|
* since they are tracked by the runtime.
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
void anv_CmdBindPipeline(
|
2015-11-30 11:48:08 -08:00
|
|
|
VkCommandBuffer commandBuffer,
|
2015-07-30 14:59:02 -07:00
|
|
|
VkPipelineBindPoint pipelineBindPoint,
|
|
|
|
|
VkPipeline _pipeline)
|
2015-07-15 12:09:52 -07:00
|
|
|
{
|
2015-11-30 11:48:08 -08:00
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
2015-07-30 14:59:02 -07:00
|
|
|
ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline);
|
2021-06-08 16:24:54 +03:00
|
|
|
struct anv_cmd_pipeline_state *state;
|
|
|
|
|
VkShaderStageFlags stages = 0;
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
switch (pipelineBindPoint) {
|
2019-11-07 11:28:47 -06:00
|
|
|
case VK_PIPELINE_BIND_POINT_COMPUTE: {
|
2023-11-08 11:42:22 +02:00
|
|
|
if (cmd_buffer->state.compute.base.pipeline == pipeline)
|
2019-11-07 11:28:47 -06:00
|
|
|
return;
|
|
|
|
|
|
2023-03-20 16:35:46 +02:00
|
|
|
cmd_buffer->state.compute.base.pipeline = pipeline;
|
2017-12-15 16:38:10 -08:00
|
|
|
cmd_buffer->state.compute.pipeline_dirty = true;
|
2023-11-08 11:42:22 +02:00
|
|
|
|
|
|
|
|
struct anv_compute_pipeline *compute_pipeline =
|
|
|
|
|
anv_pipeline_to_compute(pipeline);
|
2020-03-03 13:43:39 -08:00
|
|
|
set_dirty_for_bind_map(cmd_buffer, MESA_SHADER_COMPUTE,
|
2020-03-03 15:31:50 -08:00
|
|
|
&compute_pipeline->cs->bind_map);
|
2021-06-08 16:24:54 +03:00
|
|
|
|
|
|
|
|
state = &cmd_buffer->state.compute.base;
|
|
|
|
|
stages = VK_SHADER_STAGE_COMPUTE_BIT;
|
2015-07-30 14:59:02 -07:00
|
|
|
break;
|
2019-11-07 11:28:47 -06:00
|
|
|
}
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
case VK_PIPELINE_BIND_POINT_GRAPHICS: {
|
2023-08-02 11:36:39 +03:00
|
|
|
struct anv_graphics_pipeline *new_pipeline =
|
2020-03-03 15:31:50 -08:00
|
|
|
anv_pipeline_to_graphics(pipeline);
|
2023-10-26 17:17:22 +03:00
|
|
|
|
|
|
|
|
/* Apply the non dynamic state from the pipeline */
|
|
|
|
|
vk_cmd_set_dynamic_graphics_state(&cmd_buffer->vk,
|
|
|
|
|
&new_pipeline->dynamic_state);
|
|
|
|
|
|
2023-11-08 11:42:22 +02:00
|
|
|
if (cmd_buffer->state.gfx.base.pipeline == pipeline)
|
2019-11-07 11:28:47 -06:00
|
|
|
return;
|
|
|
|
|
|
2023-11-08 11:42:22 +02:00
|
|
|
struct anv_graphics_pipeline *old_pipeline =
|
|
|
|
|
cmd_buffer->state.gfx.base.pipeline == NULL ? NULL :
|
|
|
|
|
anv_pipeline_to_graphics(cmd_buffer->state.gfx.base.pipeline);
|
|
|
|
|
|
2023-03-20 16:35:46 +02:00
|
|
|
cmd_buffer->state.gfx.base.pipeline = pipeline;
|
2017-12-15 16:38:10 -08:00
|
|
|
cmd_buffer->state.gfx.dirty |= ANV_CMD_DIRTY_PIPELINE;
|
2019-11-07 11:28:47 -06:00
|
|
|
|
2023-08-02 11:36:39 +03:00
|
|
|
anv_foreach_stage(stage, new_pipeline->base.base.active_stages) {
|
2019-11-07 11:28:47 -06:00
|
|
|
set_dirty_for_bind_map(cmd_buffer, stage,
|
2023-08-02 11:36:39 +03:00
|
|
|
&new_pipeline->base.shaders[stage]->bind_map);
|
2019-11-07 11:28:47 -06:00
|
|
|
}
|
2015-10-07 09:28:21 -07:00
|
|
|
|
2021-06-08 16:24:54 +03:00
|
|
|
state = &cmd_buffer->state.gfx.base;
|
2023-08-02 11:36:39 +03:00
|
|
|
stages = new_pipeline->base.base.active_stages;
|
2023-03-22 16:29:58 +02:00
|
|
|
|
2022-04-06 18:12:02 +03:00
|
|
|
|
|
|
|
|
/* When the pipeline is using independent states and dynamic buffers,
|
|
|
|
|
* this will trigger an update of anv_push_constants::dynamic_base_index
|
|
|
|
|
* & anv_push_constants::dynamic_offsets.
|
|
|
|
|
*/
|
|
|
|
|
struct anv_push_constants *push =
|
|
|
|
|
&cmd_buffer->state.gfx.base.push_constants;
|
2023-08-02 11:36:39 +03:00
|
|
|
struct anv_pipeline_sets_layout *layout = &new_pipeline->base.base.layout;
|
2022-04-06 18:12:02 +03:00
|
|
|
if (layout->independent_sets && layout->num_dynamic_buffers > 0) {
|
|
|
|
|
bool modified = false;
|
|
|
|
|
for (uint32_t s = 0; s < layout->num_sets; s++) {
|
|
|
|
|
if (layout->set[s].layout == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
assert(layout->set[s].dynamic_offset_start < MAX_DYNAMIC_BUFFERS);
|
|
|
|
|
if (layout->set[s].layout->dynamic_offset_count > 0 &&
|
2023-10-20 17:33:21 +03:00
|
|
|
(push->desc_surface_offsets[s] & ANV_DESCRIPTOR_SET_DYNAMIC_INDEX_MASK) !=
|
|
|
|
|
layout->set[s].dynamic_offset_start) {
|
|
|
|
|
push->desc_surface_offsets[s] &= ~ANV_DESCRIPTOR_SET_DYNAMIC_INDEX_MASK;
|
|
|
|
|
push->desc_surface_offsets[s] |= (layout->set[s].dynamic_offset_start &
|
|
|
|
|
ANV_DESCRIPTOR_SET_DYNAMIC_INDEX_MASK);
|
2022-04-06 18:12:02 +03:00
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (modified)
|
|
|
|
|
cmd_buffer->state.push_constants_dirty |= stages;
|
|
|
|
|
}
|
2022-03-28 15:42:27 +03:00
|
|
|
|
2024-02-01 13:17:42 -08:00
|
|
|
if ((new_pipeline->fs_msaa_flags & INTEL_MSAA_FLAG_ENABLE_DYNAMIC) &&
|
2023-08-02 11:36:39 +03:00
|
|
|
push->gfx.fs_msaa_flags != new_pipeline->fs_msaa_flags) {
|
|
|
|
|
push->gfx.fs_msaa_flags = new_pipeline->fs_msaa_flags;
|
2022-03-28 15:42:27 +03:00
|
|
|
cmd_buffer->state.push_constants_dirty |= VK_SHADER_STAGE_FRAGMENT_BIT;
|
|
|
|
|
}
|
2023-08-02 11:36:39 +03:00
|
|
|
if (new_pipeline->dynamic_patch_control_points) {
|
2023-04-08 23:21:29 +03:00
|
|
|
cmd_buffer->state.push_constants_dirty |=
|
|
|
|
|
VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
|
|
|
|
|
}
|
2023-08-02 11:36:39 +03:00
|
|
|
|
|
|
|
|
anv_cmd_buffer_flush_pipeline_state(cmd_buffer, old_pipeline, new_pipeline);
|
2015-07-30 14:59:02 -07:00
|
|
|
break;
|
2020-03-03 15:31:50 -08:00
|
|
|
}
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2020-08-06 22:51:01 -05:00
|
|
|
case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR: {
|
2023-11-08 11:42:22 +02:00
|
|
|
if (cmd_buffer->state.rt.base.pipeline == pipeline)
|
2020-08-06 22:51:01 -05:00
|
|
|
return;
|
|
|
|
|
|
2023-03-20 16:35:46 +02:00
|
|
|
cmd_buffer->state.rt.base.pipeline = pipeline;
|
2020-08-06 22:51:01 -05:00
|
|
|
cmd_buffer->state.rt.pipeline_dirty = true;
|
2020-08-06 22:53:06 -05:00
|
|
|
|
2023-11-08 11:42:22 +02:00
|
|
|
struct anv_ray_tracing_pipeline *rt_pipeline =
|
|
|
|
|
anv_pipeline_to_ray_tracing(pipeline);
|
2020-08-06 22:53:06 -05:00
|
|
|
if (rt_pipeline->stack_size > 0) {
|
|
|
|
|
anv_CmdSetRayTracingPipelineStackSizeKHR(commandBuffer,
|
|
|
|
|
rt_pipeline->stack_size);
|
|
|
|
|
}
|
2021-06-08 16:24:54 +03:00
|
|
|
|
|
|
|
|
state = &cmd_buffer->state.rt.base;
|
2020-08-06 22:51:01 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
default:
|
2022-03-14 22:38:45 +02:00
|
|
|
unreachable("invalid bind point");
|
2015-07-30 14:59:02 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2021-06-08 16:24:54 +03:00
|
|
|
|
|
|
|
|
if (pipeline->ray_queries > 0)
|
|
|
|
|
anv_cmd_buffer_set_ray_query_buffer(cmd_buffer, state, pipeline, stages);
|
2015-07-15 12:09:52 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 13:47:53 -08:00
|
|
|
static void
|
|
|
|
|
anv_cmd_buffer_bind_descriptor_set(struct anv_cmd_buffer *cmd_buffer,
|
2017-12-15 14:02:27 -08:00
|
|
|
VkPipelineBindPoint bind_point,
|
2022-04-06 18:12:02 +03:00
|
|
|
struct anv_pipeline_sets_layout *layout,
|
2017-12-15 13:47:53 -08:00
|
|
|
uint32_t set_index,
|
|
|
|
|
struct anv_descriptor_set *set,
|
|
|
|
|
uint32_t *dynamic_offset_count,
|
|
|
|
|
const uint32_t **dynamic_offsets)
|
|
|
|
|
{
|
2022-03-04 12:52:04 +02:00
|
|
|
/* Either we have no pool because it's a push descriptor or the pool is not
|
|
|
|
|
* host only :
|
|
|
|
|
*
|
|
|
|
|
* VUID-vkCmdBindDescriptorSets-pDescriptorSets-04616:
|
|
|
|
|
*
|
|
|
|
|
* "Each element of pDescriptorSets must not have been allocated from a
|
|
|
|
|
* VkDescriptorPool with the
|
2022-09-06 21:18:17 +03:00
|
|
|
* VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_EXT flag set"
|
2022-03-04 12:52:04 +02:00
|
|
|
*/
|
|
|
|
|
assert(!set->pool || !set->pool->host_only);
|
|
|
|
|
|
2023-09-27 16:52:45 -07:00
|
|
|
struct anv_descriptor_set_layout *set_layout = set->layout;
|
2020-03-05 12:33:05 -08:00
|
|
|
VkShaderStageFlags stages = set_layout->shader_stages;
|
|
|
|
|
struct anv_cmd_pipeline_state *pipe_state;
|
|
|
|
|
|
|
|
|
|
switch (bind_point) {
|
|
|
|
|
case VK_PIPELINE_BIND_POINT_GRAPHICS:
|
2021-07-12 13:46:31 +02:00
|
|
|
stages &= VK_SHADER_STAGE_ALL_GRAPHICS |
|
2023-07-10 14:02:28 +02:00
|
|
|
(cmd_buffer->device->vk.enabled_extensions.EXT_mesh_shader ?
|
2022-05-08 02:24:48 +02:00
|
|
|
(VK_SHADER_STAGE_TASK_BIT_EXT |
|
|
|
|
|
VK_SHADER_STAGE_MESH_BIT_EXT) : 0);
|
2020-03-05 12:33:05 -08:00
|
|
|
pipe_state = &cmd_buffer->state.gfx.base;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VK_PIPELINE_BIND_POINT_COMPUTE:
|
|
|
|
|
stages &= VK_SHADER_STAGE_COMPUTE_BIT;
|
|
|
|
|
pipe_state = &cmd_buffer->state.compute.base;
|
|
|
|
|
break;
|
|
|
|
|
|
2020-08-06 22:51:01 -05:00
|
|
|
case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR:
|
|
|
|
|
stages &= VK_SHADER_STAGE_RAYGEN_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_ANY_HIT_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_MISS_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_INTERSECTION_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_CALLABLE_BIT_KHR;
|
|
|
|
|
pipe_state = &cmd_buffer->state.rt.base;
|
|
|
|
|
break;
|
|
|
|
|
|
2020-03-05 12:33:05 -08:00
|
|
|
default:
|
|
|
|
|
unreachable("invalid bind point");
|
|
|
|
|
}
|
2019-11-07 11:44:08 -06:00
|
|
|
|
|
|
|
|
VkShaderStageFlags dirty_stages = 0;
|
2021-06-28 13:06:07 +02:00
|
|
|
/* If it's a push descriptor set, we have to flag things as dirty
|
|
|
|
|
* regardless of whether or not the CPU-side data structure changed as we
|
|
|
|
|
* may have edited in-place.
|
|
|
|
|
*/
|
|
|
|
|
if (pipe_state->descriptors[set_index] != set ||
|
|
|
|
|
anv_descriptor_set_is_push(set)) {
|
2020-03-05 12:33:05 -08:00
|
|
|
pipe_state->descriptors[set_index] = set;
|
2021-01-21 14:13:47 -06:00
|
|
|
|
2023-02-27 17:02:11 +02:00
|
|
|
/* When using indirect descriptors, stages that have access to the HW
|
|
|
|
|
* binding tables, never need to access the
|
2023-10-20 17:33:21 +03:00
|
|
|
* anv_push_constants::desc_surface_offsets fields, because any data
|
|
|
|
|
* they need from the descriptor buffer is accessible through a binding
|
|
|
|
|
* table entry. For stages that are "bindless" (Mesh/Task/RT), we need
|
|
|
|
|
* to provide anv_push_constants::desc_surface_offsets matching the bound
|
2023-02-27 17:02:11 +02:00
|
|
|
* descriptor so that shaders can access the descriptor buffer through
|
|
|
|
|
* A64 messages.
|
|
|
|
|
*
|
|
|
|
|
* With direct descriptors, the shaders can use the
|
2023-10-20 17:33:21 +03:00
|
|
|
* anv_push_constants::desc_surface_offsets to build bindless offsets.
|
|
|
|
|
* So it's we always need to update the push constant data.
|
2021-01-21 14:13:47 -06:00
|
|
|
*/
|
2023-02-27 17:02:11 +02:00
|
|
|
bool update_desc_sets =
|
|
|
|
|
!cmd_buffer->device->physical->indirect_descriptors ||
|
|
|
|
|
(stages & (VK_SHADER_STAGE_TASK_BIT_EXT |
|
|
|
|
|
VK_SHADER_STAGE_MESH_BIT_EXT |
|
|
|
|
|
VK_SHADER_STAGE_RAYGEN_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_ANY_HIT_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_MISS_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_INTERSECTION_BIT_KHR |
|
|
|
|
|
VK_SHADER_STAGE_CALLABLE_BIT_KHR));
|
2021-07-12 13:46:31 +02:00
|
|
|
|
|
|
|
|
if (update_desc_sets) {
|
2021-01-21 14:13:47 -06:00
|
|
|
struct anv_push_constants *push = &pipe_state->push_constants;
|
|
|
|
|
|
2023-02-27 17:02:11 +02:00
|
|
|
uint64_t offset =
|
2023-10-20 17:33:21 +03:00
|
|
|
anv_address_physical(set->desc_surface_addr) -
|
|
|
|
|
cmd_buffer->device->physical->va.internal_surface_state_pool.addr;
|
2023-03-15 16:10:25 +02:00
|
|
|
assert((offset & ~ANV_DESCRIPTOR_SET_OFFSET_MASK) == 0);
|
2023-10-20 17:33:21 +03:00
|
|
|
push->desc_surface_offsets[set_index] &= ~ANV_DESCRIPTOR_SET_OFFSET_MASK;
|
|
|
|
|
push->desc_surface_offsets[set_index] |= offset;
|
|
|
|
|
push->desc_sampler_offsets[set_index] |=
|
|
|
|
|
anv_address_physical(set->desc_sampler_addr) -
|
|
|
|
|
cmd_buffer->device->physical->va.dynamic_state_pool.addr;
|
|
|
|
|
|
|
|
|
|
anv_reloc_list_add_bo(cmd_buffer->batch.relocs,
|
|
|
|
|
set->desc_surface_addr.bo);
|
|
|
|
|
anv_reloc_list_add_bo(cmd_buffer->batch.relocs,
|
|
|
|
|
set->desc_sampler_addr.bo);
|
2021-01-21 14:13:47 -06:00
|
|
|
}
|
|
|
|
|
|
2020-03-05 12:33:05 -08:00
|
|
|
dirty_stages |= stages;
|
2017-12-15 14:02:27 -08:00
|
|
|
}
|
2019-11-07 11:44:08 -06:00
|
|
|
|
2017-12-15 13:47:53 -08:00
|
|
|
if (dynamic_offsets) {
|
|
|
|
|
if (set_layout->dynamic_offset_count > 0) {
|
2020-08-04 17:25:37 +03:00
|
|
|
struct anv_push_constants *push = &pipe_state->push_constants;
|
2017-12-15 13:47:53 -08:00
|
|
|
uint32_t dynamic_offset_start =
|
|
|
|
|
layout->set[set_index].dynamic_offset_start;
|
2020-08-04 17:25:37 +03:00
|
|
|
uint32_t *push_offsets =
|
|
|
|
|
&push->dynamic_offsets[dynamic_offset_start];
|
|
|
|
|
|
2022-04-06 18:12:02 +03:00
|
|
|
memcpy(pipe_state->dynamic_offsets[set_index].offsets,
|
|
|
|
|
*dynamic_offsets,
|
|
|
|
|
sizeof(uint32_t) * MIN2(*dynamic_offset_count,
|
|
|
|
|
set_layout->dynamic_offset_count));
|
|
|
|
|
|
2020-08-04 17:25:37 +03:00
|
|
|
/* Assert that everything is in range */
|
|
|
|
|
assert(set_layout->dynamic_offset_count <= *dynamic_offset_count);
|
|
|
|
|
assert(dynamic_offset_start + set_layout->dynamic_offset_count <=
|
|
|
|
|
ARRAY_SIZE(push->dynamic_offsets));
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < set_layout->dynamic_offset_count; i++) {
|
|
|
|
|
if (push_offsets[i] != (*dynamic_offsets)[i]) {
|
2022-04-06 18:12:02 +03:00
|
|
|
pipe_state->dynamic_offsets[set_index].offsets[i] =
|
|
|
|
|
push_offsets[i] = (*dynamic_offsets)[i];
|
2020-08-04 17:25:37 +03:00
|
|
|
/* dynamic_offset_stages[] elements could contain blanket
|
|
|
|
|
* values like VK_SHADER_STAGE_ALL, so limit this to the
|
|
|
|
|
* binding point's bits.
|
|
|
|
|
*/
|
|
|
|
|
dirty_stages |= set_layout->dynamic_offset_stages[i] & stages;
|
2019-11-07 11:44:08 -06:00
|
|
|
}
|
2019-11-06 10:59:15 -06:00
|
|
|
}
|
2017-12-15 13:47:53 -08:00
|
|
|
|
|
|
|
|
*dynamic_offsets += set_layout->dynamic_offset_count;
|
|
|
|
|
*dynamic_offset_count -= set_layout->dynamic_offset_count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
anv: reduce BT emissions & surface state writes with push descriptors
Zink on Anv running Gfxbench gl_driver2 is significantly slower than
Iris.
The reason is simple, whereas Iris implements uniform updates using
push constants and only has to emit 3DSTATE_CONSTANT_* packets, Zink
uses push descriptors with a uniform buffer, which on our
implementation use both push constants & binding tables.
Anv ends up doing the following for each uniform update :
- allocate 2 surface states :
- one for the uniform buffer as the offset specify by zink
- one for the descriptor set buffer
- pack the 2 RENDER_SURFACE_STATE
- re-emit binding tables
- re-emit push constants
Of all of those operations, only the last one ends up being useful in
this benchmark because all the uniforms have been promoted to push
constants.
This change defers the 3 first operations at draw time and executes
them only if the pipeline needs them.
Vkoverhead before / after :
descriptor_template_1ubo_push: 40670 / 85786
descriptor_template_12ubo_push: 4050 / 13820
descriptor_template_1combined_sampler_push, 34410 / 34043
descriptor_template_16combined_sampler_push, 2746 / 2711
descriptor_template_1sampled_image_push, 34765 / 34089
descriptor_template_16sampled_image_push, 2794 / 2649
descriptor_template_1texelbuffer_push, 108537 / 111342
descriptor_template_16texelbuffer_push, 20619 / 20166
descriptor_template_1ssbo_push, 41506 / 85976
descriptor_template_8ssbo_push, 6036 / 18703
descriptor_template_1image_push, 88932 / 89610
descriptor_template_16image_push, 20937 / 20959
descriptor_template_1imagebuffer_push, 108407 / 113240
descriptor_template_16imagebuffer_push, 32661 / 34651
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19050>
2022-10-02 19:24:40 +03:00
|
|
|
if (set->is_push)
|
|
|
|
|
cmd_buffer->state.push_descriptors_dirty |= dirty_stages;
|
|
|
|
|
else
|
|
|
|
|
cmd_buffer->state.descriptors_dirty |= dirty_stages;
|
2019-11-07 11:44:08 -06:00
|
|
|
cmd_buffer->state.push_constants_dirty |= dirty_stages;
|
2017-12-15 13:47:53 -08:00
|
|
|
}
|
|
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
#define ANV_GRAPHICS_STAGE_BITS \
|
|
|
|
|
(VK_SHADER_STAGE_ALL_GRAPHICS | \
|
|
|
|
|
VK_SHADER_STAGE_MESH_BIT_EXT | \
|
|
|
|
|
VK_SHADER_STAGE_TASK_BIT_EXT)
|
|
|
|
|
|
|
|
|
|
#define ANV_RT_STAGE_BITS \
|
|
|
|
|
(VK_SHADER_STAGE_RAYGEN_BIT_KHR | \
|
|
|
|
|
VK_SHADER_STAGE_ANY_HIT_BIT_KHR | \
|
|
|
|
|
VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | \
|
|
|
|
|
VK_SHADER_STAGE_MISS_BIT_KHR | \
|
|
|
|
|
VK_SHADER_STAGE_INTERSECTION_BIT_KHR | \
|
|
|
|
|
VK_SHADER_STAGE_CALLABLE_BIT_KHR)
|
|
|
|
|
|
|
|
|
|
void anv_CmdBindDescriptorSets2KHR(
|
2015-11-30 11:48:08 -08:00
|
|
|
VkCommandBuffer commandBuffer,
|
2023-09-21 15:20:10 -07:00
|
|
|
const VkBindDescriptorSetsInfoKHR* pInfo)
|
2015-07-15 12:09:52 -07:00
|
|
|
{
|
2015-11-30 11:48:08 -08:00
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
2023-09-21 15:20:10 -07:00
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, pipeline_layout, pInfo->layout);
|
2022-04-06 18:12:02 +03:00
|
|
|
struct anv_pipeline_sets_layout *layout = &pipeline_layout->sets_layout;
|
2015-07-15 12:09:52 -07:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
assert(pInfo->firstSet + pInfo->descriptorSetCount <= MAX_SETS);
|
|
|
|
|
|
|
|
|
|
if (pInfo->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) {
|
|
|
|
|
uint32_t dynamicOffsetCount = pInfo->dynamicOffsetCount;
|
|
|
|
|
const uint32_t *pDynamicOffsets = pInfo->pDynamicOffsets;
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < pInfo->descriptorSetCount; i++) {
|
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, set, pInfo->pDescriptorSets[i]);
|
|
|
|
|
if (set == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
anv_cmd_buffer_bind_descriptor_set(cmd_buffer,
|
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
|
|
|
|
layout, pInfo->firstSet + i, set,
|
|
|
|
|
&dynamicOffsetCount,
|
|
|
|
|
&pDynamicOffsets);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (pInfo->stageFlags & ANV_GRAPHICS_STAGE_BITS) {
|
|
|
|
|
uint32_t dynamicOffsetCount = pInfo->dynamicOffsetCount;
|
|
|
|
|
const uint32_t *pDynamicOffsets = pInfo->pDynamicOffsets;
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < pInfo->descriptorSetCount; i++) {
|
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, set, pInfo->pDescriptorSets[i]);
|
|
|
|
|
if (set == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
anv_cmd_buffer_bind_descriptor_set(cmd_buffer,
|
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
|
layout, pInfo->firstSet + i, set,
|
|
|
|
|
&dynamicOffsetCount,
|
|
|
|
|
&pDynamicOffsets);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (pInfo->stageFlags & ANV_RT_STAGE_BITS) {
|
|
|
|
|
uint32_t dynamicOffsetCount = pInfo->dynamicOffsetCount;
|
|
|
|
|
const uint32_t *pDynamicOffsets = pInfo->pDynamicOffsets;
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < pInfo->descriptorSetCount; i++) {
|
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, set, pInfo->pDescriptorSets[i]);
|
|
|
|
|
if (set == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
anv_cmd_buffer_bind_descriptor_set(cmd_buffer,
|
|
|
|
|
VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR,
|
|
|
|
|
layout, pInfo->firstSet + i, set,
|
|
|
|
|
&dynamicOffsetCount,
|
|
|
|
|
&pDynamicOffsets);
|
|
|
|
|
}
|
2015-07-30 14:59:02 -07:00
|
|
|
}
|
2015-07-15 12:09:52 -07:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 13:06:43 +03:00
|
|
|
void anv_CmdBindVertexBuffers2(
|
2020-06-02 10:02:25 +03:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
|
uint32_t firstBinding,
|
|
|
|
|
uint32_t bindingCount,
|
|
|
|
|
const VkBuffer* pBuffers,
|
|
|
|
|
const VkDeviceSize* pOffsets,
|
|
|
|
|
const VkDeviceSize* pSizes,
|
|
|
|
|
const VkDeviceSize* pStrides)
|
2015-07-30 14:59:02 -07:00
|
|
|
{
|
2015-11-30 11:48:08 -08:00
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
2015-07-30 14:59:02 -07:00
|
|
|
struct anv_vertex_binding *vb = cmd_buffer->state.vertex_bindings;
|
2015-07-29 11:57:44 -07:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
/* We have to defer setting up vertex buffer since we need the buffer
|
|
|
|
|
* stride from the pipeline. */
|
2015-07-29 11:57:44 -07:00
|
|
|
|
2017-07-19 12:49:33 +02:00
|
|
|
assert(firstBinding + bindingCount <= MAX_VBS);
|
2015-07-30 14:59:02 -07:00
|
|
|
for (uint32_t i = 0; i < bindingCount; i++) {
|
2022-07-05 05:06:27 -05:00
|
|
|
ANV_FROM_HANDLE(anv_buffer, buffer, pBuffers[i]);
|
|
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
|
vb[firstBinding + i] = (struct anv_vertex_binding) {
|
|
|
|
|
.buffer = NULL,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
vb[firstBinding + i] = (struct anv_vertex_binding) {
|
|
|
|
|
.buffer = buffer,
|
|
|
|
|
.offset = pOffsets[i],
|
|
|
|
|
.size = vk_buffer_range(&buffer->vk, pOffsets[i],
|
|
|
|
|
pSizes ? pSizes[i] : VK_WHOLE_SIZE),
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-12-15 16:39:53 -08:00
|
|
|
cmd_buffer->state.gfx.vb_dirty |= 1 << (firstBinding + i);
|
2015-07-30 14:59:02 -07:00
|
|
|
}
|
2022-07-14 15:09:46 -05:00
|
|
|
|
|
|
|
|
if (pStrides != NULL) {
|
|
|
|
|
vk_cmd_set_vertex_binding_strides(&cmd_buffer->vk, firstBinding,
|
|
|
|
|
bindingCount, pStrides);
|
|
|
|
|
}
|
2015-07-15 12:09:52 -07:00
|
|
|
}
|
|
|
|
|
|
2018-09-10 16:17:37 -05:00
|
|
|
void anv_CmdBindTransformFeedbackBuffersEXT(
|
|
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
|
uint32_t firstBinding,
|
|
|
|
|
uint32_t bindingCount,
|
|
|
|
|
const VkBuffer* pBuffers,
|
|
|
|
|
const VkDeviceSize* pOffsets,
|
|
|
|
|
const VkDeviceSize* pSizes)
|
|
|
|
|
{
|
|
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
|
|
|
|
struct anv_xfb_binding *xfb = cmd_buffer->state.xfb_bindings;
|
|
|
|
|
|
|
|
|
|
/* We have to defer setting up vertex buffer since we need the buffer
|
|
|
|
|
* stride from the pipeline. */
|
|
|
|
|
|
|
|
|
|
assert(firstBinding + bindingCount <= MAX_XFB_BUFFERS);
|
|
|
|
|
for (uint32_t i = 0; i < bindingCount; i++) {
|
|
|
|
|
if (pBuffers[i] == VK_NULL_HANDLE) {
|
|
|
|
|
xfb[firstBinding + i].buffer = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
ANV_FROM_HANDLE(anv_buffer, buffer, pBuffers[i]);
|
|
|
|
|
xfb[firstBinding + i].buffer = buffer;
|
|
|
|
|
xfb[firstBinding + i].offset = pOffsets[i];
|
|
|
|
|
xfb[firstBinding + i].size =
|
2022-05-19 09:00:30 -05:00
|
|
|
vk_buffer_range(&buffer->vk, pOffsets[i],
|
|
|
|
|
pSizes ? pSizes[i] : VK_WHOLE_SIZE);
|
2018-09-10 16:17:37 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-13 12:38:12 -07:00
|
|
|
enum isl_format
|
2020-02-21 12:35:27 -06:00
|
|
|
anv_isl_format_for_descriptor_type(const struct anv_device *device,
|
|
|
|
|
VkDescriptorType type)
|
2015-11-06 15:14:10 -08:00
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
2020-02-21 11:45:37 -06:00
|
|
|
return device->physical->compiler->indirect_ubos_use_sampler ?
|
|
|
|
|
ISL_FORMAT_R32G32B32A32_FLOAT : ISL_FORMAT_RAW;
|
2015-11-06 15:14:10 -08:00
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
2016-05-13 12:38:12 -07:00
|
|
|
return ISL_FORMAT_RAW;
|
2015-11-06 15:14:10 -08:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Invalid descriptor type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-17 16:17:07 -07:00
|
|
|
struct anv_state
|
2015-07-30 14:59:02 -07:00
|
|
|
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
|
2015-12-01 15:37:12 -08:00
|
|
|
const void *data, uint32_t size, uint32_t alignment)
|
2015-07-29 11:57:44 -07:00
|
|
|
{
|
2015-07-30 14:59:02 -07:00
|
|
|
struct anv_state state;
|
|
|
|
|
|
2015-12-01 15:37:12 -08:00
|
|
|
state = anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, size, alignment);
|
|
|
|
|
memcpy(state.map, data, size);
|
|
|
|
|
|
|
|
|
|
VG(VALGRIND_CHECK_MEM_IS_DEFINED(state.map, size));
|
2015-07-30 14:59:02 -07:00
|
|
|
|
|
|
|
|
return state;
|
2015-07-29 11:57:44 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-17 16:17:07 -07:00
|
|
|
struct anv_state
|
2015-07-30 14:59:02 -07:00
|
|
|
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
uint32_t *a, uint32_t *b,
|
|
|
|
|
uint32_t dwords, uint32_t alignment)
|
2015-07-30 11:34:58 -07:00
|
|
|
{
|
2015-07-30 14:59:02 -07:00
|
|
|
struct anv_state state;
|
|
|
|
|
uint32_t *p;
|
2015-07-30 11:34:58 -07:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
state = anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
|
|
|
|
|
dwords * 4, alignment);
|
|
|
|
|
p = state.map;
|
|
|
|
|
for (uint32_t i = 0; i < dwords; i++)
|
|
|
|
|
p[i] = a[i] | b[i];
|
2015-07-30 11:34:58 -07:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
VG(VALGRIND_CHECK_MEM_IS_DEFINED(p, dwords * 4));
|
2015-07-30 11:34:58 -07:00
|
|
|
|
2015-07-30 14:59:02 -07:00
|
|
|
return state;
|
2015-07-30 11:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-26 17:57:51 -07:00
|
|
|
struct anv_state
|
2020-08-04 17:25:37 +03:00
|
|
|
anv_cmd_buffer_gfx_push_constants(struct anv_cmd_buffer *cmd_buffer)
|
2015-08-26 17:57:51 -07:00
|
|
|
{
|
2015-09-11 10:25:21 -07:00
|
|
|
struct anv_push_constants *data =
|
2020-08-04 17:25:37 +03:00
|
|
|
&cmd_buffer->state.gfx.base.push_constants;
|
2015-08-26 17:57:51 -07:00
|
|
|
|
|
|
|
|
struct anv_state state =
|
|
|
|
|
anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
|
2019-11-07 17:16:14 -06:00
|
|
|
sizeof(struct anv_push_constants),
|
2015-08-26 17:57:51 -07:00
|
|
|
32 /* bottom 5 bits MBZ */);
|
2019-11-07 17:16:14 -06:00
|
|
|
memcpy(state.map, data, sizeof(struct anv_push_constants));
|
2015-08-26 17:57:51 -07:00
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-08 16:56:26 -08:00
|
|
|
struct anv_state
|
|
|
|
|
anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
2022-08-04 12:56:17 -07:00
|
|
|
const struct intel_device_info *devinfo = cmd_buffer->device->info;
|
2022-04-06 18:12:02 +03:00
|
|
|
struct anv_cmd_pipeline_state *pipe_state = &cmd_buffer->state.compute.base;
|
|
|
|
|
struct anv_push_constants *data = &pipe_state->push_constants;
|
2023-11-08 11:42:22 +02:00
|
|
|
struct anv_compute_pipeline *pipeline =
|
|
|
|
|
anv_pipeline_to_compute(cmd_buffer->state.compute.base.pipeline);
|
2016-03-04 08:15:16 -08:00
|
|
|
const struct brw_cs_prog_data *cs_prog_data = get_cs_prog_data(pipeline);
|
2020-03-03 13:43:39 -08:00
|
|
|
const struct anv_push_range *range = &pipeline->cs->bind_map.push_ranges[0];
|
2015-12-08 16:56:26 -08:00
|
|
|
|
2024-02-01 16:02:50 -08:00
|
|
|
const struct intel_cs_dispatch_info dispatch =
|
2021-04-28 10:56:58 -07:00
|
|
|
brw_cs_get_dispatch_info(devinfo, cs_prog_data, NULL);
|
2020-03-20 21:02:06 -07:00
|
|
|
const unsigned total_push_constants_size =
|
2021-04-28 10:56:58 -07:00
|
|
|
brw_cs_push_const_total_size(cs_prog_data, dispatch.threads);
|
2020-03-20 21:02:06 -07:00
|
|
|
if (total_push_constants_size == 0)
|
2015-12-08 16:56:26 -08:00
|
|
|
return (struct anv_state) { .offset = 0 };
|
|
|
|
|
|
2022-08-30 14:50:51 -07:00
|
|
|
const unsigned push_constant_alignment = 64;
|
2015-12-14 15:24:11 -08:00
|
|
|
const unsigned aligned_total_push_constants_size =
|
2020-03-20 21:02:06 -07:00
|
|
|
ALIGN(total_push_constants_size, push_constant_alignment);
|
2020-05-04 18:08:35 -05:00
|
|
|
struct anv_state state;
|
2021-03-29 13:43:47 -07:00
|
|
|
if (devinfo->verx10 >= 125) {
|
2020-05-04 18:08:35 -05:00
|
|
|
state = anv_state_stream_alloc(&cmd_buffer->general_state_stream,
|
|
|
|
|
aligned_total_push_constants_size,
|
|
|
|
|
push_constant_alignment);
|
|
|
|
|
} else {
|
|
|
|
|
state = anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
|
|
|
|
|
aligned_total_push_constants_size,
|
|
|
|
|
push_constant_alignment);
|
|
|
|
|
}
|
2023-10-12 09:28:43 +03:00
|
|
|
if (state.map == NULL)
|
|
|
|
|
return state;
|
2015-12-08 16:56:26 -08:00
|
|
|
|
2019-11-07 17:16:14 -06:00
|
|
|
void *dst = state.map;
|
|
|
|
|
const void *src = (char *)data + (range->start * 32);
|
2015-12-08 16:56:26 -08:00
|
|
|
|
2016-05-27 00:53:27 -07:00
|
|
|
if (cs_prog_data->push.cross_thread.size > 0) {
|
2019-11-07 17:16:14 -06:00
|
|
|
memcpy(dst, src, cs_prog_data->push.cross_thread.size);
|
|
|
|
|
dst += cs_prog_data->push.cross_thread.size;
|
|
|
|
|
src += cs_prog_data->push.cross_thread.size;
|
2015-12-08 16:56:26 -08:00
|
|
|
}
|
|
|
|
|
|
2016-05-27 00:53:27 -07:00
|
|
|
if (cs_prog_data->push.per_thread.size > 0) {
|
2021-04-28 10:56:58 -07:00
|
|
|
for (unsigned t = 0; t < dispatch.threads; t++) {
|
2019-11-07 17:16:14 -06:00
|
|
|
memcpy(dst, src, cs_prog_data->push.per_thread.size);
|
|
|
|
|
|
|
|
|
|
uint32_t *subgroup_id = dst +
|
|
|
|
|
offsetof(struct anv_push_constants, cs.subgroup_id) -
|
|
|
|
|
(range->start * 32 + cs_prog_data->push.cross_thread.size);
|
|
|
|
|
*subgroup_id = t;
|
|
|
|
|
|
|
|
|
|
dst += cs_prog_data->push.per_thread.size;
|
2016-05-27 00:53:27 -07:00
|
|
|
}
|
2015-12-08 16:56:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
void anv_CmdPushConstants2KHR(
|
2015-11-30 11:48:08 -08:00
|
|
|
VkCommandBuffer commandBuffer,
|
2023-09-21 15:20:10 -07:00
|
|
|
const VkPushConstantsInfoKHR* pInfo)
|
2015-07-30 11:36:48 -07:00
|
|
|
{
|
2015-11-30 11:48:08 -08:00
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
2015-08-26 15:01:38 -07:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
if (pInfo->stageFlags & ANV_GRAPHICS_STAGE_BITS) {
|
2020-08-04 17:25:37 +03:00
|
|
|
struct anv_cmd_pipeline_state *pipe_state =
|
|
|
|
|
&cmd_buffer->state.gfx.base;
|
|
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
memcpy(pipe_state->push_constants.client_data + pInfo->offset,
|
|
|
|
|
pInfo->pValues, pInfo->size);
|
2020-08-04 17:25:37 +03:00
|
|
|
}
|
2023-09-21 15:20:10 -07:00
|
|
|
if (pInfo->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) {
|
2020-08-04 17:25:37 +03:00
|
|
|
struct anv_cmd_pipeline_state *pipe_state =
|
|
|
|
|
&cmd_buffer->state.compute.base;
|
|
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
memcpy(pipe_state->push_constants.client_data + pInfo->offset,
|
|
|
|
|
pInfo->pValues, pInfo->size);
|
2015-08-26 15:01:38 -07:00
|
|
|
}
|
2023-09-21 15:20:10 -07:00
|
|
|
if (pInfo->stageFlags & ANV_RT_STAGE_BITS) {
|
2020-08-06 22:51:01 -05:00
|
|
|
struct anv_cmd_pipeline_state *pipe_state =
|
|
|
|
|
&cmd_buffer->state.rt.base;
|
|
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
memcpy(pipe_state->push_constants.client_data + pInfo->offset,
|
|
|
|
|
pInfo->pValues, pInfo->size);
|
2020-08-06 22:51:01 -05:00
|
|
|
}
|
2015-08-26 15:01:38 -07:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
cmd_buffer->state.push_constants_dirty |= pInfo->stageFlags;
|
2015-07-30 14:59:02 -07:00
|
|
|
}
|
2015-07-30 11:36:48 -07:00
|
|
|
|
2023-10-07 00:42:11 +03:00
|
|
|
static struct anv_cmd_pipeline_state *
|
|
|
|
|
anv_cmd_buffer_get_pipe_state(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
VkPipelineBindPoint bind_point)
|
2017-09-27 14:16:04 +01:00
|
|
|
{
|
2020-08-06 22:51:01 -05:00
|
|
|
switch (bind_point) {
|
|
|
|
|
case VK_PIPELINE_BIND_POINT_GRAPHICS:
|
2023-10-07 00:42:11 +03:00
|
|
|
return &cmd_buffer->state.gfx.base;
|
2020-08-06 22:51:01 -05:00
|
|
|
case VK_PIPELINE_BIND_POINT_COMPUTE:
|
2023-10-07 00:42:11 +03:00
|
|
|
return &cmd_buffer->state.compute.base;
|
2020-08-06 22:51:01 -05:00
|
|
|
case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR:
|
2023-10-07 00:42:11 +03:00
|
|
|
return &cmd_buffer->state.rt.base;
|
2020-08-06 22:51:01 -05:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
unreachable("invalid bind point");
|
2017-12-15 14:02:27 -08:00
|
|
|
}
|
2023-10-07 00:42:11 +03:00
|
|
|
}
|
2017-12-15 14:02:27 -08:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
static void
|
|
|
|
|
anv_cmd_buffer_push_descriptor_sets(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
VkPipelineBindPoint bind_point,
|
|
|
|
|
const VkPushDescriptorSetInfoKHR *pInfo)
|
2017-01-12 16:12:46 +00:00
|
|
|
{
|
2023-09-21 15:20:10 -07:00
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, pipeline_layout, pInfo->layout);
|
2022-04-06 18:12:02 +03:00
|
|
|
struct anv_pipeline_sets_layout *layout = &pipeline_layout->sets_layout;
|
2017-01-12 16:12:46 +00:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
assert(pInfo->set < MAX_SETS);
|
2017-01-12 16:12:46 +00:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
struct anv_descriptor_set_layout *set_layout = layout->set[pInfo->set].layout;
|
2017-09-27 14:16:04 +01:00
|
|
|
|
2023-10-07 00:42:11 +03:00
|
|
|
struct anv_push_descriptor_set *push_set =
|
|
|
|
|
&anv_cmd_buffer_get_pipe_state(cmd_buffer,
|
2023-09-21 15:20:10 -07:00
|
|
|
bind_point)->push_descriptor;
|
2023-10-12 09:28:43 +03:00
|
|
|
if (!anv_push_descriptor_set_init(cmd_buffer, push_set, set_layout))
|
|
|
|
|
return;
|
2017-12-15 12:33:34 -08:00
|
|
|
|
2023-10-09 15:23:07 -07:00
|
|
|
anv_descriptor_set_write(cmd_buffer->device, &push_set->set,
|
2023-09-21 15:20:10 -07:00
|
|
|
pInfo->descriptorWriteCount,
|
|
|
|
|
pInfo->pDescriptorWrites);
|
2017-01-12 16:12:46 +00:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
anv_cmd_buffer_bind_descriptor_set(cmd_buffer, bind_point,
|
|
|
|
|
layout, pInfo->set, &push_set->set,
|
2023-10-07 00:42:11 +03:00
|
|
|
NULL, NULL);
|
2017-01-12 16:12:46 +00:00
|
|
|
}
|
2017-01-17 16:38:01 +00:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
void anv_CmdPushDescriptorSet2KHR(
|
|
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
|
const VkPushDescriptorSetInfoKHR* pInfo)
|
|
|
|
|
{
|
|
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
|
|
|
|
|
|
|
|
|
if (pInfo->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT)
|
|
|
|
|
anv_cmd_buffer_push_descriptor_sets(cmd_buffer,
|
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
|
|
|
|
pInfo);
|
|
|
|
|
if (pInfo->stageFlags & ANV_GRAPHICS_STAGE_BITS)
|
|
|
|
|
anv_cmd_buffer_push_descriptor_sets(cmd_buffer,
|
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
|
pInfo);
|
|
|
|
|
if (pInfo->stageFlags & ANV_RT_STAGE_BITS)
|
|
|
|
|
anv_cmd_buffer_push_descriptor_sets(cmd_buffer,
|
|
|
|
|
VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR,
|
|
|
|
|
pInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void anv_CmdPushDescriptorSetWithTemplate2KHR(
|
|
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
|
const VkPushDescriptorSetWithTemplateInfoKHR* pInfo)
|
2017-01-17 16:38:01 +00:00
|
|
|
{
|
|
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
2022-01-28 13:20:05 -06:00
|
|
|
VK_FROM_HANDLE(vk_descriptor_update_template, template,
|
2023-09-21 15:20:10 -07:00
|
|
|
pInfo->descriptorUpdateTemplate);
|
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, pipeline_layout, pInfo->layout);
|
2022-04-06 18:12:02 +03:00
|
|
|
struct anv_pipeline_sets_layout *layout = &pipeline_layout->sets_layout;
|
2017-01-17 16:38:01 +00:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
assert(pInfo->set < MAX_PUSH_DESCRIPTORS);
|
2017-01-17 16:38:01 +00:00
|
|
|
|
2023-09-21 15:20:10 -07:00
|
|
|
struct anv_descriptor_set_layout *set_layout = layout->set[pInfo->set].layout;
|
2017-09-27 14:16:04 +01:00
|
|
|
|
2023-10-07 00:42:11 +03:00
|
|
|
struct anv_push_descriptor_set *push_set =
|
|
|
|
|
&anv_cmd_buffer_get_pipe_state(cmd_buffer,
|
|
|
|
|
template->bind_point)->push_descriptor;
|
2023-10-12 09:28:43 +03:00
|
|
|
if (!anv_push_descriptor_set_init(cmd_buffer, push_set, set_layout))
|
|
|
|
|
return;
|
2017-12-15 12:33:34 -08:00
|
|
|
|
2023-10-07 00:42:11 +03:00
|
|
|
anv_descriptor_set_write_template(cmd_buffer->device, &push_set->set,
|
2017-01-17 16:38:01 +00:00
|
|
|
template,
|
2023-09-21 15:20:10 -07:00
|
|
|
pInfo->pData);
|
2017-01-17 16:38:01 +00:00
|
|
|
|
2017-12-15 14:02:27 -08:00
|
|
|
anv_cmd_buffer_bind_descriptor_set(cmd_buffer, template->bind_point,
|
2023-09-21 15:20:10 -07:00
|
|
|
layout, pInfo->set, &push_set->set,
|
2023-10-07 00:42:11 +03:00
|
|
|
NULL, NULL);
|
2017-01-17 16:38:01 +00:00
|
|
|
}
|
2017-09-21 13:54:55 -07:00
|
|
|
|
2020-08-05 16:53:12 -05:00
|
|
|
void anv_CmdSetRayTracingPipelineStackSizeKHR(
|
|
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
|
uint32_t pipelineStackSize)
|
|
|
|
|
{
|
2020-08-06 22:53:06 -05:00
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
|
|
|
|
struct anv_cmd_ray_tracing_state *rt = &cmd_buffer->state.rt;
|
|
|
|
|
struct anv_device *device = cmd_buffer->device;
|
|
|
|
|
|
|
|
|
|
if (anv_batch_has_error(&cmd_buffer->batch))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uint32_t stack_ids_per_dss = 2048; /* TODO */
|
|
|
|
|
|
2022-11-16 20:34:24 +02:00
|
|
|
unsigned stack_size_log2 = util_logbase2_ceil(pipelineStackSize);
|
2020-08-06 22:53:06 -05:00
|
|
|
if (stack_size_log2 < 10)
|
|
|
|
|
stack_size_log2 = 10;
|
|
|
|
|
|
|
|
|
|
if (rt->scratch.layout.total_size == 1 << stack_size_log2)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-08-04 12:56:17 -07:00
|
|
|
brw_rt_compute_scratch_layout(&rt->scratch.layout, device->info,
|
2020-08-06 22:53:06 -05:00
|
|
|
stack_ids_per_dss, 1 << stack_size_log2);
|
|
|
|
|
|
|
|
|
|
unsigned bucket = stack_size_log2 - 10;
|
|
|
|
|
assert(bucket < ARRAY_SIZE(device->rt_scratch_bos));
|
|
|
|
|
|
|
|
|
|
struct anv_bo *bo = p_atomic_read(&device->rt_scratch_bos[bucket]);
|
|
|
|
|
if (bo == NULL) {
|
|
|
|
|
struct anv_bo *new_bo;
|
|
|
|
|
VkResult result = anv_device_alloc_bo(device, "RT scratch",
|
|
|
|
|
rt->scratch.layout.total_size,
|
2022-08-02 16:17:31 +03:00
|
|
|
0, /* alloc_flags */
|
2020-08-06 22:53:06 -05:00
|
|
|
0, /* explicit_address */
|
|
|
|
|
&new_bo);
|
|
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
|
rt->scratch.layout.total_size = 0;
|
|
|
|
|
anv_batch_set_error(&cmd_buffer->batch, result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bo = p_atomic_cmpxchg(&device->rt_scratch_bos[bucket], NULL, new_bo);
|
|
|
|
|
if (bo != NULL) {
|
|
|
|
|
anv_device_release_bo(device, bo);
|
|
|
|
|
} else {
|
|
|
|
|
bo = new_bo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rt->scratch.bo = bo;
|
2020-08-05 16:53:12 -05:00
|
|
|
}
|
2023-09-27 16:52:45 -07:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_save_state(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
uint32_t flags,
|
|
|
|
|
struct anv_cmd_saved_state *state)
|
|
|
|
|
{
|
|
|
|
|
state->flags = flags;
|
|
|
|
|
|
|
|
|
|
/* we only support the compute pipeline at the moment */
|
|
|
|
|
assert(state->flags & ANV_CMD_SAVED_STATE_COMPUTE_PIPELINE);
|
|
|
|
|
const struct anv_cmd_pipeline_state *pipe_state =
|
|
|
|
|
&cmd_buffer->state.compute.base;
|
|
|
|
|
|
|
|
|
|
if (state->flags & ANV_CMD_SAVED_STATE_COMPUTE_PIPELINE)
|
|
|
|
|
state->pipeline = pipe_state->pipeline;
|
|
|
|
|
|
|
|
|
|
if (state->flags & ANV_CMD_SAVED_STATE_DESCRIPTOR_SET_0)
|
|
|
|
|
state->descriptor_set = pipe_state->descriptors[0];
|
|
|
|
|
|
|
|
|
|
if (state->flags & ANV_CMD_SAVED_STATE_PUSH_CONSTANTS) {
|
|
|
|
|
memcpy(state->push_constants, pipe_state->push_constants.client_data,
|
|
|
|
|
sizeof(state->push_constants));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
anv_cmd_buffer_restore_state(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
struct anv_cmd_saved_state *state)
|
|
|
|
|
{
|
|
|
|
|
VkCommandBuffer cmd_buffer_ = anv_cmd_buffer_to_handle(cmd_buffer);
|
|
|
|
|
|
|
|
|
|
assert(state->flags & ANV_CMD_SAVED_STATE_COMPUTE_PIPELINE);
|
|
|
|
|
const VkPipelineBindPoint bind_point = VK_PIPELINE_BIND_POINT_COMPUTE;
|
|
|
|
|
const VkShaderStageFlags stage_flags = VK_SHADER_STAGE_COMPUTE_BIT;
|
2023-11-08 11:42:22 +02:00
|
|
|
struct anv_cmd_pipeline_state *pipe_state = &cmd_buffer->state.compute.base;
|
2023-09-27 16:52:45 -07:00
|
|
|
|
|
|
|
|
if (state->flags & ANV_CMD_SAVED_STATE_COMPUTE_PIPELINE) {
|
|
|
|
|
if (state->pipeline) {
|
|
|
|
|
anv_CmdBindPipeline(cmd_buffer_, bind_point,
|
|
|
|
|
anv_pipeline_to_handle(state->pipeline));
|
|
|
|
|
} else {
|
|
|
|
|
pipe_state->pipeline = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state->flags & ANV_CMD_SAVED_STATE_DESCRIPTOR_SET_0) {
|
|
|
|
|
if (state->descriptor_set) {
|
|
|
|
|
anv_cmd_buffer_bind_descriptor_set(cmd_buffer, bind_point, NULL, 0,
|
|
|
|
|
state->descriptor_set, NULL, NULL);
|
|
|
|
|
} else {
|
|
|
|
|
pipe_state->descriptors[0] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state->flags & ANV_CMD_SAVED_STATE_PUSH_CONSTANTS) {
|
2023-12-14 15:59:43 -08:00
|
|
|
VkPushConstantsInfoKHR push_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PUSH_CONSTANTS_INFO_KHR,
|
|
|
|
|
.layout = VK_NULL_HANDLE,
|
|
|
|
|
.stageFlags = stage_flags,
|
|
|
|
|
.offset = 0,
|
|
|
|
|
.size = sizeof(state->push_constants),
|
|
|
|
|
.pValues = state->push_constants,
|
|
|
|
|
};
|
|
|
|
|
anv_CmdPushConstants2KHR(cmd_buffer_, &push_info);
|
2023-09-27 16:52:45 -07:00
|
|
|
}
|
|
|
|
|
}
|