v3dv: fix color border clamping with specific formats

For some reason, CTS expects E5B9G9R9 and B10G11R11 with
transparent black border clamping produce alpha 1 instead of 0.

Since border color takes precedence over the texture state swizzle,
the only way to fix this is to lower the texture swizzle in the shader
to set alpha to 1.

Fixes:
dEQP-VK.pipeline.sampler.view_type.*b10g11r11*clamp_to_border_transparent_black
dEQP-VK.pipeline.sampler.view_type.*e5b9g9r9*.clamp_to_border_transparent_black

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
This commit is contained in:
Iago Toral Quiroga
2020-07-03 10:06:28 +02:00
committed by Marge Bot
parent f156c5dc4d
commit 3bd02a729a
3 changed files with 40 additions and 9 deletions

View File

@@ -2625,11 +2625,26 @@ cmd_buffer_populate_v3d_key(struct v3d_key *key,
key->tex[combined_idx].return_channels = 4;
}
/* Note: we don't need to do anything for the swizzle, as that is
* handled with the swizzle info at the Texture State, and the
* default values for key->tex[].swizzle were already filled up on
* the pipeline populate.
*/
/* Note: In general, we don't need to do anything for the swizzle, as
* that is handled with the swizzle info at the Texture State, and the
* default values for key->tex[].swizzle were already filled up at
* the pipeline creation time.
*
* The only exeption in which we want to apply a texture swizzle
* lowering in the shader is to force alpha to 1 when using clamp
* to border with transparent black in combination with specific
* formats.
*/
if (sampler && sampler->clamp_to_transparent_black_border) {
switch (image_view->vk_format) {
case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
key->tex[combined_idx].swizzle[3] = PIPE_SWIZZLE_1;
break;
default:
break;
}
}
}
}
}

View File

@@ -2016,10 +2016,10 @@ pack_sampler_state(struct v3dv_sampler *sampler,
{
enum V3DX(Border_Color_Mode) border_color_mode;
/* FIXME: direct border_color_mode mapping would work with some specific
* formats, but some others it would be needed to use
* V3D_BORDER_COLOR_FOLLOWS, and fill up
* SAMPLER_STATE.border_color_word_[0/1/2/3]
/* For now we only support the preset Vulkan border color modes. If we
* want to implement VK_EXT_custom_border_color in the future we would have
* to use V3D_BORDER_COLOR_FOLLOWS, and fill up border_color_word_[0/1/2/3]
* SAMPLER_STATE.
*/
switch (pCreateInfo->borderColor) {
case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
@@ -2039,6 +2039,21 @@ pack_sampler_state(struct v3dv_sampler *sampler,
break;
}
/* For some texture formats, when clamping to transparent black border the
* CTS expects alpha to be set to 1 instead of 0, but the border color mode
* will take priority over the texture state swizzle, so the only way to
* fix that is to apply a swizzle in the shader. Here we keep track of
* whether we are activating that mode and we will decide if we need to
* activate the texture swizzle lowering in the shader key at compile time
* depending on the actual texture format.
*/
if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) &&
border_color_mode == V3D_BORDER_COLOR_0000) {
sampler->clamp_to_transparent_black_border = true;
}
v3dv_pack(sampler->sampler_state, SAMPLER_STATE, s) {
if (pCreateInfo->anisotropyEnable) {
s.anisotropy_enable = true;

View File

@@ -1381,6 +1381,7 @@ struct v3dv_descriptor_map {
struct v3dv_sampler {
bool compare_enable;
bool unnormalized_coordinates;
bool clamp_to_transparent_black_border;
/* Prepacked SAMPLER_STATE, that is referenced as part of the tmu
* configuration. If needed it will be copied to the descriptor info during