From 1e2dcae4da7f5754bcdbb1739c516c023c32d476 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 31 Aug 2024 08:52:52 -0400 Subject: [PATCH] asahi,hk: deduplicate txf sampler settings Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/agx_helpers.h | 15 +++++++++++++++ src/asahi/vulkan/hk_device.c | 12 ++---------- src/gallium/drivers/asahi/agx_state.c | 11 +---------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/asahi/lib/agx_helpers.h b/src/asahi/lib/agx_helpers.h index 7dd8ddaabda..190d2627be9 100644 --- a/src/asahi/lib/agx_helpers.h +++ b/src/asahi/lib/agx_helpers.h @@ -48,6 +48,21 @@ agx_translate_sampler_state_count(unsigned count, bool extended) } } +static void +agx_pack_txf_sampler(struct agx_sampler_packed *out) +{ + agx_pack(out, SAMPLER, cfg) { + /* Allow mipmapping. This is respected by txf, weirdly. */ + cfg.mip_filter = AGX_MIP_FILTER_NEAREST; + + /* Out-of-bounds reads must return 0 */ + cfg.wrap_s = AGX_WRAP_CLAMP_TO_BORDER; + cfg.wrap_t = AGX_WRAP_CLAMP_TO_BORDER; + cfg.wrap_r = AGX_WRAP_CLAMP_TO_BORDER; + cfg.border_colour = AGX_BORDER_COLOUR_TRANSPARENT_BLACK; + } +} + /* Channels agree for RGBA but are weird for force 0/1 */ static inline enum agx_channel diff --git a/src/asahi/vulkan/hk_device.c b/src/asahi/vulkan/hk_device.c index 6a002c2d135..2195d485da0 100644 --- a/src/asahi/vulkan/hk_device.c +++ b/src/asahi/vulkan/hk_device.c @@ -7,6 +7,7 @@ #include "hk_device.h" #include "agx_bg_eot.h" +#include "agx_helpers.h" #include "agx_opcodes.h" #include "agx_scratch.h" #include "hk_cmd_buffer.h" @@ -58,16 +59,7 @@ hk_upload_rodata(struct hk_device *dev) cfg.buffer = dev->rodata.bo->va->addr + offs; } - agx_pack(map + offs, SAMPLER, cfg) { - /* Allow mipmapping. This is respected by txf, weirdly. */ - cfg.mip_filter = AGX_MIP_FILTER_NEAREST; - - /* Out-of-bounds reads must return 0 */ - cfg.wrap_s = AGX_WRAP_CLAMP_TO_BORDER; - cfg.wrap_t = AGX_WRAP_CLAMP_TO_BORDER; - cfg.wrap_r = AGX_WRAP_CLAMP_TO_BORDER; - cfg.border_colour = AGX_BORDER_COLOUR_TRANSPARENT_BLACK; - } + agx_pack_txf_sampler((struct agx_sampler_packed *)(map + offs)); offs += AGX_SAMPLER_LENGTH; /* The image heap is allocated on the device prior to the rodata. The heap diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 552eac5e229..5361dab403b 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -2814,16 +2814,7 @@ agx_upload_samplers(struct agx_batch *batch, struct agx_compiled_shader *cs, agx_pool_alloc_aligned(&batch->pool, sampler_length * nr_samplers, 64); /* Sampler #0 is reserved for txf */ - agx_pack(T.cpu, SAMPLER, cfg) { - /* Allow mipmapping. This is respected by txf, weirdly. */ - cfg.mip_filter = AGX_MIP_FILTER_NEAREST; - - /* Out-of-bounds reads must return 0 */ - cfg.wrap_s = AGX_WRAP_CLAMP_TO_BORDER; - cfg.wrap_t = AGX_WRAP_CLAMP_TO_BORDER; - cfg.wrap_r = AGX_WRAP_CLAMP_TO_BORDER; - cfg.border_colour = AGX_BORDER_COLOUR_TRANSPARENT_BLACK; - } + agx_pack_txf_sampler(T.cpu); /* Remaining samplers are API samplers */ uint8_t *out_sampler = (uint8_t *)T.cpu + sampler_length;