dxil: Use nir_const_value_for_uint in dxil_nir_lower_int_samplers

This change should avoid any accidental rounding issues because of
border colors getting stored in a float in dxil_wrap_sampler_state.  It
also switches us to using the correct helpers for nir_const_value so we
can avoid any weird uninitialized data failures that can be caused by
filling out the fields in the struct directly.

Fixes: b9c61379ab ("microsoft/compiler: translate nir to dxil")
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19689>
(cherry picked from commit cd5c66e165)
This commit is contained in:
Jason Ekstrand 2022-11-11 15:14:16 -06:00 committed by Eric Engestrom
parent 3b5c8ec1a9
commit b34f6c1559
2 changed files with 10 additions and 5 deletions

View file

@ -4045,7 +4045,7 @@
"description": "dxil: Use nir_const_value_for_uint in dxil_nir_lower_int_samplers",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "b9c61379ab4c5065d624fb9403c1df9d5589b313"
},

View file

@ -217,7 +217,6 @@ static nir_ssa_def *
load_bordercolor(nir_builder *b, nir_tex_instr *tex, dxil_wrap_sampler_state *active_state,
const dxil_texture_swizzle_state *tex_swizzle)
{
nir_const_value const_value[4] = {{0}};
int ndest_comp = nir_dest_num_components(tex->dest);
unsigned swizzle[4] = {
@ -227,19 +226,25 @@ load_bordercolor(nir_builder *b, nir_tex_instr *tex, dxil_wrap_sampler_state *ac
tex_swizzle->swizzle_a
};
/* Avoid any possible float conversion issues */
uint32_t border_color[4];
memcpy(border_color, active_state->border_color, sizeof(border_color));
STATIC_ASSERT(sizeof(border_color) == sizeof(active_state->border_color));
nir_const_value const_value[4];
for (int i = 0; i < ndest_comp; ++i) {
switch (swizzle[i]) {
case PIPE_SWIZZLE_0:
const_value[i].f32 = 0;
const_value[i] = nir_const_value_for_uint(0, 32);
break;
case PIPE_SWIZZLE_1:
const_value[i].i32 = 1;
const_value[i] = nir_const_value_for_uint(1, 32);
break;
case PIPE_SWIZZLE_X:
case PIPE_SWIZZLE_Y:
case PIPE_SWIZZLE_Z:
case PIPE_SWIZZLE_W:
const_value[i].f32 = active_state->border_color[swizzle[i]];
const_value[i] = nir_const_value_for_uint(border_color[swizzle[i]], 32);
break;
default:
unreachable("Unexpected swizzle value");