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
3 changes: 1 addition & 2 deletions src/asahi/vulkan/hk_buffer_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ hk_get_buffer_format_features(struct hk_physical_device *pdev,

if (p_format == PIPE_FORMAT_R32_UINT || p_format == PIPE_FORMAT_R32_SINT ||
(p_format == PIPE_FORMAT_R32_FLOAT &&
(agx_chip_native_hal200(pdev->dev.chip) ||
agx_chip_g17_m5(pdev->dev.chip))))
pdev->vk.supported_features.shaderImageFloat32Atomics))
features |= VK_FORMAT_FEATURE_2_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
}

Expand Down
6 changes: 2 additions & 4 deletions src/asahi/vulkan/hk_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev,

enum pipe_format p_format = hk_format_to_pipe_format(vk_format);
/* D16S8 uses the existing independent D16 and S8 planes, as D32S8 does
* on G17P and M5. */
* across all generations. */
if (vk_format == VK_FORMAT_D16_UNORM_S8_UINT) {
if (!agx_chip_g17p_or_m5(pdev->dev.chip))
return 0;
p_format = PIPE_FORMAT_Z16_UNORM;
}
if (p_format == PIPE_FORMAT_NONE)
Expand Down Expand Up @@ -233,7 +231,7 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev,
/* Our image atomic lowering doesn't bother to handle linear */
if ((p_format == PIPE_FORMAT_R32_UINT || p_format == PIPE_FORMAT_R32_SINT ||
(p_format == PIPE_FORMAT_R32_FLOAT &&
agx_chip_g17p_or_m5(pdev->dev.chip))) &&
pdev->vk.supported_features.shaderImageFloat32Atomics)) &&
tiling == VK_IMAGE_TILING_OPTIMAL) {

features |= VK_FORMAT_FEATURE_2_STORAGE_IMAGE_ATOMIC_BIT;
Expand Down
25 changes: 23 additions & 2 deletions src/asahi/vulkan/hk_nir_lower_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "hk_descriptor_set.h"
#include "hk_descriptor_set_layout.h"
#include "hk_sampler.h"
#include "hk_sampler_index.h"
#include "hk_native_descriptor.h"
#include "hk_shader.h"
#include "hk_nir_sampler_bias.h"
Expand Down Expand Up @@ -1241,7 +1242,8 @@ lower_compute_lod_query(nir_builder *b, nir_tex_instr *tex,
/* Task and mesh shaders with a derivative group take the compute
* derivatives (meshAndTaskShaderDerivatives). */
if (tex->op != nir_texop_lod ||
(ctx->descriptor_generation != 9 && ctx->descriptor_generation != 10) ||
(!hk_descriptor_generation_is_agx2(ctx->descriptor_generation) &&
ctx->descriptor_generation != 9 && ctx->descriptor_generation != 10) ||
!mesa_shader_stage_uses_workgroup(b->shader->info.stage) ||
b->shader->info.derivative_group == DERIVATIVE_GROUP_NONE)
return false;
Expand Down Expand Up @@ -1274,7 +1276,26 @@ lower_compute_lod_query(nir_builder *b, nir_tex_instr *tex,
const uint64_t plane_offset_B = plane * native.stride;

nir_def *word, *api_bias;
if (ctx->descriptor_generation == 9) {
if (hk_descriptor_generation_is_agx2(ctx->descriptor_generation)) {
nir_def *published = load_resource_deref_desc(
b, 1, 16, sampler, plane_offset_B + native.sampler_index, ctx);
nir_def *published32 = nir_u2u32(b, published);
nir_def *index = nir_bcsel(
b, nir_uge_imm(b, published32, HK_SAMPLER_AGX2_BIAS),
nir_iadd_imm(b, published32, -(int)HK_SAMPLER_AGX2_BIAS),
nir_imm_int(b, 0));
api_bias = nir_f2f32(
b, load_resource_deref_desc(b, 1, 16, sampler,
plane_offset_B + native.lod_bias, ctx));
nir_def *heap = load_root(
b, 1, 64,
nir_imm_int(b, hk_root_descriptor_offset(sampler_heap_address)), 8);
nir_def *addr = nir_iadd(
b, heap,
nir_imul_imm(b, nir_u2u64(b, index),
agx_chip_sampler_heap_element_size(AGX_CHIP_G13G)));
word = load_speculatable(b, 1, 32, addr, 8);
} else if (ctx->descriptor_generation == 9) {
nir_def *index = load_resource_deref_desc(
b, 1, 16, sampler, plane_offset_B + native.sampler_index, ctx);
api_bias = load_resource_deref_desc(
Expand Down
50 changes: 14 additions & 36 deletions src/asahi/vulkan/hk_physical_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ hk_get_device_extensions(const struct agx_device *dev,
.KHR_bind_memory2 = true,
.KHR_buffer_device_address = true,
.KHR_calibrated_timestamps = true,
.KHR_compute_shader_derivatives = true,
.KHR_copy_commands2 = true,
.KHR_create_renderpass2 = true,
.KHR_dedicated_allocation = true,
Expand Down Expand Up @@ -345,8 +346,8 @@ hk_get_device_extensions(const struct agx_device *dev,
.EXT_sampler_filter_minmax = false,
.EXT_scalar_block_layout = true,
.EXT_separate_stencil_usage = true,
.EXT_shader_atomic_float = false,
.EXT_shader_atomic_float2 = false,
.EXT_shader_atomic_float = true,
.EXT_shader_atomic_float2 = true,
.EXT_shader_image_atomic_int64 = false,
.EXT_shader_demote_to_helper_invocation = true,
.EXT_shader_module_identifier = true,
Expand All @@ -362,6 +363,9 @@ hk_get_device_extensions(const struct agx_device *dev,
.EXT_swapchain_maintenance1 = true,
#endif
.EXT_texel_buffer_alignment = true,
/* Hardware ASTC HDR decode is supported across AGX2 and native AGX3
* (G13-G17P); keep HAL300 off until qualified on M5 hardware. */
.EXT_texture_compression_astc_hdr = !agx_chip_hal300_path(dev->chip),
.EXT_tooling_info = true,
.EXT_transform_feedback = true,

Expand Down Expand Up @@ -1082,21 +1086,16 @@ hk_get_device_features(
* fragment entry and prevent merging triangles across derivative quads.
*/
features->shaderQuadControl = dev->chip == AGX_CHIP_G17P;

/* Qualified on A18 Pro only. */
if (dev->chip == AGX_CHIP_G17P) {
features->computeDerivativeGroupQuads = true;
features->computeDerivativeGroupLinear = true;
features->textureCompressionASTC_HDR = true;
}
}

/* Compute derivatives are NIR quad-swap lowering plus explicit-gradient
* samples, both available on M5; quad control remains restricted to G17P. */
if (agx_chip_g17_m5(dev->chip)) {
features->computeDerivativeGroupQuads = true;
features->computeDerivativeGroupLinear = true;
}
/* Compute derivatives lower in NIR to quad swaps and explicit-gradient
* texture operations, available across all generations. */
features->computeDerivativeGroupQuads =
supported_extensions->KHR_compute_shader_derivatives;
features->computeDerivativeGroupLinear =
supported_extensions->KHR_compute_shader_derivatives;
features->textureCompressionASTC_HDR =
supported_extensions->EXT_texture_compression_astc_hdr;

/* A multiview promise for a stage this device does not expose is
* meaningless, so keep the pair consistent however the stage bits above
Expand Down Expand Up @@ -2278,27 +2277,6 @@ hk_create_drm_physical_device(struct vk_instance *_instance,
pdev->dev.chip == AGX_CHIP_G17P;
}

if (pdev->dev.chip == AGX_CHIP_G17P) {
/* Advanced blending is hardware-qualified on A18 Pro for every
* operation and advertised overlap/premultiplication mode, including
* coherent sequencing, across the bounded one-attachment profile. */
supported_extensions.KHR_compute_shader_derivatives = true;
supported_extensions.EXT_shader_atomic_float = true;
supported_extensions.EXT_shader_atomic_float2 = true;
supported_extensions.EXT_texture_compression_astc_hdr = true;
}

if (agx_chip_g17_m5(pdev->dev.chip))
supported_extensions.KHR_compute_shader_derivatives = true;

/* AGX3C has no witnessed native float atomic; agx_nir_lower_atomics turns
* fp32 add/min/max on buffers, shared memory and (lowered) images into
* compare-and-swap loops, so the same feature set is exact on M5. */
if (agx_chip_g17_m5(pdev->dev.chip)) {
supported_extensions.EXT_shader_atomic_float = true;
supported_extensions.EXT_shader_atomic_float2 = true;
}

struct vk_features supported_features;
/* G17P runs mesh shaders natively and task shaders in software. */
if (pdev->dev.chip == AGX_CHIP_G17P)
Expand Down
24 changes: 14 additions & 10 deletions src/asahi/vulkan/hk_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,29 +585,33 @@ hk_preprocess_nir(struct vk_physical_device *vk_pdev, nir_shader *nir,
UNUSED const struct vk_pipeline_robustness_state *rs)
{
hk_preprocess_nir_internal(vk_pdev, nir);
const enum agx_chip chip = ((struct hk_physical_device *)vk_pdev)->dev.chip;
/* G17P task shaders run as compute kernels, and mesh workgroups map
* invocations to lanes as compute does, so they take the same derivatives
* (meshAndTaskShaderDerivatives). */
const bool g17p_compute_derivatives =
((agx_chip_g17p_or_m5(chip) &&
/* Compute derivatives lower via NIR quad swaps and explicit-gradient
* samples across all chips; mesh/task derivatives follow
* meshAndTaskShaderDerivatives. */
const bool compute_derivative_mode_supported =
nir->info.derivative_group == DERIVATIVE_GROUP_QUADS
? vk_pdev->supported_features.computeDerivativeGroupQuads
: vk_pdev->supported_features.computeDerivativeGroupLinear;
const bool lower_compute_derivatives =
((compute_derivative_mode_supported &&
nir->info.stage == MESA_SHADER_COMPUTE) ||
(chip == AGX_CHIP_G17P && (nir->info.stage == MESA_SHADER_TASK ||
nir->info.stage == MESA_SHADER_MESH))) &&
(vk_pdev->properties.meshAndTaskShaderDerivatives &&
(nir->info.stage == MESA_SHADER_TASK ||
nir->info.stage == MESA_SHADER_MESH))) &&
nir->info.derivative_group != DERIVATIVE_GROUP_NONE;
nir_lower_compute_system_values_options csv_options = {
/* Only vkCmdDispatchBase has a base workgroup. Task/mesh draws have
* none, and their root is the graphics arm: root.cs.base_group
* (byte 88) overlays root.draw.attrib_clamps[2..4] there. */
.has_base_workgroup_id = nir->info.stage == MESA_SHADER_COMPUTE,
};
if (g17p_compute_derivatives &&
if (lower_compute_derivatives &&
nir->info.derivative_group == DERIVATIVE_GROUP_QUADS) {
NIR_PASS(_, nir, agx_nir_lower_quad_derivative_ids);
csv_options.shuffle_local_ids_for_quad_derivatives = true;
}
NIR_PASS(_, nir, nir_lower_compute_system_values, &csv_options);
if (g17p_compute_derivatives)
if (lower_compute_derivatives)
NIR_PASS(_, nir, agx_nir_lower_compute_derivatives);
}

Expand Down