nvk: Use vk_sampler_state for nvk_sampler_get_header()
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35624>
This commit is contained in:
committed by
Marge Bot
parent
a33e25185a
commit
5d416a3742
@@ -146,34 +146,33 @@ vk_to_9097_trilin_opt(float max_anisotropy)
|
||||
|
||||
static struct nvk_sampler_header
|
||||
nvk_sampler_get_header(const struct nvk_physical_device *pdev,
|
||||
const struct VkSamplerCreateInfo *info,
|
||||
const struct vk_sampler *vk_sampler)
|
||||
const struct vk_sampler_state *state)
|
||||
{
|
||||
struct nvk_sampler_header samp = {};
|
||||
|
||||
SAMP_SET_U(samp, NV9097, 0, ADDRESS_U,
|
||||
vk_to_9097_address_mode(info->addressModeU));
|
||||
vk_to_9097_address_mode(state->address_mode_u));
|
||||
SAMP_SET_U(samp, NV9097, 0, ADDRESS_V,
|
||||
vk_to_9097_address_mode(info->addressModeV));
|
||||
vk_to_9097_address_mode(state->address_mode_v));
|
||||
SAMP_SET_U(samp, NV9097, 0, ADDRESS_P,
|
||||
vk_to_9097_address_mode(info->addressModeW));
|
||||
vk_to_9097_address_mode(state->address_mode_w));
|
||||
|
||||
if (info->compareEnable) {
|
||||
if (state->compare_enable) {
|
||||
SAMP_SET_B(samp, NV9097, 0, DEPTH_COMPARE, true);
|
||||
SAMP_SET_U(samp, NV9097, 0, DEPTH_COMPARE_FUNC,
|
||||
vk_to_9097_texsamp_compare_op(info->compareOp));
|
||||
vk_to_9097_texsamp_compare_op(state->compare_op));
|
||||
}
|
||||
|
||||
SAMP_SET_B(samp, NV9097, 0, S_R_G_B_CONVERSION, true);
|
||||
SAMP_SET_E(samp, NV9097, 0, FONT_FILTER_WIDTH, SIZE_2);
|
||||
SAMP_SET_E(samp, NV9097, 0, FONT_FILTER_HEIGHT, SIZE_2);
|
||||
|
||||
if (info->anisotropyEnable) {
|
||||
if (state->anisotropy_enable) {
|
||||
SAMP_SET_U(samp, NV9097, 0, MAX_ANISOTROPY,
|
||||
vk_to_9097_max_anisotropy(info->maxAnisotropy));
|
||||
vk_to_9097_max_anisotropy(state->max_anisotropy));
|
||||
}
|
||||
|
||||
switch (info->magFilter) {
|
||||
switch (state->mag_filter) {
|
||||
case VK_FILTER_NEAREST:
|
||||
SAMP_SET_E(samp, NV9097, 1, MAG_FILTER, MAG_POINT);
|
||||
break;
|
||||
@@ -184,12 +183,12 @@ nvk_sampler_get_header(const struct nvk_physical_device *pdev,
|
||||
unreachable("Invalid filter");
|
||||
}
|
||||
|
||||
switch (info->minFilter) {
|
||||
switch (state->min_filter) {
|
||||
case VK_FILTER_NEAREST:
|
||||
SAMP_SET_E(samp, NV9097, 1, MIN_FILTER, MIN_POINT);
|
||||
break;
|
||||
case VK_FILTER_LINEAR:
|
||||
if (info->anisotropyEnable)
|
||||
if (state->anisotropy_enable)
|
||||
SAMP_SET_E(samp, NV9097, 1, MIN_FILTER, MIN_ANISO);
|
||||
else
|
||||
SAMP_SET_E(samp, NV9097, 1, MIN_FILTER, MIN_LINEAR);
|
||||
@@ -198,7 +197,7 @@ nvk_sampler_get_header(const struct nvk_physical_device *pdev,
|
||||
unreachable("Invalid filter");
|
||||
}
|
||||
|
||||
switch (info->mipmapMode) {
|
||||
switch (state->mipmap_mode) {
|
||||
case VK_SAMPLER_MIPMAP_MODE_NEAREST:
|
||||
SAMP_SET_E(samp, NV9097, 1, MIP_FILTER, MIP_POINT);
|
||||
break;
|
||||
@@ -210,14 +209,14 @@ nvk_sampler_get_header(const struct nvk_physical_device *pdev,
|
||||
}
|
||||
|
||||
assert(pdev->info.cls_eng3d >= KEPLER_A);
|
||||
if (info->flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT) {
|
||||
if (state->flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT) {
|
||||
SAMP_SET_E(samp, NVA097, 1, CUBEMAP_INTERFACE_FILTERING, USE_WRAP);
|
||||
} else {
|
||||
SAMP_SET_E(samp, NVA097, 1, CUBEMAP_INTERFACE_FILTERING, AUTO_SPAN_SEAM);
|
||||
}
|
||||
|
||||
if (pdev->info.cls_eng3d >= MAXWELL_B) {
|
||||
switch (vk_sampler->reduction_mode) {
|
||||
switch (state->reduction_mode) {
|
||||
case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE:
|
||||
SAMP_SET_E(samp, NVB197, 1, REDUCTION_FILTER, RED_NONE);
|
||||
break;
|
||||
@@ -232,10 +231,10 @@ nvk_sampler_get_header(const struct nvk_physical_device *pdev,
|
||||
}
|
||||
}
|
||||
|
||||
SAMP_SET_SF(samp, NV9097, 1, MIP_LOD_BIAS, info->mipLodBias);
|
||||
SAMP_SET_SF(samp, NV9097, 1, MIP_LOD_BIAS, state->mip_lod_bias);
|
||||
|
||||
assert(pdev->info.cls_eng3d >= KEPLER_A);
|
||||
if (info->unnormalizedCoordinates) {
|
||||
if (state->unnormalized_coordinates) {
|
||||
SAMP_SET_E(samp, NVA097, 1, FLOAT_COORD_NORMALIZATION,
|
||||
FORCE_UNNORMALIZED_COORDS);
|
||||
} else {
|
||||
@@ -243,26 +242,28 @@ nvk_sampler_get_header(const struct nvk_physical_device *pdev,
|
||||
USE_HEADER_SETTING);
|
||||
}
|
||||
SAMP_SET_U(samp, NV9097, 1, TRILIN_OPT,
|
||||
vk_to_9097_trilin_opt(info->maxAnisotropy));
|
||||
vk_to_9097_trilin_opt(state->max_anisotropy));
|
||||
|
||||
SAMP_SET_UF(samp, NV9097, 2, MIN_LOD_CLAMP, info->minLod);
|
||||
SAMP_SET_UF(samp, NV9097, 2, MAX_LOD_CLAMP, info->maxLod);
|
||||
SAMP_SET_UF(samp, NV9097, 2, MIN_LOD_CLAMP, state->min_lod);
|
||||
SAMP_SET_UF(samp, NV9097, 2, MAX_LOD_CLAMP, state->max_lod);
|
||||
|
||||
VkClearColorValue bc = state->border_color_value;
|
||||
|
||||
/* If the image is sRGB, we have to sRGB encode the border color value
|
||||
* BEFORE we swizzle because the swizzle might move alpha around.
|
||||
*/
|
||||
if (state->image_view_is_srgb) {
|
||||
for (uint32_t i = 0; i < 3; i++)
|
||||
bc.float32[i] = util_format_linear_to_srgb_float(bc.float32[i]);
|
||||
}
|
||||
|
||||
/* Swizzle the border color as needed */
|
||||
const bool bc_is_int = vk_border_color_is_int(state->border_color);
|
||||
bc = vk_swizzle_color_value(bc,
|
||||
state->border_color_component_mapping, bc_is_int);
|
||||
|
||||
VkClearColorValue bc = vk_sampler->border_color_value;
|
||||
uint8_t bc_srgb[3];
|
||||
|
||||
const VkSamplerBorderColorComponentMappingCreateInfoEXT *swiz_info =
|
||||
vk_find_struct_const(info->pNext,
|
||||
SAMPLER_BORDER_COLOR_COMPONENT_MAPPING_CREATE_INFO_EXT);
|
||||
if (swiz_info) {
|
||||
if (swiz_info->srgb) {
|
||||
for (uint32_t i = 0; i < 3; i++)
|
||||
bc.float32[i] = util_format_linear_to_srgb_float(bc.float32[i]);
|
||||
}
|
||||
|
||||
const bool is_int = vk_border_color_is_int(info->borderColor);
|
||||
bc = vk_swizzle_color_value(bc, swiz_info->components, is_int);
|
||||
|
||||
if (state->image_view_is_srgb) {
|
||||
for (uint32_t i = 0; i < 3; i++)
|
||||
bc_srgb[i] = _mesa_float_to_unorm(bc.float32[i], 8);
|
||||
} else {
|
||||
@@ -289,24 +290,20 @@ nvk_sampler_get_header(const struct nvk_physical_device *pdev,
|
||||
struct nvk_sampler_header
|
||||
nvk_txf_sampler_header(const struct nvk_physical_device *pdev)
|
||||
{
|
||||
const VkSamplerCreateInfo sampler_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
||||
.magFilter = VK_FILTER_NEAREST,
|
||||
.minFilter = VK_FILTER_NEAREST,
|
||||
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK,
|
||||
.minLod = 0.0,
|
||||
.maxLod = 16.0,
|
||||
.unnormalizedCoordinates = true,
|
||||
const struct vk_sampler_state sampler_state = {
|
||||
.mag_filter = VK_FILTER_NEAREST,
|
||||
.min_filter = VK_FILTER_NEAREST,
|
||||
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||
.address_mode_u = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.address_mode_v = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.address_mode_w = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.border_color = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK,
|
||||
.min_lod = 0.0,
|
||||
.max_lod = 16.0,
|
||||
.unnormalized_coordinates = true,
|
||||
};
|
||||
|
||||
struct vk_sampler sampler;
|
||||
vk_sampler_init(&sampler_info, &sampler);
|
||||
|
||||
return nvk_sampler_get_header(pdev, &sampler_info, &sampler);
|
||||
return nvk_sampler_get_header(pdev, &sampler_state);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
@@ -332,10 +329,13 @@ nvk_CreateSampler(VkDevice device,
|
||||
if (!sampler)
|
||||
return vk_error(dev, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
struct vk_sampler_state state;
|
||||
vk_sampler_state_init(&state, pCreateInfo);
|
||||
|
||||
{
|
||||
sampler->plane_count = 1;
|
||||
const struct nvk_sampler_header samp =
|
||||
nvk_sampler_get_header(pdev, pCreateInfo, &sampler->vk);
|
||||
nvk_sampler_get_header(pdev, &state);
|
||||
|
||||
uint32_t desc_index = 0;
|
||||
if (cap_info != NULL) {
|
||||
@@ -365,18 +365,17 @@ nvk_CreateSampler(VkDevice device,
|
||||
* planes.
|
||||
*/
|
||||
|
||||
if (sampler->vk.ycbcr_conversion) {
|
||||
const VkFilter chroma_filter =
|
||||
sampler->vk.ycbcr_conversion->state.chroma_filter;
|
||||
if (pCreateInfo->magFilter != chroma_filter ||
|
||||
pCreateInfo->minFilter != chroma_filter) {
|
||||
VkSamplerCreateInfo plane2_info = *pCreateInfo;
|
||||
plane2_info.magFilter = chroma_filter;
|
||||
plane2_info.minFilter = chroma_filter;
|
||||
if (state.has_ycbcr_conversion) {
|
||||
const VkFilter chroma_filter = state.ycbcr_conversion.chroma_filter;
|
||||
if (state.mag_filter != state.ycbcr_conversion.chroma_filter ||
|
||||
state.min_filter != state.ycbcr_conversion.chroma_filter) {
|
||||
struct vk_sampler_state chroma_state = state;
|
||||
chroma_state.mag_filter = chroma_filter;
|
||||
chroma_state.min_filter = chroma_filter;
|
||||
|
||||
sampler->plane_count = 2;
|
||||
const struct nvk_sampler_header samp =
|
||||
nvk_sampler_get_header(pdev, &plane2_info, &sampler->vk);
|
||||
nvk_sampler_get_header(pdev, &chroma_state);
|
||||
|
||||
uint32_t desc_index = 0;
|
||||
if (cap_info != NULL) {
|
||||
|
||||
Reference in New Issue
Block a user