17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2016 Intel Corporation 37ec681f3Smrg * Copyright © 2019 Google LLC 47ec681f3Smrg * 57ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 67ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 77ec681f3Smrg * to deal in the Software without restriction, including without limitation 87ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 97ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 107ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 117ec681f3Smrg * 127ec681f3Smrg * The above copyright notice and this permission notice (including the next 137ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 147ec681f3Smrg * Software. 157ec681f3Smrg * 167ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 177ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 187ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 197ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 207ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 217ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 227ec681f3Smrg * DEALINGS IN THE SOFTWARE. 237ec681f3Smrg */ 247ec681f3Smrg 257ec681f3Smrg#ifndef U_FORMAT_VK_H 267ec681f3Smrg#define U_FORMAT_VK_H 277ec681f3Smrg 287ec681f3Smrg#include <vulkan/vulkan_core.h> 297ec681f3Smrg#include "util/format/u_format.h" 307ec681f3Smrg 317ec681f3Smrg#ifdef __cplusplus 327ec681f3Smrgextern "C" { 337ec681f3Smrg#endif 347ec681f3Smrg 357ec681f3Smrgenum pipe_format 367ec681f3Smrgvk_format_to_pipe_format(enum VkFormat vkformat); 377ec681f3Smrg 387ec681f3SmrgVkImageAspectFlags 397ec681f3Smrgvk_format_aspects(VkFormat format); 407ec681f3Smrg 417ec681f3Smrgstatic inline bool 427ec681f3Smrgvk_format_is_color(VkFormat format) 437ec681f3Smrg{ 447ec681f3Smrg return vk_format_aspects(format) == VK_IMAGE_ASPECT_COLOR_BIT; 457ec681f3Smrg} 467ec681f3Smrg 477ec681f3Smrgstatic inline bool 487ec681f3Smrgvk_format_is_depth_or_stencil(VkFormat format) 497ec681f3Smrg{ 507ec681f3Smrg const VkImageAspectFlags aspects = vk_format_aspects(format); 517ec681f3Smrg return aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); 527ec681f3Smrg} 537ec681f3Smrg 547ec681f3Smrgstatic inline bool 557ec681f3Smrgvk_format_has_depth(VkFormat format) 567ec681f3Smrg{ 577ec681f3Smrg const VkImageAspectFlags aspects = vk_format_aspects(format); 587ec681f3Smrg return aspects & VK_IMAGE_ASPECT_DEPTH_BIT; 597ec681f3Smrg} 607ec681f3Smrg 617ec681f3Smrgstatic inline bool 627ec681f3Smrgvk_format_has_stencil(VkFormat format) 637ec681f3Smrg{ 647ec681f3Smrg const VkImageAspectFlags aspects = vk_format_aspects(format); 657ec681f3Smrg return aspects & VK_IMAGE_ASPECT_STENCIL_BIT; 667ec681f3Smrg} 677ec681f3Smrg 687ec681f3Smrgstatic inline VkFormat 697ec681f3Smrgvk_format_depth_only(VkFormat format) 707ec681f3Smrg{ 717ec681f3Smrg assert(vk_format_has_depth(format)); 727ec681f3Smrg switch (format) { 737ec681f3Smrg case VK_FORMAT_D16_UNORM_S8_UINT: 747ec681f3Smrg return VK_FORMAT_D16_UNORM; 757ec681f3Smrg case VK_FORMAT_D24_UNORM_S8_UINT: 767ec681f3Smrg return VK_FORMAT_X8_D24_UNORM_PACK32; 777ec681f3Smrg case VK_FORMAT_D32_SFLOAT_S8_UINT: 787ec681f3Smrg return VK_FORMAT_D32_SFLOAT; 797ec681f3Smrg default: 807ec681f3Smrg return format; 817ec681f3Smrg } 827ec681f3Smrg} 837ec681f3Smrg 847ec681f3Smrgstatic inline VkFormat 857ec681f3Smrgvk_format_stencil_only(VkFormat format) 867ec681f3Smrg{ 877ec681f3Smrg assert(vk_format_has_stencil(format)); 887ec681f3Smrg return VK_FORMAT_S8_UINT; 897ec681f3Smrg} 907ec681f3Smrg 917ec681f3Smrg#ifdef __cplusplus 927ec681f3Smrg} 937ec681f3Smrg#endif 947ec681f3Smrg 957ec681f3Smrg#endif 96