mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 21:43:34 +00:00
Rearrange the way sRGB textures work (again);
This commit is contained in:
parent
2770ab270a
commit
0bf09ca108
|
@ -436,14 +436,16 @@ bool gpu_texture_init(gpu_texture* texture, gpu_texture_info* info) {
|
||||||
return gpu_texture_init_view(texture, &viewInfo);
|
return gpu_texture_init_view(texture, &viewInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mutableFormat = info->srgb && (info->usage & GPU_TEXTURE_STORAGE);
|
||||||
|
|
||||||
VkImageCreateInfo imageInfo = {
|
VkImageCreateInfo imageInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||||
.flags =
|
.flags =
|
||||||
(info->type == GPU_TEXTURE_3D ? VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT : 0) |
|
(info->type == GPU_TEXTURE_3D ? VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT : 0) |
|
||||||
(info->type == GPU_TEXTURE_CUBE ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0) |
|
(info->type == GPU_TEXTURE_CUBE ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0) |
|
||||||
(info->srgb ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0),
|
(mutableFormat ? (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT) : 0),
|
||||||
.imageType = imageTypes[info->type],
|
.imageType = imageTypes[info->type],
|
||||||
.format = convertFormat(texture->format, LINEAR),
|
.format = convertFormat(texture->format, info->srgb),
|
||||||
.extent.width = info->size[0],
|
.extent.width = info->size[0],
|
||||||
.extent.height = info->size[1],
|
.extent.height = info->size[1],
|
||||||
.extent.depth = texture->layers ? 1 : info->size[2],
|
.extent.depth = texture->layers ? 1 : info->size[2],
|
||||||
|
@ -464,7 +466,7 @@ bool gpu_texture_init(gpu_texture* texture, gpu_texture_info* info) {
|
||||||
|
|
||||||
VkFormat formats[2];
|
VkFormat formats[2];
|
||||||
VkImageFormatListCreateInfo imageFormatList;
|
VkImageFormatListCreateInfo imageFormatList;
|
||||||
if (info->srgb && state.extensions.formatList) {
|
if (mutableFormat && state.extensions.formatList) {
|
||||||
imageFormatList = (VkImageFormatListCreateInfo) {
|
imageFormatList = (VkImageFormatListCreateInfo) {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO,
|
||||||
.viewFormatCount = COUNTOF(formats),
|
.viewFormatCount = COUNTOF(formats),
|
||||||
|
@ -472,13 +474,10 @@ bool gpu_texture_init(gpu_texture* texture, gpu_texture_info* info) {
|
||||||
};
|
};
|
||||||
|
|
||||||
formats[0] = imageInfo.format;
|
formats[0] = imageInfo.format;
|
||||||
formats[1] = convertFormat(texture->format, SRGB);
|
formats[1] = convertFormat(texture->format, LINEAR);
|
||||||
|
|
||||||
if (formats[0] != formats[1]) {
|
|
||||||
imageFormatList.pNext = imageInfo.pNext;
|
imageFormatList.pNext = imageInfo.pNext;
|
||||||
imageInfo.pNext = &imageFormatList;
|
imageInfo.pNext = &imageFormatList;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
VK(vkCreateImage(state.device, &imageInfo, NULL, &texture->handle), "Could not create texture") return false;
|
VK(vkCreateImage(state.device, &imageInfo, NULL, &texture->handle), "Could not create texture") return false;
|
||||||
nickname(texture->handle, VK_OBJECT_TYPE_IMAGE, info->label);
|
nickname(texture->handle, VK_OBJECT_TYPE_IMAGE, info->label);
|
||||||
|
@ -505,10 +504,7 @@ bool gpu_texture_init(gpu_texture* texture, gpu_texture_info* info) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needsView = info->usage & (GPU_TEXTURE_RENDER | GPU_TEXTURE_SAMPLE | GPU_TEXTURE_STORAGE);
|
if (!gpu_texture_init_view(texture, &viewInfo)) {
|
||||||
if (info->usage == GPU_TEXTURE_STORAGE && info->srgb) needsView = false;
|
|
||||||
|
|
||||||
if (needsView && !gpu_texture_init_view(texture, &viewInfo)) {
|
|
||||||
vkDestroyImage(state.device, texture->handle, NULL);
|
vkDestroyImage(state.device, texture->handle, NULL);
|
||||||
gpu_release(memory);
|
gpu_release(memory);
|
||||||
return false;
|
return false;
|
||||||
|
@ -650,6 +646,11 @@ bool gpu_texture_init_view(gpu_texture* texture, gpu_texture_view_info* info) {
|
||||||
((info->usage & GPU_TEXTURE_STORAGE) && !texture->srgb ? VK_IMAGE_USAGE_STORAGE_BIT : 0)
|
((info->usage & GPU_TEXTURE_STORAGE) && !texture->srgb ? VK_IMAGE_USAGE_STORAGE_BIT : 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (usage.usage == 0) {
|
||||||
|
texture->view = VK_NULL_HANDLE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
VkImageViewCreateInfo createInfo = {
|
VkImageViewCreateInfo createInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
.pNext = &usage,
|
.pNext = &usage,
|
||||||
|
@ -2201,7 +2202,6 @@ bool gpu_init(gpu_config* config) {
|
||||||
{ "VK_KHR_portability_enumeration", true, &state.extensions.portability },
|
{ "VK_KHR_portability_enumeration", true, &state.extensions.portability },
|
||||||
{ "VK_EXT_debug_utils", config->debug, &state.extensions.debug },
|
{ "VK_EXT_debug_utils", config->debug, &state.extensions.debug },
|
||||||
{ "VK_EXT_swapchain_colorspace", true, &state.extensions.colorspace },
|
{ "VK_EXT_swapchain_colorspace", true, &state.extensions.colorspace },
|
||||||
{ "VK_KHR_image_format_list", true, &state.extensions.formatList },
|
|
||||||
{ "VK_KHR_surface", true, &state.extensions.surface },
|
{ "VK_KHR_surface", true, &state.extensions.surface },
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
{ "VK_KHR_win32_surface", true, &state.extensions.surfaceOS },
|
{ "VK_KHR_win32_surface", true, &state.extensions.surfaceOS },
|
||||||
|
@ -2436,6 +2436,7 @@ bool gpu_init(gpu_config* config) {
|
||||||
{ "VK_KHR_portability_subset", true, &state.extensions.portability },
|
{ "VK_KHR_portability_subset", true, &state.extensions.portability },
|
||||||
{ "VK_KHR_depth_stencil_resolve", true, &state.extensions.depthResolve },
|
{ "VK_KHR_depth_stencil_resolve", true, &state.extensions.depthResolve },
|
||||||
{ "VK_KHR_shader_non_semantic_info", config->debug, &state.extensions.shaderDebug },
|
{ "VK_KHR_shader_non_semantic_info", config->debug, &state.extensions.shaderDebug },
|
||||||
|
{ "VK_KHR_image_format_list", true, &state.extensions.formatList },
|
||||||
{ "VK_KHR_synchronization2", true, NULL }
|
{ "VK_KHR_synchronization2", true, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue