Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/egl/drivers/dri2/platform_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,17 @@ dri2_initialize_x11(_EGLDisplay *disp)
* We're going to enable Zink anyway.
*/
if (!force_zink) {
bool status = dri3_x11_connect(dri2_dpy, disp->Options.ForceSoftware);
/* Zink+kopper does not use the DRI3 device: kopper presents through
* Vulkan WSI, which imports dma-bufs without DRI3Open. Some X servers
* (for example Termux:X11) only implement the dma-buf import half of
* DRI3, so don't warn about the missing render device when kopper will
* be used anyway.
*/
const bool zink_kopper =
disp->Options.Zink && !disp->Options.ForceSoftware &&
!debug_get_bool_option("LIBGL_KOPPER_DISABLE", false);
bool status = dri3_x11_connect(dri2_dpy,
disp->Options.ForceSoftware || zink_kopper);
/* the status here is ignored for zink-with-kopper and swrast,
* otherwise return whatever error/fallback status as failure
*/
Expand Down
6 changes: 6 additions & 0 deletions src/freedreno/common/freedreno_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@
has_z24uint_s8uint = True,
tess_use_shared = True,
storage_16bit = True,
# Requires storage_16bit + has_isam_v (asserted in tu_descriptor_set.cc).
storage_8bit = True,
# 7 usable sets + 1 reserved for dynamic descriptors. a6xx only has
# five hardware bindless base registers, so sets 4-7 are virtualized
# on top of the last register.
max_sets = 8,
has_tex_filter_cubic = True,
has_separate_chroma_filter = True,
has_sample_locations = True,
Expand Down
2 changes: 2 additions & 0 deletions src/freedreno/ir3/ir3_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,8 @@ ir3_const_alloc_type_to_string(enum ir3_const_alloc_type type)
return "inline_uniform_addresses";
case IR3_CONST_ALLOC_BINDLESS_BASE_ADDRS:
return "bindless_base_addresses";
case IR3_CONST_ALLOC_VIRTUAL_SET_OFFSETS:
return "virtual_set_offsets";
case IR3_CONST_ALLOC_DRIVER_PARAMS:
return "driver_params";
case IR3_CONST_ALLOC_UBO_RANGES:
Expand Down
6 changes: 5 additions & 1 deletion src/freedreno/ir3/ir3_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ enum ir3_const_alloc_type {
IR3_CONST_ALLOC_PRIMITIVE_MAP = 11,
/* For SSBO emulation */
IR3_CONST_ALLOC_BINDLESS_BASE_ADDRS = 12,
IR3_CONST_ALLOC_MAX = 13,
/* For descriptor-set virtualization: one u32 per set, holding the offset
* in descriptor units from the shared hardware bindless base.
*/
IR3_CONST_ALLOC_VIRTUAL_SET_OFFSETS = 13,
IR3_CONST_ALLOC_MAX = 14,
};

struct ir3_const_allocation {
Expand Down
179 changes: 148 additions & 31 deletions src/freedreno/vulkan/tu_cmd_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4772,6 +4772,26 @@ tu_CmdBindIndexBuffer2KHR(VkCommandBuffer commandBuffer,
}
TU_GENX(tu_CmdBindIndexBuffer2KHR);

/* Returns the shared hardware bindless base address used by virtualized
* descriptor sets. Sets at and above hw_max_sets - 1 share the last hardware
* base register, and are distinguished by a per-set descriptor offset.
*/
static uint64_t
tu_bindless_anchor(unsigned hw_max_sets, const uint64_t *set_iova)
{
uint64_t anchor = 0;

for (unsigned i = hw_max_sets - 1; i < MAX_SETS; i++) {
uint64_t va = set_iova[i] & ~0x3f;
if (!va)
continue;
if (!anchor || va < anchor)
anchor = va;
}

return anchor;
}

template <chip CHIP>
static void
tu6_emit_descriptor_sets(struct tu_cmd_buffer *cmd,
Expand All @@ -4782,24 +4802,56 @@ tu6_emit_descriptor_sets(struct tu_cmd_buffer *cmd,
uint32_t sp_bindless_base_reg, hlsq_bindless_base_reg;
struct tu_cs *cs, state_cs;

/* a6xx only has 5 bindless descriptor set base registers per stage, and
* a7xx has 8. When descriptor-set virtualization lets more sets be bound
* than that, sets at and above hw_max_sets - 1 share the last base
* register: program it with the lowest set address and let shaders add a
* per-set descriptor offset. On a6xx the next register after the array
* is SP_CS_UAV_BASE.
*/
const unsigned hw_max_sets = tu_hw_max_sets(CHIP);
const bool virtual_sets =
tu_uses_virtual_sets(CHIP, cmd->device->physical_device->usable_sets);
const unsigned max_sets_bound =
virtual_sets ? hw_max_sets :
MIN2(descriptors_state->max_sets_bound, hw_max_sets);
uint64_t set_iova[MAX_SETS];

/* Dynamic descriptors normally get the reserved set's base register. When
* that set is virtualized it shares the anchor register instead, so there
* is no separate dynamic-register packet to emit.
*/
const int reserved_set_idx =
cmd->device->physical_device->reserved_set_idx;
const bool has_dynamic_regs =
descriptors_state->max_dynamic_offset_size &&
reserved_set_idx >= 0 && reserved_set_idx < static_cast<int>(hw_max_sets);

memcpy(set_iova, descriptors_state->set_iova, sizeof(set_iova));
if (virtual_sets) {
set_iova[hw_max_sets - 1] =
tu_bindless_anchor(hw_max_sets, descriptors_state->set_iova) |
BINDLESS_DESCRIPTOR_64B;
}

if (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) {
sp_bindless_base_reg = __SP_GFX_BINDLESS_BASE_DESCRIPTOR<CHIP>(0, {}).reg;
hlsq_bindless_base_reg = REG_A6XX_HLSQ_BINDLESS_BASE(0);

unsigned bindless_pkt_size = descriptors_state->max_sets_bound ?
1 + 2 * descriptors_state->max_sets_bound :
unsigned bindless_pkt_size = max_sets_bound ?
1 + 2 * max_sets_bound :
0;

if (CHIP == A6XX) {
cmd->state.desc_sets =
tu_cs_draw_state(&cmd->sub_cs, &state_cs,
2 + 2 * bindless_pkt_size +
(descriptors_state->max_dynamic_offset_size ? 6 : 0));
(has_dynamic_regs ? 6 : 0));
} else {
cmd->state.desc_sets =
tu_cs_draw_state(&cmd->sub_cs, &state_cs,
2 + bindless_pkt_size +
(descriptors_state->max_dynamic_offset_size ? 3 : 0));
(has_dynamic_regs ? 3 : 0));
}
cs = &state_cs;
} else {
Expand All @@ -4811,27 +4863,28 @@ tu6_emit_descriptor_sets(struct tu_cmd_buffer *cmd,
cs = &cmd->cs;
}

if (descriptors_state->max_sets_bound > 0) {
tu_cs_emit_pkt4(cs, sp_bindless_base_reg, 2 * descriptors_state->max_sets_bound);
tu_cs_emit_array(cs, reinterpret_cast<const uint32_t*>(descriptors_state->set_iova),
2 * descriptors_state->max_sets_bound);
if (max_sets_bound > 0) {
tu_cs_emit_pkt4(cs, sp_bindless_base_reg, 2 * max_sets_bound);
tu_cs_emit_array(cs, reinterpret_cast<const uint32_t *>(set_iova),
2 * max_sets_bound);
if (CHIP == A6XX) {
tu_cs_emit_pkt4(cs, hlsq_bindless_base_reg, 2 * descriptors_state->max_sets_bound);
tu_cs_emit_array(cs, reinterpret_cast<const uint32_t*>(descriptors_state->set_iova),
2 * descriptors_state->max_sets_bound);
tu_cs_emit_pkt4(cs, hlsq_bindless_base_reg, 2 * max_sets_bound);
tu_cs_emit_array(cs, reinterpret_cast<const uint32_t *>(set_iova),
2 * max_sets_bound);
}
}

/* Dynamic descriptors get the reserved descriptor set. */
if (descriptors_state->max_dynamic_offset_size) {
int reserved_set_idx = cmd->device->physical_device->reserved_set_idx;
assert(reserved_set_idx >= 0); /* reserved set must be bound */

tu_cs_emit_pkt4(cs, sp_bindless_base_reg + reserved_set_idx * 2, 2);
tu_cs_emit_qw(cs, descriptors_state->set_iova[reserved_set_idx]);
if (CHIP == A6XX) {
tu_cs_emit_pkt4(cs, hlsq_bindless_base_reg + reserved_set_idx * 2, 2);
if (has_dynamic_regs) {
tu_cs_emit_pkt4(cs, sp_bindless_base_reg + reserved_set_idx * 2, 2);
tu_cs_emit_qw(cs, descriptors_state->set_iova[reserved_set_idx]);
if (CHIP == A6XX) {
tu_cs_emit_pkt4(cs, hlsq_bindless_base_reg + reserved_set_idx * 2, 2);
tu_cs_emit_qw(cs, descriptors_state->set_iova[reserved_set_idx]);
}
}
}

Expand Down Expand Up @@ -7775,6 +7828,11 @@ tu6_user_consts_size(const struct tu_const_state *const_state,
}
}

if (const_state->num_virtual_set_offsets > 0 &&
!load_shader_consts_via_preamble) {
dwords += 4 + align(const_state->num_virtual_set_offsets, 4);
}

return dwords;
}

Expand Down Expand Up @@ -7978,28 +8036,48 @@ tu6_const_size(struct tu_cmd_buffer *cmd,
static void
fill_bindless_base_addresses(const struct tu_const_state *const_state,
struct tu_descriptor_state *descriptors,
unsigned hw_max_sets,
uint64_t *addresses)
{
assert(const_state->num_bindless_base_addresses <= MAX_SETS);

for (unsigned i = 0; i < const_state->num_bindless_base_addresses; i++)
addresses[i] = descriptors->set_iova[i] & ~0x3f;

if (const_state->num_virtual_set_offsets)
addresses[hw_max_sets - 1] =
tu_bindless_anchor(hw_max_sets, descriptors->set_iova);
}

/* Upload the per-set descriptor offsets for virtualized sets, in 64-byte
* descriptor units relative to the shared base register.
*/
static void
tu6_emit_bindless_base_addresses(struct tu_cs *cs,
const struct tu_const_state *const_state,
const struct ir3_const_state *ir_const_state,
mesa_shader_stage type,
struct tu_descriptor_state *descriptors)
tu6_emit_virtual_set_offsets(struct tu_cs *cs,
const struct tu_const_state *const_state,
const struct ir3_const_state *ir_const_state,
mesa_shader_stage type,
struct tu_descriptor_state *descriptors)
{
uint64_t addresses[MAX_SETS] = {0};
fill_bindless_base_addresses(const_state, descriptors, addresses);
if (!const_state->num_virtual_set_offsets)
return;

const unsigned hw_max_sets =
tu_hw_max_sets(cs->device->compiler->info->chip);
uint64_t anchor = tu_bindless_anchor(hw_max_sets, descriptors->set_iova);
uint32_t offsets[MAX_SETS] = {0};

for (unsigned i = hw_max_sets - 1;
i < const_state->num_virtual_set_offsets; i++) {
uint64_t va = descriptors->set_iova[i] & ~0x3f;
if (va)
offsets[i] = (va - anchor) / 64;
}

uint32_t offset =
ir_const_state->allocs.consts[IR3_CONST_ALLOC_BINDLESS_BASE_ADDRS]
ir_const_state->allocs.consts[IR3_CONST_ALLOC_VIRTUAL_SET_OFFSETS]
.offset_vec4;
unsigned num_dwords = align(const_state->num_bindless_base_addresses * 2, 4);
unsigned num_dwords = align(const_state->num_virtual_set_offsets, 4);

tu_cs_emit_pkt7(cs, tu6_stage2opcode(type), 3 + num_dwords);
tu_cs_emit(cs, CP_LOAD_STATE6_0_DST_OFF(offset) |
Expand All @@ -8010,12 +8088,48 @@ tu6_emit_bindless_base_addresses(struct tu_cs *cs,
tu_cs_emit(cs, 0);
tu_cs_emit(cs, 0);

for (unsigned i = 0; i < const_state->num_bindless_base_addresses; i++)
tu_cs_emit_qw(cs, addresses[i]);
for (unsigned i = 0; i < num_dwords; i++)
tu_cs_emit(cs, i < const_state->num_virtual_set_offsets ? offsets[i] : 0);
}

static void
tu6_emit_bindless_base_addresses(struct tu_cs *cs,
const struct tu_const_state *const_state,
const struct ir3_const_state *ir_const_state,
mesa_shader_stage type,
struct tu_descriptor_state *descriptors)
{
if (const_state->num_bindless_base_addresses > 0) {
uint64_t addresses[MAX_SETS] = {0};
fill_bindless_base_addresses(
const_state, descriptors,
tu_hw_max_sets(cs->device->compiler->info->chip), addresses);

uint32_t offset =
ir_const_state->allocs.consts[IR3_CONST_ALLOC_BINDLESS_BASE_ADDRS]
.offset_vec4;
unsigned num_dwords =
align(const_state->num_bindless_base_addresses * 2, 4);

for (unsigned i = const_state->num_bindless_base_addresses * 2;
i < num_dwords; i++)
tu_cs_emit_pkt7(cs, tu6_stage2opcode(type), 3 + num_dwords);
tu_cs_emit(cs, CP_LOAD_STATE6_0_DST_OFF(offset) |
CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS) |
CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT) |
CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type)) |
CP_LOAD_STATE6_0_NUM_UNIT(num_dwords / 4));
tu_cs_emit(cs, 0);
tu_cs_emit(cs, 0);

for (unsigned i = 0; i < const_state->num_bindless_base_addresses; i++)
tu_cs_emit_qw(cs, addresses[i]);

for (unsigned i = const_state->num_bindless_base_addresses * 2;
i < num_dwords; i++)
tu_cs_emit(cs, 0);
}

tu6_emit_virtual_set_offsets(cs, const_state, ir_const_state, type,
descriptors);
}

static void
Expand All @@ -8029,7 +8143,9 @@ tu7_emit_bindless_base_addresses(struct tu_cs *cs,
if (ubo_offset < 0)
return;

fill_bindless_base_addresses(const_state, descriptors, addresses);
fill_bindless_base_addresses(
const_state, descriptors,
tu_hw_max_sets(cs->device->compiler->info->chip), addresses);

/* A7XX TODO: Emit data via sub_cs instead of NOP */
uint64_t iova = tu_cs_emit_data_nop(
Expand All @@ -8055,7 +8171,8 @@ tu_emit_bindless_base_addresses(struct tu_cs *cs,
mesa_shader_stage type,
struct tu_descriptor_state *descriptors)
{
if (!const_state->num_bindless_base_addresses)
if (!const_state->num_bindless_base_addresses &&
!const_state->num_virtual_set_offsets)
return;

if (cs->device->physical_device->info->props.load_shader_consts_via_preamble) {
Expand Down
20 changes: 20 additions & 0 deletions src/freedreno/vulkan/tu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@
#define MAX_INLINE_UBO_RANGE 256
#define MAX_INLINE_UBOS 4

/* Number of hardware bindless descriptor-set base registers per stage.
* a6xx has five, while a7xx and later have eight.
*/
static inline unsigned
tu_hw_max_sets(unsigned chip)
{
return chip == 6 ? 5 : 8;
}

/* Whether we need to virtualize descriptor sets because more sets are exposed
* to applications than there are hardware bindless base registers. Sets at
* and above tu_hw_max_sets() - 1 then share the last hardware base register,
* with a per-set descriptor-index offset.
*/
static inline bool
tu_uses_virtual_sets(unsigned chip, unsigned usable_sets)
{
return usable_sets >= tu_hw_max_sets(chip);
}

#define A6XX_TEX_SAMP_DWORDS 4

/* We sample the fragment density map on the CPU, so technically the
Expand Down
26 changes: 19 additions & 7 deletions src/freedreno/vulkan/tu_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ tu_physical_device_compiler_options_init(struct tu_physical_device *device,
device->compiler_options.enable_texel_buffer_emulation =
instance->drirc.misc.enable_texel_buffer_emulation;
}
if (device->info->props.max_storage_buffer_range_bytes < TU_D3D12_MAX_STORAGE_BUFFER_RANGE_BYTES) {
assert(fd_dev_gen(&device->dev_id) == 7);
device->compiler_options.enable_ssbo_emulation =
instance->drirc.misc.enable_ssbo_emulation;
}
}

/* SSBO emulation only needs global loads/stores and a driver UBO holding
* the per-set descriptor base addresses, both of which exist on a6xx, so
* allow the drirc option on all supported generations.
*/
if (device->info->props.max_storage_buffer_range_bytes < TU_D3D12_MAX_STORAGE_BUFFER_RANGE_BYTES) {
device->compiler_options.enable_ssbo_emulation =
instance->drirc.misc.enable_ssbo_emulation;
}

device->compiler_options.allow_oob_indirect_ubo_loads =
Expand Down Expand Up @@ -1332,9 +1336,17 @@ tu_get_properties(struct tu_physical_device *pdevice,
props->optimalBufferCopyRowPitchAlignment = 128;
props->nonCoherentAtomSize = 64;

/* Vulkan 1.4 requires storageBuffer8BitAccess and
* maxBoundDescriptorSets >= 7. Only a6xx gen4 and newer (and a7xx/a8xx)
* support 8-bit storage; a6xx gen4 parts expose 7 usable sets (plus one
* reserved for dynamic descriptors) by virtualizing sets 4-7 on top of the
* last hardware bindless base register, see tu_uses_virtual_sets(). Keep
* older a6xx parts, or configurations that override the set count below
* seven, on 1.3.
*/
props->apiVersion =
((pdevice->info->chip >= 7) ? TU_API_VERSION :
VK_MAKE_VERSION(1, 3, VK_HEADER_VERSION));
(pdevice->info->props.storage_8bit && pdevice->usable_sets >= 7) ?
TU_API_VERSION : VK_MAKE_VERSION(1, 3, VK_HEADER_VERSION);
props->driverVersion = vk_get_driver_version();
props->vendorID = pdevice->instance->drirc.debug.force_vk_vendor != 0 ?
pdevice->instance->drirc.debug.force_vk_vendor : 0x5143;
Expand Down
Loading