From d49586cfae34f4320f9eb56d79b2e62f5c0676d4 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 2 Aug 2022 08:34:12 -0400 Subject: [PATCH] zink: support emulating alpha formats using new border color quirk this works for texturing only because swizzles can be used Reviewed-by: Dave Airlie Part-of: --- src/freedreno/ci/traces-freedreno.yml | 2 +- .../drivers/zink/ci/zink-lvp-fails.txt | 4 -- .../drivers/zink/ci/zink-lvp-skips.txt | 4 ++ .../drivers/zink/ci/zink-radv-fails.txt | 2 - .../drivers/zink/ci/zink-radv-skips.txt | 3 ++ src/gallium/drivers/zink/zink_context.c | 45 +++++++++++++++++++ src/gallium/drivers/zink/zink_screen.c | 21 +++++++-- 7 files changed, 70 insertions(+), 11 deletions(-) diff --git a/src/freedreno/ci/traces-freedreno.yml b/src/freedreno/ci/traces-freedreno.yml index 1a7c93ff06e..dd52c36a91f 100644 --- a/src/freedreno/ci/traces-freedreno.yml +++ b/src/freedreno/ci/traces-freedreno.yml @@ -128,7 +128,7 @@ traces: - device: freedreno-a630 checksum: 730692659fbb9eefa44d6b1a2df2fa8e - device: zink-a630 - checksum: 5a97da6dbb6c10d615f92030c03d116c + checksum: 165d3c13c8143fbc2265a55758afc04c - path: behdad-glyphy/glyphy.trace expectations: - device: freedreno-a306 diff --git a/src/gallium/drivers/zink/ci/zink-lvp-fails.txt b/src/gallium/drivers/zink/ci/zink-lvp-fails.txt index 669d2021e67..91c0cd59e0f 100644 --- a/src/gallium/drivers/zink/ci/zink-lvp-fails.txt +++ b/src/gallium/drivers/zink/ci/zink-lvp-fails.txt @@ -245,10 +245,6 @@ spec@!opengl 1.0@rasterpos,Fail spec@!opengl 1.0@rasterpos@glsl_vs_gs_linked,Fail spec@!opengl 1.0@rasterpos@glsl_vs_tes_linked,Fail -#these need format conversions that gallium doesn't implement yet -spec@arb_texture_buffer_object@formats (fs- arb),Crash -spec@arb_texture_buffer_object@formats (vs- arb),Crash - spec@arb_arrays_of_arrays@execution@image_store@basic-imagestore-mixed-const-non-const-uniform-index,Fail spec@arb_arrays_of_arrays@execution@image_store@basic-imagestore-mixed-const-non-const-uniform-index2,Fail diff --git a/src/gallium/drivers/zink/ci/zink-lvp-skips.txt b/src/gallium/drivers/zink/ci/zink-lvp-skips.txt index de69f762bba..b9648d5ac16 100644 --- a/src/gallium/drivers/zink/ci/zink-lvp-skips.txt +++ b/src/gallium/drivers/zink/ci/zink-lvp-skips.txt @@ -42,3 +42,7 @@ glx@glx-tfp # These tests started hitting timeouts when we upgraded LLVM from v11 to 13 spec@arb_texture_rg@fbo-blending-formats + +#these need format conversions that gallium doesn't implement yet +spec@arb_texture_buffer_object@formats.*arb.* + diff --git a/src/gallium/drivers/zink/ci/zink-radv-fails.txt b/src/gallium/drivers/zink/ci/zink-radv-fails.txt index c486a93170d..69f6b80d4f9 100644 --- a/src/gallium/drivers/zink/ci/zink-radv-fails.txt +++ b/src/gallium/drivers/zink/ci/zink-radv-fails.txt @@ -239,8 +239,6 @@ spec@arb_shader_texture_lod@execution@glsl-fs-shadow2dgradarb-cumulative,Fail spec@arb_shading_language_packing@execution@built-in-functions@fs-packhalf2x16,Fail spec@arb_shading_language_packing@execution@built-in-functions@vs-packhalf2x16,Fail spec@arb_tessellation_shader@arb_tessellation_shader-tes-gs-max-output -small -scan 1 50,Crash -spec@arb_texture_buffer_object@formats (fs- arb),Crash -spec@arb_texture_buffer_object@formats (vs- arb),Crash spec@arb_texture_float@fbo-blending-formats,Fail spec@arb_texture_float@fbo-blending-formats@GL_INTENSITY16F_ARB,Fail spec@arb_texture_float@fbo-blending-formats@GL_INTENSITY32F_ARB,Fail diff --git a/src/gallium/drivers/zink/ci/zink-radv-skips.txt b/src/gallium/drivers/zink/ci/zink-radv-skips.txt index 641f74734c4..ae11e30ff22 100644 --- a/src/gallium/drivers/zink/ci/zink-radv-skips.txt +++ b/src/gallium/drivers/zink/ci/zink-radv-skips.txt @@ -18,3 +18,6 @@ glx@glx-tfp # Tests below timeout most of the time. KHR-GL46.copy_image.functional KHR-GL46.texture_swizzle.smoke + +#these need format conversions that gallium doesn't implement yet +spec@arb_texture_buffer_object@formats.*arb.* diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 885a31d0c69..91ab59876a5 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -871,6 +871,36 @@ clamp_zs_swizzle(enum pipe_swizzle swizzle) return swizzle; } +ALWAYS_INLINE static enum pipe_swizzle +clamp_alpha_swizzle(enum pipe_swizzle swizzle) +{ + if (swizzle == PIPE_SWIZZLE_W) + return PIPE_SWIZZLE_X; + if (swizzle < PIPE_SWIZZLE_W) + return PIPE_SWIZZLE_0; + return swizzle; +} + +ALWAYS_INLINE static enum pipe_swizzle +clamp_luminance_swizzle(enum pipe_swizzle swizzle) +{ + if (swizzle == PIPE_SWIZZLE_W) + return PIPE_SWIZZLE_1; + if (swizzle < PIPE_SWIZZLE_W) + return PIPE_SWIZZLE_X; + return swizzle; +} + +ALWAYS_INLINE static enum pipe_swizzle +clamp_luminance_alpha_swizzle(enum pipe_swizzle swizzle) +{ + if (swizzle == PIPE_SWIZZLE_W) + return PIPE_SWIZZLE_Y; + if (swizzle < PIPE_SWIZZLE_W) + return PIPE_SWIZZLE_X; + return swizzle; +} + ALWAYS_INLINE static bool viewtype_is_cube(const VkImageViewCreateInfo *ivci) { @@ -945,6 +975,21 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres, ivci.components.g = zink_component_mapping(zink_clamp_void_swizzle(desc, sampler_view->base.swizzle_g)); ivci.components.b = zink_component_mapping(zink_clamp_void_swizzle(desc, sampler_view->base.swizzle_b)); ivci.components.a = zink_component_mapping(zink_clamp_void_swizzle(desc, sampler_view->base.swizzle_a)); + } else if (util_format_is_alpha(state->format)) { + ivci.components.r = zink_component_mapping(clamp_alpha_swizzle(sampler_view->base.swizzle_r)); + ivci.components.g = zink_component_mapping(clamp_alpha_swizzle(sampler_view->base.swizzle_g)); + ivci.components.b = zink_component_mapping(clamp_alpha_swizzle(sampler_view->base.swizzle_b)); + ivci.components.a = zink_component_mapping(clamp_alpha_swizzle(sampler_view->base.swizzle_a)); + } else if (util_format_is_luminance(state->format)) { + ivci.components.r = zink_component_mapping(clamp_luminance_swizzle(sampler_view->base.swizzle_r)); + ivci.components.g = zink_component_mapping(clamp_luminance_swizzle(sampler_view->base.swizzle_g)); + ivci.components.b = zink_component_mapping(clamp_luminance_swizzle(sampler_view->base.swizzle_b)); + ivci.components.a = zink_component_mapping(clamp_luminance_swizzle(sampler_view->base.swizzle_a)); + } else if (util_format_is_luminance_alpha(state->format)) { + ivci.components.r = zink_component_mapping(clamp_luminance_alpha_swizzle(sampler_view->base.swizzle_r)); + ivci.components.g = zink_component_mapping(clamp_luminance_alpha_swizzle(sampler_view->base.swizzle_g)); + ivci.components.b = zink_component_mapping(clamp_luminance_alpha_swizzle(sampler_view->base.swizzle_b)); + ivci.components.a = zink_component_mapping(clamp_luminance_alpha_swizzle(sampler_view->base.swizzle_a)); } else { ivci.components.r = zink_component_mapping(sampler_view->base.swizzle_r); ivci.components.g = zink_component_mapping(sampler_view->base.swizzle_g); diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index a4deb00635b..51d2cfaae0d 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -550,9 +550,10 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param) case PIPE_CAP_GL_CLAMP: return 0; - case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK: + case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK: { + enum pipe_quirk_texture_border_color_swizzle quirk = PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_ALPHA_NOT_W; if (!screen->info.border_color_feats.customBorderColorWithoutFormat) - return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO; + return quirk | PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO; /* assume that if drivers don't implement this extension they either: * - don't support custom border colors * - handle things correctly @@ -560,8 +561,9 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param) */ if (screen->info.have_EXT_border_color_swizzle && !screen->info.border_swizzle_feats.borderColorSwizzleFromImage) - return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50; - return 0; + return quirk | PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50; + return quirk; + } case PIPE_CAP_MAX_TEXTURE_2D_SIZE: return screen->info.props.limits.maxImageDimension2D; @@ -1515,6 +1517,8 @@ emulate_x8(enum pipe_format format) VkFormat zink_get_format(struct zink_screen *screen, enum pipe_format format) { + format = zink_format_get_emulated_alpha(format); + VkFormat ret = zink_pipe_format_to_vk_format(emulate_x8(format)); if (format == PIPE_FORMAT_X32_S8X24_UINT && @@ -1544,6 +1548,9 @@ zink_get_format(struct zink_screen *screen, enum pipe_format format) !screen->info.format_4444_feats.formatA4R4G4B4)) return VK_FORMAT_UNDEFINED; + if (format == PIPE_FORMAT_R4A4_UNORM) + return VK_FORMAT_R4G4_UNORM_PACK8; + return ret; } @@ -1755,6 +1762,12 @@ populate_format_props(struct zink_screen *screen) } } else VKSCR(GetPhysicalDeviceFormatProperties)(screen->pdev, format, &screen->format_props[i]); + if (zink_format_is_emulated_alpha(i)) { + VkFormatFeatureFlags blocked = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; + screen->format_props[i].linearTilingFeatures &= ~blocked; + screen->format_props[i].optimalTilingFeatures &= ~blocked; + screen->format_props[i].bufferFeatures = 0; + } } VkImageFormatProperties image_props; VkResult ret = VKSCR(GetPhysicalDeviceImageFormatProperties)(screen->pdev, VK_FORMAT_D32_SFLOAT,