mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 14:00:09 +00:00
gpu: Add a mipmap sampler
It's not used yet, but the sampler infrastructure needs to be expanded, so I decided to split this out to easier find regressions.
This commit is contained in:
parent
03f820d26c
commit
528e246f1a
@ -144,24 +144,34 @@ static void
|
|||||||
gsk_gl_device_setup_samplers (GskGLDevice *self)
|
gsk_gl_device_setup_samplers (GskGLDevice *self)
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
GLuint filter;
|
GLuint min_filter;
|
||||||
|
GLuint mag_filter;
|
||||||
GLuint wrap;
|
GLuint wrap;
|
||||||
} sampler_flags[GSK_GPU_SAMPLER_N_SAMPLERS] = {
|
} sampler_flags[GSK_GPU_SAMPLER_N_SAMPLERS] = {
|
||||||
[GSK_GPU_SAMPLER_DEFAULT] = {
|
[GSK_GPU_SAMPLER_DEFAULT] = {
|
||||||
GL_LINEAR,
|
.min_filter = GL_LINEAR,
|
||||||
GL_CLAMP_TO_EDGE,
|
.mag_filter = GL_LINEAR,
|
||||||
|
.wrap = GL_CLAMP_TO_EDGE,
|
||||||
},
|
},
|
||||||
[GSK_GPU_SAMPLER_TRANSPARENT] = {
|
[GSK_GPU_SAMPLER_TRANSPARENT] = {
|
||||||
GL_LINEAR,
|
.min_filter = GL_LINEAR,
|
||||||
GL_CLAMP_TO_BORDER,
|
.mag_filter = GL_LINEAR,
|
||||||
|
.wrap = GL_CLAMP_TO_BORDER,
|
||||||
},
|
},
|
||||||
[GSK_GPU_SAMPLER_REPEAT] = {
|
[GSK_GPU_SAMPLER_REPEAT] = {
|
||||||
GL_LINEAR,
|
.min_filter = GL_LINEAR,
|
||||||
GL_REPEAT,
|
.mag_filter = GL_LINEAR,
|
||||||
|
.wrap = GL_REPEAT,
|
||||||
},
|
},
|
||||||
[GSK_GPU_SAMPLER_NEAREST] = {
|
[GSK_GPU_SAMPLER_NEAREST] = {
|
||||||
GL_NEAREST,
|
.min_filter = GL_NEAREST,
|
||||||
GL_CLAMP_TO_EDGE,
|
.mag_filter = GL_NEAREST,
|
||||||
|
.wrap = GL_CLAMP_TO_EDGE,
|
||||||
|
},
|
||||||
|
[GSK_GPU_SAMPLER_MIPMAP_DEFAULT] = {
|
||||||
|
.min_filter = GL_LINEAR_MIPMAP_LINEAR,
|
||||||
|
.mag_filter = GL_LINEAR,
|
||||||
|
.wrap = GL_CLAMP_TO_EDGE,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
guint i;
|
guint i;
|
||||||
@ -170,8 +180,8 @@ gsk_gl_device_setup_samplers (GskGLDevice *self)
|
|||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (self->sampler_ids); i++)
|
for (i = 0; i < G_N_ELEMENTS (self->sampler_ids); i++)
|
||||||
{
|
{
|
||||||
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_MIN_FILTER, sampler_flags[i].filter);
|
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_MIN_FILTER, sampler_flags[i].min_filter);
|
||||||
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_MAG_FILTER, sampler_flags[i].filter);
|
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_MAG_FILTER, sampler_flags[i].mag_filter);
|
||||||
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_WRAP_S, sampler_flags[i].wrap);
|
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_WRAP_S, sampler_flags[i].wrap);
|
||||||
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_WRAP_T, sampler_flags[i].wrap);
|
glSamplerParameteri (self->sampler_ids[i], GL_TEXTURE_WRAP_T, sampler_flags[i].wrap);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ typedef enum {
|
|||||||
GSK_GPU_SAMPLER_TRANSPARENT,
|
GSK_GPU_SAMPLER_TRANSPARENT,
|
||||||
GSK_GPU_SAMPLER_REPEAT,
|
GSK_GPU_SAMPLER_REPEAT,
|
||||||
GSK_GPU_SAMPLER_NEAREST,
|
GSK_GPU_SAMPLER_NEAREST,
|
||||||
|
GSK_GPU_SAMPLER_MIPMAP_DEFAULT,
|
||||||
/* add more */
|
/* add more */
|
||||||
GSK_GPU_SAMPLER_N_SAMPLERS
|
GSK_GPU_SAMPLER_N_SAMPLERS
|
||||||
} GskGpuSampler;
|
} GskGpuSampler;
|
||||||
|
@ -552,7 +552,9 @@ static VkSampler
|
|||||||
gsk_vulkan_device_create_sampler (GskVulkanDevice *self,
|
gsk_vulkan_device_create_sampler (GskVulkanDevice *self,
|
||||||
VkSamplerYcbcrConversion vk_conversion,
|
VkSamplerYcbcrConversion vk_conversion,
|
||||||
VkFilter vk_filter,
|
VkFilter vk_filter,
|
||||||
VkSamplerAddressMode vk_address_mode)
|
VkSamplerAddressMode vk_address_mode,
|
||||||
|
VkSamplerMipmapMode vk_mipmap_mode,
|
||||||
|
float max_lod)
|
||||||
{
|
{
|
||||||
VkSampler result;
|
VkSampler result;
|
||||||
|
|
||||||
@ -561,12 +563,15 @@ gsk_vulkan_device_create_sampler (GskVulkanDevice *self,
|
|||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
||||||
.magFilter = vk_filter,
|
.magFilter = vk_filter,
|
||||||
.minFilter = vk_filter,
|
.minFilter = vk_filter,
|
||||||
|
.mipmapMode = vk_mipmap_mode,
|
||||||
.addressModeU = vk_address_mode,
|
.addressModeU = vk_address_mode,
|
||||||
.addressModeV = vk_address_mode,
|
.addressModeV = vk_address_mode,
|
||||||
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||||
.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
|
.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
|
||||||
.unnormalizedCoordinates = VK_FALSE,
|
.unnormalizedCoordinates = VK_FALSE,
|
||||||
.maxAnisotropy = 1.0,
|
.maxAnisotropy = 1.0,
|
||||||
|
.minLod = 0.0,
|
||||||
|
.maxLod = max_lod,
|
||||||
.pNext = vk_conversion == VK_NULL_HANDLE ? NULL : &(VkSamplerYcbcrConversionInfo) {
|
.pNext = vk_conversion == VK_NULL_HANDLE ? NULL : &(VkSamplerYcbcrConversionInfo) {
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
||||||
.conversion = vk_conversion
|
.conversion = vk_conversion
|
||||||
@ -585,22 +590,38 @@ gsk_vulkan_device_get_vk_sampler (GskVulkanDevice *self,
|
|||||||
const struct {
|
const struct {
|
||||||
VkFilter filter;
|
VkFilter filter;
|
||||||
VkSamplerAddressMode address_mode;
|
VkSamplerAddressMode address_mode;
|
||||||
|
VkSamplerMipmapMode mipmap_mode;
|
||||||
|
float max_lod;
|
||||||
} filter_attrs[GSK_GPU_SAMPLER_N_SAMPLERS] = {
|
} filter_attrs[GSK_GPU_SAMPLER_N_SAMPLERS] = {
|
||||||
[GSK_GPU_SAMPLER_DEFAULT] = {
|
[GSK_GPU_SAMPLER_DEFAULT] = {
|
||||||
.filter = VK_FILTER_LINEAR,
|
.filter = VK_FILTER_LINEAR,
|
||||||
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||||
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||||
|
.max_lod = 0.0f,
|
||||||
},
|
},
|
||||||
[GSK_GPU_SAMPLER_TRANSPARENT] = {
|
[GSK_GPU_SAMPLER_TRANSPARENT] = {
|
||||||
.filter = VK_FILTER_LINEAR,
|
.filter = VK_FILTER_LINEAR,
|
||||||
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||||
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||||
|
.max_lod = 0.0f,
|
||||||
},
|
},
|
||||||
[GSK_GPU_SAMPLER_REPEAT] = {
|
[GSK_GPU_SAMPLER_REPEAT] = {
|
||||||
.filter = VK_FILTER_LINEAR,
|
.filter = VK_FILTER_LINEAR,
|
||||||
.address_mode = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
||||||
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||||
|
.max_lod = 0.0f,
|
||||||
},
|
},
|
||||||
[GSK_GPU_SAMPLER_NEAREST] = {
|
[GSK_GPU_SAMPLER_NEAREST] = {
|
||||||
.filter = VK_FILTER_NEAREST,
|
.filter = VK_FILTER_NEAREST,
|
||||||
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||||
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||||
|
.max_lod = 0.0f,
|
||||||
|
},
|
||||||
|
[GSK_GPU_SAMPLER_MIPMAP_DEFAULT] = {
|
||||||
|
.filter = VK_FILTER_LINEAR,
|
||||||
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||||
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
|
||||||
|
.max_lod = VK_LOD_CLAMP_NONE,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -609,7 +630,9 @@ gsk_vulkan_device_get_vk_sampler (GskVulkanDevice *self,
|
|||||||
self->vk_samplers[sampler] = gsk_vulkan_device_create_sampler (self,
|
self->vk_samplers[sampler] = gsk_vulkan_device_create_sampler (self,
|
||||||
VK_NULL_HANDLE,
|
VK_NULL_HANDLE,
|
||||||
filter_attrs[sampler].filter,
|
filter_attrs[sampler].filter,
|
||||||
filter_attrs[sampler].address_mode);
|
filter_attrs[sampler].address_mode,
|
||||||
|
filter_attrs[sampler].mipmap_mode,
|
||||||
|
filter_attrs[sampler].max_lod);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self->vk_samplers[sampler];
|
return self->vk_samplers[sampler];
|
||||||
@ -663,7 +686,9 @@ gsk_vulkan_device_get_vk_conversion (GskVulkanDevice *self,
|
|||||||
entry->vk_sampler = gsk_vulkan_device_create_sampler (self,
|
entry->vk_sampler = gsk_vulkan_device_create_sampler (self,
|
||||||
entry->vk_conversion,
|
entry->vk_conversion,
|
||||||
VK_FILTER_LINEAR,
|
VK_FILTER_LINEAR,
|
||||||
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE);
|
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||||
|
VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||||
|
0.0f);
|
||||||
|
|
||||||
g_hash_table_insert (self->conversion_cache, entry, entry);
|
g_hash_table_insert (self->conversion_cache, entry, entry);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user