mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 22:38:05 +02:00
tu: Move sampler related code to tu_sampler.cc/h
More code isolation. Match the structure of the common Vulkan runtime, NVK and RADV. Signed-off-by: Valentine Burley <valentine.burley@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29808>
This commit is contained in:
parent
739dfcf807
commit
a931329146
6 changed files with 168 additions and 140 deletions
|
|
@ -36,6 +36,7 @@ libtu_files = files(
|
|||
'tu_nir_lower_multiview.cc',
|
||||
'tu_pass.cc',
|
||||
'tu_pipeline.cc',
|
||||
'tu_sampler.cc',
|
||||
'tu_query.cc',
|
||||
'tu_rmv.cc',
|
||||
'tu_shader.cc',
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "vk_descriptor_set_layout.h"
|
||||
|
||||
#include "tu_sampler.h"
|
||||
|
||||
/* The hardware supports up to 8 descriptor sets since A7XX.
|
||||
* Note: This is the maximum across generations, not the maximum for a
|
||||
* particular generation so it should only be used for allocation.
|
||||
|
|
|
|||
|
|
@ -3171,135 +3171,6 @@ tu_DestroyFramebuffer(VkDevice _device,
|
|||
vk_object_free(&device->vk, pAllocator, fb);
|
||||
}
|
||||
|
||||
static void
|
||||
tu_init_sampler(struct tu_device *device,
|
||||
struct tu_sampler *sampler,
|
||||
const VkSamplerCreateInfo *pCreateInfo)
|
||||
{
|
||||
const struct VkSamplerYcbcrConversionInfo *ycbcr_conversion =
|
||||
vk_find_struct_const(pCreateInfo->pNext, SAMPLER_YCBCR_CONVERSION_INFO);
|
||||
/* for non-custom border colors, the VK enum is translated directly to an offset in
|
||||
* the border color buffer. custom border colors are located immediately after the
|
||||
* builtin colors, and thus an offset of TU_BORDER_COLOR_BUILTIN is added.
|
||||
*/
|
||||
uint32_t border_color = (unsigned) pCreateInfo->borderColor;
|
||||
if (vk_border_color_is_custom(pCreateInfo->borderColor)) {
|
||||
mtx_lock(&device->mutex);
|
||||
border_color = BITSET_FFS(device->custom_border_color) - 1;
|
||||
assert(border_color < TU_BORDER_COLOR_COUNT);
|
||||
BITSET_CLEAR(device->custom_border_color, border_color);
|
||||
mtx_unlock(&device->mutex);
|
||||
|
||||
VkClearColorValue color = sampler->vk.border_color_value;
|
||||
if (sampler->vk.format == VK_FORMAT_D24_UNORM_S8_UINT &&
|
||||
pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT &&
|
||||
device->use_z24uint_s8uint) {
|
||||
/* When sampling stencil using the special Z24UINT_S8UINT format, the
|
||||
* border color is in the second component. Note: if
|
||||
* customBorderColorWithoutFormat is enabled, we may miss doing this
|
||||
* here if the format isn't specified, which is why we don't use that
|
||||
* format.
|
||||
*/
|
||||
color.uint32[1] = color.uint32[0];
|
||||
}
|
||||
|
||||
tu6_pack_border_color(
|
||||
&device->global_bo_map->bcolor[border_color], &color,
|
||||
pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT);
|
||||
border_color += TU_BORDER_COLOR_BUILTIN;
|
||||
}
|
||||
|
||||
unsigned aniso = pCreateInfo->anisotropyEnable ?
|
||||
util_last_bit(MIN2((uint32_t)pCreateInfo->maxAnisotropy >> 1, 8)) : 0;
|
||||
bool miplinear = (pCreateInfo->mipmapMode == VK_SAMPLER_MIPMAP_MODE_LINEAR);
|
||||
float min_lod = CLAMP(pCreateInfo->minLod, 0.0f, 4095.0f / 256.0f);
|
||||
float max_lod = CLAMP(pCreateInfo->maxLod, 0.0f, 4095.0f / 256.0f);
|
||||
|
||||
sampler->descriptor[0] =
|
||||
COND(miplinear, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR) |
|
||||
A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo->magFilter, aniso)) |
|
||||
A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo->minFilter, aniso)) |
|
||||
A6XX_TEX_SAMP_0_ANISO((enum a6xx_tex_aniso) aniso) |
|
||||
A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo->addressModeU)) |
|
||||
A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo->addressModeV)) |
|
||||
A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo->addressModeW)) |
|
||||
A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo->mipLodBias);
|
||||
sampler->descriptor[1] =
|
||||
COND(pCreateInfo->flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT,
|
||||
A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) |
|
||||
COND(pCreateInfo->unnormalizedCoordinates, A6XX_TEX_SAMP_1_UNNORM_COORDS) |
|
||||
A6XX_TEX_SAMP_1_MIN_LOD(min_lod) |
|
||||
A6XX_TEX_SAMP_1_MAX_LOD(max_lod) |
|
||||
COND(pCreateInfo->compareEnable,
|
||||
A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo->compareOp)));
|
||||
sampler->descriptor[2] = A6XX_TEX_SAMP_2_BCOLOR(border_color);
|
||||
sampler->descriptor[3] = 0;
|
||||
|
||||
if (sampler->vk.reduction_mode != VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE) {
|
||||
sampler->descriptor[2] |= A6XX_TEX_SAMP_2_REDUCTION_MODE(
|
||||
tu6_reduction_mode(sampler->vk.reduction_mode));
|
||||
}
|
||||
|
||||
sampler->vk.ycbcr_conversion = ycbcr_conversion ?
|
||||
vk_ycbcr_conversion_from_handle(ycbcr_conversion->conversion) : NULL;
|
||||
|
||||
if (sampler->vk.ycbcr_conversion &&
|
||||
sampler->vk.ycbcr_conversion->state.chroma_filter == VK_FILTER_LINEAR) {
|
||||
sampler->descriptor[2] |= A6XX_TEX_SAMP_2_CHROMA_LINEAR;
|
||||
}
|
||||
|
||||
/* TODO:
|
||||
* A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
|
||||
*/
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_CreateSampler(VkDevice _device,
|
||||
const VkSamplerCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkSampler *pSampler)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
struct tu_sampler *sampler;
|
||||
|
||||
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
|
||||
|
||||
sampler = (struct tu_sampler *) vk_sampler_create(
|
||||
&device->vk, pCreateInfo, pAllocator, sizeof(*sampler));
|
||||
if (!sampler)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
tu_init_sampler(device, sampler, pCreateInfo);
|
||||
*pSampler = tu_sampler_to_handle(sampler);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_DestroySampler(VkDevice _device,
|
||||
VkSampler _sampler,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
VK_FROM_HANDLE(tu_sampler, sampler, _sampler);
|
||||
uint32_t border_color;
|
||||
|
||||
if (!sampler)
|
||||
return;
|
||||
|
||||
border_color = (sampler->descriptor[2] & A6XX_TEX_SAMP_2_BCOLOR__MASK) >> A6XX_TEX_SAMP_2_BCOLOR__SHIFT;
|
||||
if (border_color >= TU_BORDER_COLOR_BUILTIN) {
|
||||
border_color -= TU_BORDER_COLOR_BUILTIN;
|
||||
/* if the sampler had a custom border color, free it. TODO: no lock */
|
||||
mtx_lock(&device->mutex);
|
||||
assert(!BITSET_TEST(device->custom_border_color, border_color));
|
||||
BITSET_SET(device->custom_border_color, border_color);
|
||||
mtx_unlock(&device->mutex);
|
||||
}
|
||||
|
||||
vk_sampler_destroy(&device->vk, pAllocator, &sampler->vk);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_GetMemoryFdKHR(VkDevice _device,
|
||||
const VkMemoryGetFdInfoKHR *pGetFdInfo,
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
#include "vk_buffer.h"
|
||||
#include "vk_device_memory.h"
|
||||
#include "vk_sampler.h"
|
||||
#include "vk_ycbcr_conversion.h"
|
||||
|
||||
#include "tu_autotune.h"
|
||||
#include "tu_pass.h"
|
||||
|
|
@ -478,15 +476,6 @@ struct tu_framebuffer
|
|||
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer, base, VkFramebuffer,
|
||||
VK_OBJECT_TYPE_FRAMEBUFFER)
|
||||
|
||||
|
||||
struct tu_sampler {
|
||||
struct vk_sampler vk;
|
||||
|
||||
uint32_t descriptor[A6XX_TEX_SAMP_DWORDS];
|
||||
};
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler, vk.base, VkSampler,
|
||||
VK_OBJECT_TYPE_SAMPLER)
|
||||
|
||||
uint64_t
|
||||
tu_get_system_heap_size(struct tu_physical_device *physical_device);
|
||||
|
||||
|
|
|
|||
142
src/freedreno/vulkan/tu_sampler.cc
Normal file
142
src/freedreno/vulkan/tu_sampler.cc
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright © 2016 Red Hat.
|
||||
* Copyright © 2016 Bas Nieuwenhuizen
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* based in part on anv driver which is:
|
||||
* Copyright © 2015 Intel Corporation
|
||||
*/
|
||||
|
||||
#include "tu_sampler.h"
|
||||
|
||||
#include "tu_device.h"
|
||||
#include "tu_util.h"
|
||||
|
||||
static void
|
||||
tu_init_sampler(struct tu_device *device,
|
||||
struct tu_sampler *sampler,
|
||||
const VkSamplerCreateInfo *pCreateInfo)
|
||||
{
|
||||
const struct VkSamplerYcbcrConversionInfo *ycbcr_conversion =
|
||||
vk_find_struct_const(pCreateInfo->pNext, SAMPLER_YCBCR_CONVERSION_INFO);
|
||||
/* for non-custom border colors, the VK enum is translated directly to an offset in
|
||||
* the border color buffer. custom border colors are located immediately after the
|
||||
* builtin colors, and thus an offset of TU_BORDER_COLOR_BUILTIN is added.
|
||||
*/
|
||||
uint32_t border_color = (unsigned) pCreateInfo->borderColor;
|
||||
if (vk_border_color_is_custom(pCreateInfo->borderColor)) {
|
||||
mtx_lock(&device->mutex);
|
||||
border_color = BITSET_FFS(device->custom_border_color) - 1;
|
||||
assert(border_color < TU_BORDER_COLOR_COUNT);
|
||||
BITSET_CLEAR(device->custom_border_color, border_color);
|
||||
mtx_unlock(&device->mutex);
|
||||
|
||||
VkClearColorValue color = sampler->vk.border_color_value;
|
||||
if (sampler->vk.format == VK_FORMAT_D24_UNORM_S8_UINT &&
|
||||
pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT &&
|
||||
device->use_z24uint_s8uint) {
|
||||
/* When sampling stencil using the special Z24UINT_S8UINT format, the
|
||||
* border color is in the second component. Note: if
|
||||
* customBorderColorWithoutFormat is enabled, we may miss doing this
|
||||
* here if the format isn't specified, which is why we don't use that
|
||||
* format.
|
||||
*/
|
||||
color.uint32[1] = color.uint32[0];
|
||||
}
|
||||
|
||||
tu6_pack_border_color(
|
||||
&device->global_bo_map->bcolor[border_color], &color,
|
||||
pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT);
|
||||
border_color += TU_BORDER_COLOR_BUILTIN;
|
||||
}
|
||||
|
||||
unsigned aniso = pCreateInfo->anisotropyEnable ?
|
||||
util_last_bit(MIN2((uint32_t)pCreateInfo->maxAnisotropy >> 1, 8)) : 0;
|
||||
bool miplinear = (pCreateInfo->mipmapMode == VK_SAMPLER_MIPMAP_MODE_LINEAR);
|
||||
float min_lod = CLAMP(pCreateInfo->minLod, 0.0f, 4095.0f / 256.0f);
|
||||
float max_lod = CLAMP(pCreateInfo->maxLod, 0.0f, 4095.0f / 256.0f);
|
||||
|
||||
sampler->descriptor[0] =
|
||||
COND(miplinear, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR) |
|
||||
A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo->magFilter, aniso)) |
|
||||
A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo->minFilter, aniso)) |
|
||||
A6XX_TEX_SAMP_0_ANISO((enum a6xx_tex_aniso) aniso) |
|
||||
A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo->addressModeU)) |
|
||||
A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo->addressModeV)) |
|
||||
A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo->addressModeW)) |
|
||||
A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo->mipLodBias);
|
||||
sampler->descriptor[1] =
|
||||
COND(pCreateInfo->flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT,
|
||||
A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) |
|
||||
COND(pCreateInfo->unnormalizedCoordinates, A6XX_TEX_SAMP_1_UNNORM_COORDS) |
|
||||
A6XX_TEX_SAMP_1_MIN_LOD(min_lod) |
|
||||
A6XX_TEX_SAMP_1_MAX_LOD(max_lod) |
|
||||
COND(pCreateInfo->compareEnable,
|
||||
A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo->compareOp)));
|
||||
sampler->descriptor[2] = A6XX_TEX_SAMP_2_BCOLOR(border_color);
|
||||
sampler->descriptor[3] = 0;
|
||||
|
||||
if (sampler->vk.reduction_mode != VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE) {
|
||||
sampler->descriptor[2] |= A6XX_TEX_SAMP_2_REDUCTION_MODE(
|
||||
tu6_reduction_mode(sampler->vk.reduction_mode));
|
||||
}
|
||||
|
||||
sampler->vk.ycbcr_conversion = ycbcr_conversion ?
|
||||
vk_ycbcr_conversion_from_handle(ycbcr_conversion->conversion) : NULL;
|
||||
|
||||
if (sampler->vk.ycbcr_conversion &&
|
||||
sampler->vk.ycbcr_conversion->state.chroma_filter == VK_FILTER_LINEAR) {
|
||||
sampler->descriptor[2] |= A6XX_TEX_SAMP_2_CHROMA_LINEAR;
|
||||
}
|
||||
|
||||
/* TODO:
|
||||
* A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
|
||||
*/
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_CreateSampler(VkDevice _device,
|
||||
const VkSamplerCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkSampler *pSampler)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
struct tu_sampler *sampler;
|
||||
|
||||
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
|
||||
|
||||
sampler = (struct tu_sampler *) vk_sampler_create(
|
||||
&device->vk, pCreateInfo, pAllocator, sizeof(*sampler));
|
||||
if (!sampler)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
tu_init_sampler(device, sampler, pCreateInfo);
|
||||
*pSampler = tu_sampler_to_handle(sampler);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_DestroySampler(VkDevice _device,
|
||||
VkSampler _sampler,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
VK_FROM_HANDLE(tu_sampler, sampler, _sampler);
|
||||
uint32_t border_color;
|
||||
|
||||
if (!sampler)
|
||||
return;
|
||||
|
||||
border_color = (sampler->descriptor[2] & A6XX_TEX_SAMP_2_BCOLOR__MASK) >> A6XX_TEX_SAMP_2_BCOLOR__SHIFT;
|
||||
if (border_color >= TU_BORDER_COLOR_BUILTIN) {
|
||||
border_color -= TU_BORDER_COLOR_BUILTIN;
|
||||
/* if the sampler had a custom border color, free it. TODO: no lock */
|
||||
mtx_lock(&device->mutex);
|
||||
assert(!BITSET_TEST(device->custom_border_color, border_color));
|
||||
BITSET_SET(device->custom_border_color, border_color);
|
||||
mtx_unlock(&device->mutex);
|
||||
}
|
||||
|
||||
vk_sampler_destroy(&device->vk, pAllocator, &sampler->vk);
|
||||
}
|
||||
23
src/freedreno/vulkan/tu_sampler.h
Normal file
23
src/freedreno/vulkan/tu_sampler.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright © 2014 Valentine Burley
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef TU_SAMPLER_H
|
||||
#define TU_SAMPLER_H
|
||||
|
||||
#include "tu_common.h"
|
||||
|
||||
#include "vk_sampler.h"
|
||||
#include "vk_ycbcr_conversion.h"
|
||||
|
||||
struct tu_sampler {
|
||||
struct vk_sampler vk;
|
||||
|
||||
uint32_t descriptor[A6XX_TEX_SAMP_DWORDS];
|
||||
};
|
||||
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler, vk.base, VkSampler,
|
||||
VK_OBJECT_TYPE_SAMPLER)
|
||||
|
||||
#endif /* TU_SAMPLER_H */
|
||||
Loading…
Add table
Reference in a new issue