Skip to content
Merged
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
41 changes: 32 additions & 9 deletions src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -15442,7 +15442,8 @@ agx_assert_post_lower_invariants(const nir_shader *nir, bool g17p, bool m5,

static void
agx_preprocess_nir_internal(nir_shader *nir, bool g17p, bool native_fragment_depth,
bool g18g, bool m5, bool chip_g17p, bool post_lower)
bool g18g, bool m5, bool chip_g17p, bool post_lower,
bool defer_idiv)
{
if (!nir)
return;
Expand Down Expand Up @@ -15548,10 +15549,15 @@ agx_preprocess_nir_internal(nir_shader *nir, bool g17p, bool native_fragment_dep
* provably nonnegative operands first so the remaining lowering drops
* redundant sign fixups. Other integer division waits for the shader key
* (agx_nir_lower_integer_division), which decides whether a preamble forms.
* The first preprocessing of a Vulkan compute shader may defer these passes
* so compute-kernel matchers see the raw idiv/udiv/irem/imod/umod by a
* constant; hk_lower_nir() preprocesses it again before backend compilation.
*/
NIR_PASS(_, nir, agx_nir_opt_iv_divmod);
NIR_PASS(_, nir, agx_nir_opt_nonneg_idiv);
NIR_PASS(_, nir, nir_opt_idiv_const, 16);
if (!defer_idiv) {
NIR_PASS(_, nir, agx_nir_opt_iv_divmod);
NIR_PASS(_, nir, agx_nir_opt_nonneg_idiv);
NIR_PASS(_, nir, nir_opt_idiv_const, 16);
}

NIR_PASS(_, nir, nir_opt_deref);
NIR_PASS(_, nir, nir_lower_vars_to_ssa);
Expand Down Expand Up @@ -15631,14 +15637,22 @@ agx_preprocess_nir_internal(nir_shader *nir, bool g17p, bool native_fragment_dep
void
agx_preprocess_nir(nir_shader *nir)
{
agx_preprocess_nir_internal(nir, false, false, false, false, false, false);
agx_preprocess_nir_internal(nir, false, false, false, false, false, false,
false);
}

void
agx_preprocess_nir_native(nir_shader *nir, enum agx_chip chip)
{
agx_preprocess_nir_internal(nir, true, true, false, false,
chip == AGX_CHIP_G17P, false);
chip == AGX_CHIP_G17P, false, false);
}

void
agx_preprocess_nir_native_defer_idiv(nir_shader *nir, enum agx_chip chip)
{
agx_preprocess_nir_internal(nir, true, true, false, false,
chip == AGX_CHIP_G17P, false, true);
}

void
Expand All @@ -15651,7 +15665,8 @@ void
agx_preprocess_nir_g18g(nir_shader *nir)
{
/* Select G18 trig without inheriting G17P subgroup/shared-memory rules. */
agx_preprocess_nir_internal(nir, false, false, true, false, false, false);
agx_preprocess_nir_internal(nir, false, false, true, false, false, false,
false);
}

void
Expand All @@ -15664,7 +15679,7 @@ agx_preprocess_nir_post_lower(nir_shader *nir, enum agx_chip chip)
const bool chip_g17p = chip == AGX_CHIP_G17P;

agx_preprocess_nir_internal(nir, g17p, native_fragment_depth, g18g, m5,
chip_g17p, true);
chip_g17p, true, false);
}

static bool
Expand Down Expand Up @@ -18459,5 +18474,13 @@ agx_compile_shader_nir_preoptimized(nir_shader *nir, struct agx_shader_key *key,
void
agx_preprocess_nir_m5(nir_shader *nir)
{
agx_preprocess_nir_internal(nir, false, true, false, true, false, false);
agx_preprocess_nir_internal(nir, false, true, false, true, false, false,
false);
}

void
agx_preprocess_nir_m5_defer_idiv(nir_shader *nir)
{
agx_preprocess_nir_internal(nir, false, true, false, true, false, false,
true);
}
2 changes: 2 additions & 0 deletions src/asahi/compiler/agx_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ void agx_preprocess_nir_g17p(nir_shader *nir);
/* For any native AGX3 chip (agx_chip_native_agx3); passes validated on G17P
* alone check chip. */
void agx_preprocess_nir_native(nir_shader *nir, enum agx_chip chip);
void agx_preprocess_nir_native_defer_idiv(nir_shader *nir, enum agx_chip chip);
void agx_preprocess_nir_g18g(nir_shader *nir);
/* Fast second-stage preprocessing for shaders already preprocessed once before
* simple I/O or push-constant lowering. Falls back to full preprocessing if any
Expand All @@ -771,6 +772,7 @@ void agx_preprocess_nir_post_lower(nir_shader *nir, enum agx_chip chip);
* AGX3 stack protocol encodes. agx_preprocess_nir_g17p() runs it. */
bool agx3_nir_lower_scratch_words(nir_shader *nir);
void agx_preprocess_nir_m5(nir_shader *nir);
void agx_preprocess_nir_m5_defer_idiv(nir_shader *nir);
bool agx_nir_lower_discard_zs_emit(nir_shader *s);
bool agx_nir_lower_sample_mask(nir_shader *s);
/* TARGET/LIVE retain their normal semantics. This flag records the proof that
Expand Down
7 changes: 4 additions & 3 deletions src/asahi/vulkan/hk_agx3_vdm_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ extern "C" {
* attachmentless layer-zero root lowering and fs.reads_layer, to 46 when
* AGX3 fragment binaries carry on-chip local_read NIR payloads, to 47
* when agx_shader_info gains AGX3 vertex preamble hoist metadata and
* vertex binaries may carry extracted preamble NIR, and to 48 when
* hk_shader_info.vs records per-pipeline vertex input robustness. */
#define HK_AGX3_SHADER_BINARY_VERSION 48u
* vertex binaries may carry extracted preamble NIR, to 48 when
* hk_shader_info.vs records per-pipeline vertex input robustness, and to 49
* when compute shaders carry packed vec4 alternates. */
#define HK_AGX3_SHADER_BINARY_VERSION 49u
#define HK_CLASSIC_SHADER_BINARY_VERSION 37u
/* AGX2 binaries include attachmentless layer-zero root lowering, fs.reads_layer,
* and per-pipeline vertex input robustness in hk_shader_info.vs. */
Expand Down
5 changes: 5 additions & 0 deletions src/asahi/vulkan/hk_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,11 @@ hk_BindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
assert(buffer->vk.device_address == 0);
buffer->vk.device_address =
hk_device_memory_addr(mem) + pBindInfos[i].memoryOffset;
if (!mem->replay_va &&
!(mem->bo->flags & (AGX_BO_SHARED | AGX_BO_SHAREABLE | AGX_BO_HOST_PTR))) {
buffer->storage_backing_handle = mem->bo->handle;
buffer->storage_backing_offset = pBindInfos[i].memoryOffset;
}
}

VK_FROM_HANDLE(hk_device, dev, device);
Expand Down
3 changes: 3 additions & 0 deletions src/asahi/vulkan/hk_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct hk_physical_device;
struct hk_buffer {
struct vk_buffer vk;

uint32_t storage_backing_handle;
uint64_t storage_backing_offset;

/** Reserved VA for sparse buffers, NULL otherwise. */
struct agx_va *va;

Expand Down
9 changes: 8 additions & 1 deletion src/asahi/vulkan/hk_cmd_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* SPDX-License-Identifier: MIT
*/
#include "hk_cmd_buffer.h"
#include "hk_identity_copy4.h"
#include "util/format/u_format.h"
#include "hk_frame_anatomy.h"
#include "hk_ppp_state.h"
Expand Down Expand Up @@ -1651,7 +1652,7 @@ hk_CmdBindDescriptorSets2KHR(
}

static void
hk_push_constants(UNUSED struct hk_cmd_buffer *cmd,
hk_push_constants(struct hk_cmd_buffer *cmd,
struct hk_descriptor_state *desc,
const VkPushConstantsInfoKHR *info)
{
Expand All @@ -1664,6 +1665,12 @@ hk_push_constants(UNUSED struct hk_cmd_buffer *cmd,
desc->push_written_dwords |= mask << first_dw;
}

if (!cmd->in_meta && desc == &cmd->state.cs.descriptors &&
info->offset < HK_COMPUTE_OPT_PUSH_BYTES) {
unsigned size = MIN2(info->size, HK_COMPUTE_OPT_PUSH_BYTES - info->offset);
desc->identity_copy4_push_mask |= BITFIELD64_MASK(size) << info->offset;
}

/* D3D translation layers re-push unchanged constants before most draws.
* While the root is clean the uploaded root holds exactly these bytes, so
* an identical push changes nothing; keep the root and every preparation
Expand Down
1 change: 1 addition & 0 deletions src/asahi/vulkan/hk_cmd_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ static_assert(hk_root_descriptor_offset(set_dynamic_buffer_start) ==
struct hk_descriptor_state {
bool root_dirty;
uint64_t generation;
uint64_t identity_copy4_push_mask;
struct hk_root_descriptor_table root;
/* Immutable command-buffer storage; reset with descriptor state. Only the
* uploaded head and tail are compared, excluding unused dynamic slots. */
Expand Down
Loading