From 832af7776b09869dc5fcbd7130ee7f24f373b83e Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 22 Jul 2022 14:12:37 -0400 Subject: [PATCH] lavapipe: replace lvp_sampler internals with pipe_sampler_state less indirection, less code Reviewed-by: Konstantin Seurer Acked-by: Dave Airlie Part-of: --- src/gallium/frontends/lavapipe/lvp_device.c | 31 ++++++++++++++++---- src/gallium/frontends/lavapipe/lvp_execute.c | 27 +---------------- src/gallium/frontends/lavapipe/lvp_private.h | 4 +-- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index 38a43ad7e2c..2ff04aa3aab 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -22,6 +22,7 @@ */ #include "lvp_private.h" +#include "lvp_conv.h" #include "pipe-loader/pipe_loader.h" #include "git_sha1.h" @@ -2171,16 +2172,36 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateSampler( vk_object_base_init(&device->vk, &sampler->base, VK_OBJECT_TYPE_SAMPLER); - sampler->create_info = *pCreateInfo; VkClearColorValue border_color = vk_sampler_border_color_value(pCreateInfo, NULL); - STATIC_ASSERT(sizeof(sampler->border_color) == sizeof(border_color)); - memcpy(&sampler->border_color, &border_color, sizeof(border_color)); + STATIC_ASSERT(sizeof(sampler->state.border_color) == sizeof(border_color)); - sampler->reduction_mode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; + sampler->state.wrap_s = vk_conv_wrap_mode(pCreateInfo->addressModeU); + sampler->state.wrap_t = vk_conv_wrap_mode(pCreateInfo->addressModeV); + sampler->state.wrap_r = vk_conv_wrap_mode(pCreateInfo->addressModeW); + sampler->state.min_img_filter = pCreateInfo->minFilter == VK_FILTER_LINEAR ? PIPE_TEX_FILTER_LINEAR : PIPE_TEX_FILTER_NEAREST; + sampler->state.min_mip_filter = pCreateInfo->mipmapMode == VK_SAMPLER_MIPMAP_MODE_LINEAR ? PIPE_TEX_MIPFILTER_LINEAR : PIPE_TEX_MIPFILTER_NEAREST; + sampler->state.mag_img_filter = pCreateInfo->magFilter == VK_FILTER_LINEAR ? PIPE_TEX_FILTER_LINEAR : PIPE_TEX_FILTER_NEAREST; + sampler->state.min_lod = pCreateInfo->minLod; + sampler->state.max_lod = pCreateInfo->maxLod; + sampler->state.lod_bias = pCreateInfo->mipLodBias; + if (pCreateInfo->anisotropyEnable) + sampler->state.max_anisotropy = pCreateInfo->maxAnisotropy; + else + sampler->state.max_anisotropy = 1; + sampler->state.normalized_coords = !pCreateInfo->unnormalizedCoordinates; + sampler->state.compare_mode = pCreateInfo->compareEnable ? PIPE_TEX_COMPARE_R_TO_TEXTURE : PIPE_TEX_COMPARE_NONE; + sampler->state.compare_func = pCreateInfo->compareOp; + sampler->state.seamless_cube_map = !(pCreateInfo->flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT); + STATIC_ASSERT((unsigned)VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE == (unsigned)PIPE_TEX_REDUCTION_WEIGHTED_AVERAGE); + STATIC_ASSERT((unsigned)VK_SAMPLER_REDUCTION_MODE_MIN == (unsigned)PIPE_TEX_REDUCTION_MIN); + STATIC_ASSERT((unsigned)VK_SAMPLER_REDUCTION_MODE_MAX == (unsigned)PIPE_TEX_REDUCTION_MAX); if (reduction_mode_create_info) - sampler->reduction_mode = reduction_mode_create_info->reductionMode; + sampler->state.reduction_mode = (enum pipe_tex_reduction_mode)reduction_mode_create_info->reductionMode; + else + sampler->state.reduction_mode = PIPE_TEX_REDUCTION_WEIGHTED_AVERAGE; + memcpy(&sampler->state.border_color, &border_color, sizeof(border_color)); *pSampler = lvp_sampler_to_handle(sampler); diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index de324a1e1d4..2537f076257 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -1041,31 +1041,6 @@ struct dyn_info { uint32_t dynamic_offset_count; }; -static void fill_sampler(struct pipe_sampler_state *ss, - struct lvp_sampler *samp) -{ - ss->wrap_s = vk_conv_wrap_mode(samp->create_info.addressModeU); - ss->wrap_t = vk_conv_wrap_mode(samp->create_info.addressModeV); - ss->wrap_r = vk_conv_wrap_mode(samp->create_info.addressModeW); - ss->min_img_filter = samp->create_info.minFilter == VK_FILTER_LINEAR ? PIPE_TEX_FILTER_LINEAR : PIPE_TEX_FILTER_NEAREST; - ss->min_mip_filter = samp->create_info.mipmapMode == VK_SAMPLER_MIPMAP_MODE_LINEAR ? PIPE_TEX_MIPFILTER_LINEAR : PIPE_TEX_MIPFILTER_NEAREST; - ss->mag_img_filter = samp->create_info.magFilter == VK_FILTER_LINEAR ? PIPE_TEX_FILTER_LINEAR : PIPE_TEX_FILTER_NEAREST; - ss->min_lod = samp->create_info.minLod; - ss->max_lod = samp->create_info.maxLod; - ss->lod_bias = samp->create_info.mipLodBias; - if (samp->create_info.anisotropyEnable) - ss->max_anisotropy = samp->create_info.maxAnisotropy; - else - ss->max_anisotropy = 1; - ss->normalized_coords = !samp->create_info.unnormalizedCoordinates; - ss->compare_mode = samp->create_info.compareEnable ? PIPE_TEX_COMPARE_R_TO_TEXTURE : PIPE_TEX_COMPARE_NONE; - ss->compare_func = samp->create_info.compareOp; - ss->seamless_cube_map = !(samp->create_info.flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT); - ss->reduction_mode = samp->reduction_mode; - memcpy(&ss->border_color, &samp->border_color, - sizeof(union pipe_color_union)); -} - static void fill_sampler_stage(struct rendering_state *state, struct dyn_info *dyn_info, gl_shader_stage stage, @@ -1079,7 +1054,7 @@ static void fill_sampler_stage(struct rendering_state *state, return; ss_idx += array_idx; ss_idx += dyn_info->stage[stage].sampler_count; - fill_sampler(&state->ss[p_stage][ss_idx], binding->immutable_samplers ? binding->immutable_samplers[array_idx] : descriptor->sampler); + state->ss[p_stage][ss_idx] = binding->immutable_samplers ? binding->immutable_samplers[array_idx]->state : descriptor->sampler->state; if (state->num_sampler_states[p_stage] <= ss_idx) state->num_sampler_states[p_stage] = ss_idx + 1; state->ss_dirty[p_stage] = true; diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index 42985b628da..5870a925b79 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -261,9 +261,7 @@ struct lvp_image_view { struct lvp_sampler { struct vk_object_base base; - VkSamplerCreateInfo create_info; - union pipe_color_union border_color; - VkSamplerReductionMode reduction_mode; + struct pipe_sampler_state state; }; struct lvp_descriptor_set_binding_layout {