mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-03 12:08:06 +02:00
anv: Replace duplicated code set shader relocs by a function
This code was duplicated and with a assert mistake in one of the copies, so here moving it to function and calling it from both places. Also I have removed anv_shader_bin_rewrite_embedded_samplers() as it is already being done in anv_shader_set_relocs(). Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Signed-off-by: José Roberto de Souza <jose.souza@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37749>
This commit is contained in:
parent
16458f756e
commit
62a746b353
3 changed files with 58 additions and 121 deletions
|
|
@ -29,6 +29,7 @@
|
|||
#include "nir/nir_serialize.h"
|
||||
#include "nir/nir.h"
|
||||
#include "anv_private.h"
|
||||
#include "anv_shader.h"
|
||||
#include "nir/nir_xfb_info.h"
|
||||
#include "vk_util.h"
|
||||
#include "compiler/spirv/nir_spirv.h"
|
||||
|
|
@ -75,27 +76,6 @@ const struct vk_pipeline_cache_object_ops *const anv_cache_import_ops[2] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
static void
|
||||
anv_shader_bin_rewrite_embedded_samplers(struct anv_device *device,
|
||||
struct anv_shader_bin *shader,
|
||||
const struct anv_pipeline_bind_map *bind_map,
|
||||
const struct brw_stage_prog_data *prog_data_in)
|
||||
{
|
||||
int rv_count = 0;
|
||||
struct brw_shader_reloc_value reloc_values[BRW_MAX_EMBEDDED_SAMPLERS];
|
||||
|
||||
for (uint32_t i = 0; i < bind_map->embedded_sampler_count; i++) {
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_EMBEDDED_SAMPLER_HANDLE + i,
|
||||
.value = shader->embedded_samplers[i]->sampler_state.offset,
|
||||
};
|
||||
}
|
||||
|
||||
brw_write_shader_relocs(&device->physical->compiler->isa,
|
||||
shader->kernel.map, prog_data_in,
|
||||
reloc_values, rv_count);
|
||||
}
|
||||
|
||||
static struct anv_shader_bin *
|
||||
anv_shader_bin_create(struct anv_device *device,
|
||||
mesa_shader_stage stage,
|
||||
|
|
@ -159,87 +139,17 @@ anv_shader_bin_create(struct anv_device *device,
|
|||
}
|
||||
}
|
||||
|
||||
uint64_t shader_data_addr =
|
||||
device->physical->va.instruction_state_pool.addr +
|
||||
shader->kernel.offset +
|
||||
prog_data_in->const_data_offset;
|
||||
|
||||
int rv_count = 0;
|
||||
struct brw_shader_reloc_value reloc_values[11];
|
||||
assert((device->physical->va.instruction_state_pool.addr & 0xffffffff) == 0);
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_INSTRUCTION_BASE_ADDR_HIGH,
|
||||
.value = device->physical->va.instruction_state_pool.addr >> 32,
|
||||
};
|
||||
assert((device->physical->va.dynamic_visible_pool.addr & 0xffffffff) == 0);
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_DESCRIPTORS_BUFFER_ADDR_HIGH,
|
||||
.value = device->physical->va.dynamic_visible_pool.addr >> 32,
|
||||
};
|
||||
assert((device->physical->va.indirect_descriptor_pool.addr & 0xffffffff) == 0);
|
||||
assert((device->physical->va.internal_surface_state_pool.addr & 0xffffffff) == 0);
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_DESCRIPTORS_ADDR_HIGH,
|
||||
.value = device->physical->indirect_descriptors ?
|
||||
(device->physical->va.indirect_descriptor_pool.addr >> 32) :
|
||||
(device->physical->va.internal_surface_state_pool.addr >> 32),
|
||||
};
|
||||
assert((device->physical->va.instruction_state_pool.addr & 0xffffffff) == 0);
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_CONST_DATA_ADDR_LOW,
|
||||
.value = shader_data_addr,
|
||||
};
|
||||
assert((device->physical->va.instruction_state_pool.addr & 0xffffffff) == 0);
|
||||
assert(shader_data_addr >> 32 == device->physical->va.instruction_state_pool.addr >> 32);
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_CONST_DATA_ADDR_HIGH,
|
||||
.value = device->physical->va.instruction_state_pool.addr >> 32,
|
||||
};
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_SHADER_START_OFFSET,
|
||||
.value = shader->kernel.offset,
|
||||
};
|
||||
if (brw_shader_stage_is_bindless(stage)) {
|
||||
const struct brw_bs_prog_data *bs_prog_data =
|
||||
brw_bs_prog_data_const(prog_data_in);
|
||||
uint64_t resume_sbt_addr =
|
||||
device->physical->va.instruction_state_pool.addr +
|
||||
shader->kernel.offset +
|
||||
bs_prog_data->resume_sbt_offset;
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_RESUME_SBT_ADDR_LOW,
|
||||
.value = resume_sbt_addr,
|
||||
};
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_RESUME_SBT_ADDR_HIGH,
|
||||
.value = resume_sbt_addr >> 32,
|
||||
};
|
||||
}
|
||||
|
||||
if (INTEL_DEBUG(DEBUG_SHADER_PRINT)) {
|
||||
struct anv_bo *bo = device->printf.bo;
|
||||
assert(bo != NULL);
|
||||
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_LOW,
|
||||
.value = bo->offset & 0xffffffff,
|
||||
};
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_HIGH,
|
||||
.value = bo->offset >> 32,
|
||||
};
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_PRINTF_BUFFER_SIZE,
|
||||
.value = anv_printf_buffer_size(),
|
||||
};
|
||||
}
|
||||
rv_count = anv_shader_set_relocs(device, reloc_values, stage,
|
||||
&shader->kernel, prog_data_in, bind_map,
|
||||
shader->embedded_samplers);
|
||||
assert(rv_count <= ARRAY_SIZE(reloc_values));
|
||||
|
||||
brw_write_shader_relocs(&device->physical->compiler->isa,
|
||||
shader->kernel.map, prog_data_in,
|
||||
reloc_values, rv_count);
|
||||
|
||||
anv_shader_bin_rewrite_embedded_samplers(device, shader, bind_map, prog_data_in);
|
||||
|
||||
memcpy(prog_data, prog_data_in, prog_data_size);
|
||||
typed_memcpy(prog_data_relocs, prog_data_in->relocs,
|
||||
prog_data_in->num_relocs);
|
||||
|
|
|
|||
|
|
@ -299,33 +299,27 @@ static struct vk_shader_ops anv_shader_ops = {
|
|||
anv_shader_get_executable_internal_representations,
|
||||
};
|
||||
|
||||
static VkResult
|
||||
anv_shader_reloc(struct anv_device *device,
|
||||
void *code,
|
||||
struct anv_shader *shader,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
int
|
||||
anv_shader_set_relocs(struct anv_device *device,
|
||||
struct brw_shader_reloc_value *reloc_values,
|
||||
mesa_shader_stage stage,
|
||||
struct anv_state *kernel,
|
||||
const struct brw_stage_prog_data *prog_data_in,
|
||||
const struct anv_pipeline_bind_map *bind_map,
|
||||
struct anv_embedded_sampler **embedded_samplers)
|
||||
{
|
||||
uint64_t shader_data_addr =
|
||||
int rv_count = 0;
|
||||
const uint64_t shader_data_addr =
|
||||
device->physical->va.instruction_state_pool.addr +
|
||||
shader->kernel.offset +
|
||||
shader->prog_data->const_data_offset;
|
||||
kernel->offset +
|
||||
prog_data_in->const_data_offset;
|
||||
|
||||
const uint32_t max_relocs =
|
||||
BRW_SHADER_RELOC_EMBEDDED_SAMPLER_HANDLE +
|
||||
shader->bind_map.embedded_sampler_count;
|
||||
uint32_t rv_count = 0;
|
||||
struct brw_shader_reloc_value *reloc_values =
|
||||
vk_zalloc2(&device->vk.alloc, pAllocator,
|
||||
sizeof(struct brw_shader_reloc_value) * max_relocs, 8,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
|
||||
if (reloc_values == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
assert((device->physical->va.dynamic_visible_pool.addr & 0xffffffff) == 0);
|
||||
assert((device->physical->va.instruction_state_pool.addr & 0xffffffff) == 0);
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_INSTRUCTION_BASE_ADDR_HIGH,
|
||||
.value = device->physical->va.instruction_state_pool.addr >> 32,
|
||||
};
|
||||
assert((device->physical->va.dynamic_visible_pool.addr & 0xffffffff) == 0);
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_DESCRIPTORS_BUFFER_ADDR_HIGH,
|
||||
.value = device->physical->va.dynamic_visible_pool.addr >> 32,
|
||||
|
|
@ -351,14 +345,14 @@ anv_shader_reloc(struct anv_device *device,
|
|||
};
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_SHADER_START_OFFSET,
|
||||
.value = shader->kernel.offset,
|
||||
.value = kernel->offset,
|
||||
};
|
||||
if (brw_shader_stage_is_bindless(shader->vk.stage)) {
|
||||
if (brw_shader_stage_is_bindless(stage)) {
|
||||
const struct brw_bs_prog_data *bs_prog_data =
|
||||
brw_bs_prog_data_const(shader->prog_data);
|
||||
brw_bs_prog_data_const(prog_data_in);
|
||||
uint64_t resume_sbt_addr =
|
||||
device->physical->va.instruction_state_pool.addr +
|
||||
shader->kernel.offset +
|
||||
kernel->offset +
|
||||
bs_prog_data->resume_sbt_offset;
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_RESUME_SBT_ADDR_LOW,
|
||||
|
|
@ -388,13 +382,37 @@ anv_shader_reloc(struct anv_device *device,
|
|||
};
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < shader->bind_map.embedded_sampler_count; i++) {
|
||||
for (uint32_t i = 0; i < bind_map->embedded_sampler_count; i++) {
|
||||
reloc_values[rv_count++] = (struct brw_shader_reloc_value) {
|
||||
.id = BRW_SHADER_RELOC_EMBEDDED_SAMPLER_HANDLE + i,
|
||||
.value = shader->embedded_samplers[i]->sampler_state.offset,
|
||||
.value = embedded_samplers[i]->sampler_state.offset,
|
||||
};
|
||||
}
|
||||
|
||||
return rv_count;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
anv_shader_reloc(struct anv_device *device,
|
||||
void *code,
|
||||
struct anv_shader *shader,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
const uint32_t max_relocs =
|
||||
BRW_SHADER_RELOC_EMBEDDED_SAMPLER_HANDLE +
|
||||
shader->bind_map.embedded_sampler_count;
|
||||
uint32_t rv_count;
|
||||
struct brw_shader_reloc_value *reloc_values =
|
||||
vk_zalloc2(&device->vk.alloc, pAllocator,
|
||||
sizeof(struct brw_shader_reloc_value) * max_relocs, 8,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
|
||||
if (reloc_values == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
rv_count = anv_shader_set_relocs(device, reloc_values, shader->vk.stage,
|
||||
&shader->kernel, shader->prog_data,
|
||||
&shader->bind_map,
|
||||
shader->embedded_samplers);
|
||||
assert(rv_count <= max_relocs);
|
||||
|
||||
brw_write_shader_relocs(&device->physical->compiler->isa,
|
||||
|
|
|
|||
|
|
@ -129,3 +129,12 @@ VkResult anv_shader_deserialize(struct vk_device *device,
|
|||
struct vk_shader **shader_out);
|
||||
|
||||
extern struct vk_device_shader_ops anv_device_shader_ops;
|
||||
|
||||
int
|
||||
anv_shader_set_relocs(struct anv_device *device,
|
||||
struct brw_shader_reloc_value *reloc_values,
|
||||
mesa_shader_stage stage,
|
||||
struct anv_state *kernel,
|
||||
const struct brw_stage_prog_data *prog_data_in,
|
||||
const struct anv_pipeline_bind_map *bind_map,
|
||||
struct anv_embedded_sampler **embedded_samplers);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue