Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions src/asahi/compiler/agx_nir_lower_g17p_combined_sampler.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ g17p_sample_shape(const nir_tex_instr *tex, bool m5, bool g17p)
* handle, which has no AGX3 encoding, and the pipeline failed
* with VK_ERROR_UNKNOWN. */
!register_level && !register_bias &&
/* G17P also takes a constant level or bias: the backend keeps
* it in a register (agx_optimizer_inline_imm), so it is staged
* beside the layer like a per-lane one. */
/* AGX3B native backends also take a constant level or bias: the
* backend keeps it in a register (agx_optimizer_inline_imm), so it
* is staged beside the layer like a per-lane one. */
!(g17p && !cube &&
((tex->op == nir_texop_txl && level_src >= 0) ||
(tex->op == nir_texop_txb && bias_src >= 0))) &&
Expand Down
4 changes: 2 additions & 2 deletions src/asahi/compiler/agx_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,14 @@ agx_optimizer_inline_imm(agx_context *ctx, agx_instr **defs, agx_instr *I)
(I->lod_mode == AGX_LOD_MODE_LOD_MIN ||
I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS)))
continue;
/* A G17P array comparison without an offset stages its level or bias
/* An AGX3B array comparison without an offset stages its level or bias
* beside the layer from a register; an immediate would share SMP's
* operand with that layer, which agx3_emit_texture_sample() refuses.
* A zero level or bias, and an explicit level in a stage the packer
* treats as vertex_explicit_lod, encode as immediates and keep them. */
if (I->op == AGX_OPCODE_TEXTURE_SAMPLE && s == 1 && I->shadow &&
!I->offset && I->dim == AGX_DIM_2D_ARRAY &&
ctx->key->dev.chip == AGX_CHIP_G17P &&
ctx->key->dev.encoding == AGX_ISA_ENCODING_AGX3B &&
(def->dest[0].size == AGX_SIZE_16 ? _mesa_half_to_float(def->imm)
: uif(def->imm)) != 0.0f &&
!(I->lod_mode == AGX_LOD_MODE_LOD_MIN &&
Expand Down
14 changes: 11 additions & 3 deletions src/asahi/compiler/test/test-native-form-regressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7346,11 +7346,11 @@ TEST(NativeForms, CooperativeMatrixDefaultsFollowTheImplementedEncoding)
EXPECT_FALSE(agx_chip_cooperative_matrix_supported(AGX_CHIP_G18G));
}

/* A G17P 2D-array comparison keeps a nonzero constant level or bias in a
/* An AGX3B 2D-array comparison keeps a nonzero constant level or bias in a
* register, since agx3_emit_texture_sample() refuses that immediate. Every
* form the packer already encoded keeps its immediate, so no shader that
* compiled before compiles differently. */
TEST(NativeForms, G17PArrayShadowConstantLodKeepsEncodableImmediates)
TEST(NativeForms, AGX3BArrayShadowConstantLodKeepsEncodableImmediates)
{
struct {
mesa_shader_stage stage;
Expand Down Expand Up @@ -7380,9 +7380,17 @@ TEST(NativeForms, G17PArrayShadowConstantLodKeepsEncodableImmediates)
AGX_CHIP_G17P, true},
{MESA_SHADER_FRAGMENT, AGX_LOD_MODE_LOD_MIN, 0x4000, true,
AGX_CHIP_G17P, true},
/* Other chips are unchanged. */
/* Other AGX3B chips (G16G, G15G) follow the same staging rule. */
{MESA_SHADER_FRAGMENT, AGX_LOD_MODE_LOD_MIN, 0x4000, false,
AGX_CHIP_G16G, false},
{MESA_SHADER_FRAGMENT, AGX_LOD_MODE_AUTO_LOD_BIAS, 0x3800, false,
AGX_CHIP_G16G, false},
{MESA_SHADER_FRAGMENT, AGX_LOD_MODE_LOD_MIN, 0x0000, false,
AGX_CHIP_G16G, true},
{MESA_SHADER_FRAGMENT, AGX_LOD_MODE_LOD_MIN, 0x4000, false,
AGX_CHIP_G15G, false},
{MESA_SHADER_FRAGMENT, AGX_LOD_MODE_LOD_MIN, 0x0000, false,
AGX_CHIP_G15G, true},
};
for (const auto &c : cases) {
SCOPED_TRACE(::testing::Message()
Expand Down
10 changes: 5 additions & 5 deletions src/asahi/vulkan/hk_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,19 @@ hk_agx2_packed_float_copy(enum agx_chip chip, VkFormat format)
/* Whether end-of-tile programs store R11G11B10F through its own class, under
* the lane class of packed 32-bit formats (see hk_eot_key_format()), rather
* than as the raw tile word through an R32_UINT PBE. The stored bytes are the
* same. The reason is the end-of-tile PBE of the G17P profile: when an
* same. The reason is the end-of-tile PBE of the HAL200 profile: when an
* end-of-tile program resolves a multisampled tile into its single-sample
* target, only this class averages the packed fields. Through the raw 32-bit
* class no resolved pixel is its samples' mean, and the wrong value changes
* from run to run (aurora-r11g11b10f 2, res-eot). It is also the only class
* that could write the format compressed. The PBE is the same on every G17P
* SoC, so all of them take it: measured on the M4 Pro (since c724930c) and
* the M4 Max; the A18 Pro has the same PBE classes and has not been measured.
* that could write the format compressed. The PBE is shared across native
* HAL200 SoCs (G17P and G16G), so all of them take it: measured on M4 (G16G),
* M4 Pro (since c724930c), and M4 Max, and shared by A18 Pro.
* M5 already stores the format in its own class (agx_rt0_pbe_format()). */
static inline bool
hk_eot_r11g11b10_own_class(const struct agx_device *dev)
{
return dev->chip == AGX_CHIP_G17P;
return agx_chip_native_hal200(dev->chip);
}

/* The format an end-of-tile PBE stores a target through. */
Expand Down
29 changes: 15 additions & 14 deletions src/asahi/vulkan/hk_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5653,18 +5653,18 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
xfb_info = &shader->info.xfb_info;
}

/* Only G17P's backend keeps an array comparison's constant level or bias
* in a register (agx_optimizer_inline_imm), so only G17P admits one to
* the sampler lowerings below. */
const bool g17p = dev->dev.chip == AGX_CHIP_G17P;
/* AGX3B native backends keep an array comparison's constant level or bias
* in a register (agx_optimizer_inline_imm), so native AGX3 chips admit one
* to the sampler lowerings below. */
const bool native_agx3 = agx_chip_native_agx3(dev->dev.chip);
if (agx_chip_native_or_g18g(dev->dev.chip) &&
nir->info.stage == MESA_SHADER_VERTEX) {
/* Software vertex variants feed geometry/tessellation through CDM.
* They use the same indexed texture heap and shifted vertex uniforms
* as hardware VS variants; legacy descriptor-base/index operands do
* not encode as native G17P texture fetches. Lower before changing the
* NIR stage so both variants retain the vertex preamble convention. */
if (agx_nir_lower_g17p_indexed_samplers(nir, g17p)) {
if (agx_nir_lower_g17p_indexed_samplers(nir, native_agx3)) {
shader->info.agx3_indexed_sampler_valid = true;

/* Native G17P publishes texture/sampler heap pointers in halves
Expand Down Expand Up @@ -5694,7 +5694,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
* the same register-operand SMP form selected after this rewrite. The
* VDM-launched mesh program takes the heaps in uniform halves 0..7 like
* the vertex program (hk_g17p_graphics_uniform_ranges()). */
if (agx_nir_lower_g17p_indexed_samplers(nir, g17p))
if (agx_nir_lower_g17p_indexed_samplers(nir, native_agx3))
shader->info.agx3_indexed_sampler_valid = true;
} else if (agx_chip_native_or_g18g(dev->dev.chip) &&
nir->info.stage == MESA_SHADER_FRAGMENT) {
Expand All @@ -5703,12 +5703,13 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
nir_shader *candidate =
!dev->vk.enabled_features.descriptorBindingSampledImageUpdateAfterBind &&
!(features & HK_FEAT_DESCRIPTOR_BUFFER) &&
agx_nir_g17p_combined_sampler_candidate(nir, g17p)
agx_nir_g17p_combined_sampler_candidate(nir, native_agx3)
? nir_shader_clone(NULL, nir)
: NULL;
struct agx_g17p_combined_sampler_binding binding;
if (candidate &&
agx_nir_lower_g17p_combined_sampler(candidate, &binding, g17p)) {
agx_nir_lower_g17p_combined_sampler(candidate, &binding,
native_agx3)) {
ralloc_free(nir);
nir = candidate;
shader->info.agx3_combined_sampler_valid = true;
Expand All @@ -5721,7 +5722,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
set_count = 0;
} else {
ralloc_free(candidate);
if (agx_nir_lower_g17p_indexed_samplers(nir, g17p))
if (agx_nir_lower_g17p_indexed_samplers(nir, native_agx3))
shader->info.agx3_indexed_sampler_valid = true;
}
} else if (dev->dev.chip == AGX_CHIP_G18G &&
Expand Down Expand Up @@ -5779,7 +5780,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
} else if (ops.has_tex || ops.has_bindless_image_read) {
nir_shader *c = nir_shader_clone(NULL, nir);
shader->info.agx3_indexed_sampler_valid = hk_g18g_keep_lowered(
&nir, c, c && agx_nir_lower_g17p_indexed_samplers(c, g17p));
&nir, c, c && agx_nir_lower_g17p_indexed_samplers(c, native_agx3));
}
}
shader->info.g18_unlowered_image =
Expand Down Expand Up @@ -5829,12 +5830,12 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
}

if (!lowered && record_time_sets && !sampled_uab && ops.has_tex &&
agx_nir_g17p_combined_sampler_candidate(nir, g17p)) {
agx_nir_g17p_combined_sampler_candidate(nir, native_agx3)) {
nir_shader *candidate = nir_shader_clone(NULL, nir);
struct agx_g17p_combined_sampler_binding sampled_binding;
if (candidate &&
agx_nir_lower_g17p_combined_sampler(candidate,
&sampled_binding, g17p)) {
agx_nir_lower_g17p_combined_sampler(candidate, &sampled_binding,
native_agx3)) {
ralloc_free(nir);
nir = candidate;
shader->info.agx3_combined_sampler_valid = true;
Expand All @@ -5851,7 +5852,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator,
if (!lowered && (ops.has_tex || ops.has_bindless_image_read)) {
nir_shader *candidate = nir_shader_clone(NULL, nir);
if (candidate &&
agx_nir_lower_g17p_indexed_samplers(candidate, g17p)) {
agx_nir_lower_g17p_indexed_samplers(candidate, native_agx3)) {
/* Keep the storage image BINDLESS alongside indexed
* samplers.
*
Expand Down
23 changes: 23 additions & 0 deletions src/asahi/vulkan/tests/test-hk-compression-contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,28 @@ query_feedback_disables_color_compression(struct hk_physical_device *pdev)
feedback_hic.identicalMemoryLayout;
}

static void
check_r11g11b10_eot_class(const struct agx_device *dev)
{
const bool own_class = agx_chip_native_hal200(dev->chip);
assert(hk_eot_r11g11b10_own_class(dev) == own_class);

const enum pipe_format pbe =
hk_eot_pbe_format(dev, PIPE_FORMAT_R11G11B10_FLOAT);
const enum pipe_format key =
hk_eot_key_format(dev, PIPE_FORMAT_R11G11B10_FLOAT);
if (own_class) {
assert(pbe == PIPE_FORMAT_R11G11B10_FLOAT);
assert(key == PIPE_FORMAT_R10G10B10A2_UNORM);
} else if (agx_chip_g17_m5(dev->chip)) {
assert(pbe == PIPE_FORMAT_R11G11B10_FLOAT);
assert(key == PIPE_FORMAT_R11G11B10_FLOAT);
} else {
assert(pbe == PIPE_FORMAT_R32_UINT);
assert(key == PIPE_FORMAT_R11G11B10_FLOAT);
}
}

int
main(void)
{
Expand Down Expand Up @@ -228,6 +250,7 @@ main(void)
assert(query_feedback_disables_color_compression(pdev) ==
cases[i].expect_feedback_disables);
check_interchange_modifiers(pdev);
check_r11g11b10_eot_class(&pdev->dev);
}

/* Disabling compression disables the contract query and Interchange too. */
Expand Down
3 changes: 1 addition & 2 deletions src/gallium/drivers/asahi/agx_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -13295,8 +13295,7 @@ agx_g17p_emit_bind_state(struct agx_batch *batch, uint8_t *out,
const struct agx_ppp_hal200_fragment_control_fields control_fields = {
.linked_control = linked_fragment_control,
.shader_tri_merge_disable =
(dev->chip == AGX_CHIP_G17P &&
ctx->fs->b.info.needs_quad_derivatives) ||
ctx->fs->b.info.needs_quad_derivatives ||
(batch->tilebuffer_layout.nr_samples > 1 &&
ctx->fs->epilog_key.write_z) ||
/* The linker's own merge-disable bit. */
Expand Down