Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 5 deletions src/asahi/vulkan/hk_agx3_vdm_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ extern "C" {
* needs_full_quads, to 39 when G17P payloads record the fragment
* twins of unlinked mesh shaders, to 42 when unlinked G17P vertex
* shaders over the canonical size carry relocatable varying writes, to 43
* when agx_shader_info gains launch_size, and to 44 when unlinked G17P vertex
* shaders drop the canonical layout for the relocatable one. */
#define HK_AGX3_SHADER_BINARY_VERSION 44u
#define HK_CLASSIC_SHADER_BINARY_VERSION 34u
* when agx_shader_info gains launch_size, to 44 when unlinked G17P vertex
* shaders drop the canonical layout for the relocatable one, and to 45 when
* M5 payloads carry the compute root prefix. Classic payloads move to 35 and
* AGX2 to 37 when they carry it too. */
#define HK_AGX3_SHADER_BINARY_VERSION 45u
#define HK_CLASSIC_SHADER_BINARY_VERSION 35u
/* AGX2 image-acquire binaries now include memory-to-texture visibility. */
#define HK_AGX2_SHADER_BINARY_VERSION 36u
#define HK_AGX2_SHADER_BINARY_VERSION 37u

static inline uint32_t
hk_shader_binary_version(enum agx_chip chip)
Expand Down
18 changes: 10 additions & 8 deletions src/asahi/vulkan/hk_cmd_upload.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ hk_cmd_buffer_upload_root(struct hk_cmd_buffer *cmd,
struct hk_descriptor_state *desc = hk_get_descriptors_state(cmd, bind_point);
struct hk_root_descriptor_table *root = &desc->root;

/* A compute shader's measured root prefix (hk_compile_nir()), or a native
* HAL200 graphics pipeline's measured prefix; zero for an unmeasured
* shader, which takes the whole table. */
size_t root_size = sizeof(*root);
if (agx_chip_native_hal200(dev->dev.chip)) {
if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) {
const struct hk_shader *s = hk_only_variant(cmd->state.cs.shader);
if (s && s->root_descriptor_size)
root_size = MIN2(root_size, s->root_descriptor_size);
} else if (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) {
root_size = MIN2(root_size, hk_gfx_root_descriptor_size(cmd));
}
if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) {
const struct hk_shader *s = hk_only_variant(cmd->state.cs.shader);
if (s && s->root_descriptor_size)
root_size = MIN2(root_size, s->root_descriptor_size);
} else if (agx_chip_native_hal200(dev->dev.chip) &&
bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) {
root_size = MIN2(root_size, hk_gfx_root_descriptor_size(cmd));
}

root->printf_buffer_address = dev->dev.printf_buffer_address;
Expand Down
35 changes: 19 additions & 16 deletions src/asahi/vulkan/hk_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5372,20 +5372,25 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
shader->info.agx3_root_reads = hk_nir_root_reads(nir);
}

/* Measure while root markers are still explicit. Uniform lowering loads
* the root pointer and set bases separately, so retain that prefix too.
* Hardware VS and FS prologs/epilogs access only the draw arm preceding
* push constants, so flooring graphics stages at offsetof(push) preserves
/* Measure while root markers are still explicit, so that
* hk_cmd_buffer_upload_root() uploads only the prefix a compute shader
* reads (on every generation) or a native HAL200 graphics shader reads.
* Uniform lowering loads the root pointer and set bases separately, so
* retain that prefix too: it is also all that a compute launch preloads
* from the root on every generation (the AGX2 USC root uniform and the
* AGX3 Ioto root range are both root_desc_addr plus set_count set bases).
* Uniform DMA spans over the root come from loads measured here. Hardware
* VS and FS prologs/epilogs access only the draw arm preceding push
* constants, so flooring HAL200 graphics stages at offsetof(push) preserves
* every driver-synthesized root load while trimming unused push-constant,
* dynamic-buffer and trailing tail bytes. Round up for native
* uniform/global load granularity. */
if (agx_chip_native_hal200(dev->dev.chip))
shader->root_descriptor_size = sizeof(struct hk_root_descriptor_table);
if (agx_chip_native_hal200(dev->dev.chip) &&
(sw_stage == MESA_SHADER_COMPUTE ||
sw_stage == MESA_SHADER_FRAGMENT ||
(sw_stage == MESA_SHADER_VERTEX &&
nir->info.stage == MESA_SHADER_VERTEX))) {
* uniform/global load granularity. Every other stage keeps the whole table. */
shader->root_descriptor_size = sizeof(struct hk_root_descriptor_table);
if (sw_stage == MESA_SHADER_COMPUTE ||
(agx_chip_native_hal200(dev->dev.chip) &&
(sw_stage == MESA_SHADER_FRAGMENT ||
(sw_stage == MESA_SHADER_VERTEX &&
nir->info.stage == MESA_SHADER_VERTEX)))) {
shader->root_descriptor_size = hk_shader_root_descriptor_size(
nir, sw_stage, set_count, hk_root_descriptor_offset(sets),
hk_root_descriptor_offset(push),
Expand Down Expand Up @@ -8551,8 +8556,7 @@ hk_deserialize_shader(struct hk_device *dev, struct blob_reader *blob,
{
struct hk_shader_info info;
blob_copy_bytes(blob, &info, sizeof(info));
const uint32_t root_descriptor_size =
agx_chip_native_hal200(dev->dev.chip) ? blob_read_uint32(blob) : 0;
const uint32_t root_descriptor_size = blob_read_uint32(blob);
uint8_t mesh_primitive_comps[64] = {0};
if (dev->dev.chip == AGX_CHIP_G17P && info.stage == MESA_SHADER_MESH)
blob_copy_bytes(blob, mesh_primitive_comps, sizeof(mesh_primitive_comps));
Expand Down Expand Up @@ -9169,8 +9173,7 @@ hk_shader_serialize(struct vk_device *vk_dev, const struct hk_shader *shader,
{
struct hk_device *dev = container_of(vk_dev, struct hk_device, vk);
blob_write_bytes(blob, &shader->info, sizeof(shader->info));
if (agx_chip_native_hal200(dev->dev.chip))
blob_write_uint32(blob, shader->root_descriptor_size);
blob_write_uint32(blob, shader->root_descriptor_size);
if (dev->dev.chip == AGX_CHIP_G17P &&
shader->info.stage == MESA_SHADER_MESH)
blob_write_bytes(blob, shader->g17p_mesh_primitive_comps,
Expand Down
5 changes: 3 additions & 2 deletions src/asahi/vulkan/hk_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ struct hk_shader {
struct agx_shader_part b;

struct hk_shader_info info;
/* G17P-only root prefix; serialized separately in its version-35 payload.
* Keep hk_shader_info and version-34 payloads unchanged on other chips. */
/* Root table prefix a compute shader (or native HAL200 graphics shader)
* reads (whole table for other stages, zero when unmeasured); serialized
* after hk_shader_info. */
uint32_t root_descriptor_size;
/* G17P mesh: 32-bit words each varying slot takes in the per-primitive
* record (agx_gen1_mesh_record_layout()), serialized like the root prefix.
Expand Down
12 changes: 8 additions & 4 deletions src/asahi/vulkan/tests/hk_cpu_upload_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,19 @@ reuse_correctness(struct fixture *f)
cs->variants[0].root_descriptor_size = small_B;
CHECK(hk_cmd_buffer_upload_root(cmd, VK_PIPELINE_BIND_POINT_COMPUTE) != full);
CHECK(cd->uploaded_root_size == small_B);
/* A retained or adversarial short-prefix value must have no effect on
* any non-HAL200 chip, including the native-encoding M3 (G15) path. */
/* Every chip uploads only the measured compute prefix, including the AGX2
* and native-encoding M3 paths, and an unmeasured shader the whole table. */
for (enum agx_chip chip = AGX_CHIP_G13G; chip < AGX_CHIP_UNKNOWN; ++chip) {
if (agx_chip_native_hal200(chip))
continue;
f->dev.dev.chip = chip;
cs->variants[0].root_descriptor_size = small_B;
CHECK(hk_cmd_buffer_upload_root(cmd, VK_PIPELINE_BIND_POINT_COMPUTE));
CHECK(cd->uploaded_root_size == small_B);
CHECK(memcmp(cd->uploaded_root.cpu, &cd->root, small_B) == 0);
cs->variants[0].root_descriptor_size = 0;
CHECK(hk_cmd_buffer_upload_root(cmd, VK_PIPELINE_BIND_POINT_COMPUTE));
CHECK(cd->uploaded_root_size == sizeof(cd->root));
}
cs->variants[0].root_descriptor_size = small_B;
const enum agx_chip hal200_chips[] = {AGX_CHIP_G17P, AGX_CHIP_G16G};
const size_t gfx_small_B =
ALIGN_POT(hk_root_descriptor_offset(push) + 16, 16);
Expand Down
4 changes: 2 additions & 2 deletions src/asahi/vulkan/tests/test-hk-execution-allowance.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ int main(void)
for (enum agx_chip chip = AGX_CHIP_G13G; chip < AGX_CHIP_UNKNOWN; ++chip)
assert(hk_shader_binary_version(chip) ==
(chip == AGX_CHIP_G17P || chip == AGX_CHIP_G17G ||
chip == AGX_CHIP_G17S || chip == AGX_CHIP_G17C ? 44 :
chip <= AGX_CHIP_G15P ? 36 : 34));
chip == AGX_CHIP_G17S || chip == AGX_CHIP_G17C ? 45 :
chip <= AGX_CHIP_G15P ? 37 : 35));
assert(hk_as_build_flags(AGX_CHIP_G17P, 0, true) == 0);
assert(hk_as_build_flags(AGX_CHIP_G17P, DRM_ASAHI_FEATURE_RENDER_RAY_QUERY, true) == 0);
assert(hk_as_build_flags(AGX_CHIP_G17P, DRM_ASAHI_FEATURE_BOUNDED_AS_BUILD, false) == 0);
Expand Down