{
ANV_FROM_HANDLE(anv_device, device, _device);
struct anv_sampler *sampler;
- uint32_t mag_filter, min_filter, max_anisotropy;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
if (!sampler)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
- if (pCreateInfo->maxAnisotropy > 1) {
- mag_filter = MAPFILTER_ANISOTROPIC;
- min_filter = MAPFILTER_ANISOTROPIC;
- max_anisotropy = (pCreateInfo->maxAnisotropy - 2) / 2;
- } else {
- mag_filter = vk_to_gen_tex_filter[pCreateInfo->magFilter];
- min_filter = vk_to_gen_tex_filter[pCreateInfo->minFilter];
- max_anisotropy = RATIO21;
- }
+ uint32_t filter = vk_to_gen_tex_filter(pCreateInfo->magFilter,
+ pCreateInfo->anisotropyEnable);
struct GEN7_SAMPLER_STATE sampler_state = {
.SamplerDisable = false,
.TextureBorderColorMode = DX10OGL,
.BaseMipLevel = 0.0,
.MipModeFilter = vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode],
- .MagModeFilter = mag_filter,
- .MinModeFilter = min_filter,
+ .MagModeFilter = filter,
+ .MinModeFilter = filter,
.TextureLODBias = pCreateInfo->mipLodBias * 256,
.AnisotropicAlgorithm = EWAApproximation,
.MinLOD = pCreateInfo->minLod,
device->border_colors.offset +
pCreateInfo->borderColor * sizeof(float) * 4,
- .MaximumAnisotropy = max_anisotropy,
+ .MaximumAnisotropy = vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy),
.RAddressMinFilterRoundingEnable = 0,
.RAddressMagFilterRoundingEnable = 0,
.VAddressMinFilterRoundingEnable = 0,
{
ANV_FROM_HANDLE(anv_device, device, _device);
struct anv_sampler *sampler;
- uint32_t mag_filter, min_filter, max_anisotropy;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
if (!sampler)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
- if (pCreateInfo->maxAnisotropy > 1) {
- mag_filter = MAPFILTER_ANISOTROPIC;
- min_filter = MAPFILTER_ANISOTROPIC;
- max_anisotropy = (pCreateInfo->maxAnisotropy - 2) / 2;
- } else {
- mag_filter = vk_to_gen_tex_filter[pCreateInfo->magFilter];
- min_filter = vk_to_gen_tex_filter[pCreateInfo->minFilter];
- max_anisotropy = RATIO21;
- }
+ uint32_t filter = vk_to_gen_tex_filter(pCreateInfo->magFilter,
+ pCreateInfo->anisotropyEnable);
struct GENX(SAMPLER_STATE) sampler_state = {
.SamplerDisable = false,
.BaseMipLevel = 0.0,
#endif
.MipModeFilter = vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode],
- .MagModeFilter = mag_filter,
- .MinModeFilter = min_filter,
+ .MagModeFilter = filter,
+ .MinModeFilter = filter,
.TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16, 15.996),
.AnisotropicAlgorithm = EWAApproximation,
.MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14),
pCreateInfo->borderColor * sizeof(float) * 4,
.LODClampMagnificationMode = MIPNONE,
- .MaximumAnisotropy = max_anisotropy,
+ .MaximumAnisotropy = vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy),
.RAddressMinFilterRoundingEnable = 0,
.RAddressMagFilterRoundingEnable = 0,
.VAddressMinFilterRoundingEnable = 0,
}
#endif
-static const uint32_t vk_to_gen_tex_filter[] = {
- [VK_FILTER_NEAREST] = MAPFILTER_NEAREST,
- [VK_FILTER_LINEAR] = MAPFILTER_LINEAR
-};
+static inline uint32_t
+vk_to_gen_tex_filter(VkFilter filter, bool anisotropyEnable)
+{
+ switch (filter) {
+ default:
+ assert(!"Invalid filter");
+ case VK_FILTER_NEAREST:
+ return MAPFILTER_NEAREST;
+ case VK_FILTER_LINEAR:
+ return anisotropyEnable ? MAPFILTER_ANISOTROPIC : MAPFILTER_LINEAR;
+ }
+}
+
+static inline uint32_t
+vk_to_gen_max_anisotropy(float ratio)
+{
+ return (anv_clamp_f(ratio, 2, 16) - 2) / 2;
+}
static const uint32_t vk_to_gen_mipmap_mode[] = {
[VK_SAMPLER_MIPMAP_MODE_BASE] = MIPFILTER_NONE,