Home | History | Annotate | Download | only in vk
      1 /*
      2  * Copyright 2015 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "GrVkUtil.h"
      9 
     10 bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) {
     11     VkFormat dontCare;
     12     if (!format) {
     13         format = &dontCare;
     14     }
     15 
     16     switch (config) {
     17         case kRGBA_8888_GrPixelConfig:
     18             *format = VK_FORMAT_R8G8B8A8_UNORM;
     19             break;
     20         case kBGRA_8888_GrPixelConfig:
     21             *format = VK_FORMAT_B8G8R8A8_UNORM;
     22             break;
     23         case kSRGBA_8888_GrPixelConfig:
     24             *format = VK_FORMAT_R8G8B8A8_SRGB;
     25             break;
     26         case kRGB_565_GrPixelConfig:
     27             *format = VK_FORMAT_R5G6B5_UNORM_PACK16;
     28             break;
     29         case kRGBA_4444_GrPixelConfig:
     30             *format = VK_FORMAT_R4G4B4A4_UNORM_PACK16;
     31             break;
     32         case kIndex_8_GrPixelConfig:
     33             // No current rad support for this config
     34             return false;
     35         case kAlpha_8_GrPixelConfig:
     36             *format = VK_FORMAT_R8_UNORM;
     37             break;
     38         case kETC1_GrPixelConfig:
     39             // converting to ETC2 which is a superset of ETC1
     40             *format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
     41             break;
     42         case kLATC_GrPixelConfig:
     43             // No current rad support for this config
     44             return false;
     45         case kR11_EAC_GrPixelConfig:
     46             *format = VK_FORMAT_EAC_R11_UNORM_BLOCK;
     47             break;
     48         case kASTC_12x12_GrPixelConfig:
     49             *format = VK_FORMAT_ASTC_12x12_UNORM_BLOCK;
     50             break;
     51         case kRGBA_float_GrPixelConfig:
     52             *format = VK_FORMAT_R32G32B32A32_SFLOAT;
     53             break;
     54         case kRGBA_half_GrPixelConfig:
     55             *format = VK_FORMAT_R16G16B16A16_SFLOAT;
     56             break;
     57         case kAlpha_half_GrPixelConfig:
     58             *format = VK_FORMAT_R16_SFLOAT;
     59             break;
     60         default:
     61             return false;
     62     }
     63     return true;
     64 }
     65 
     66 bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples) {
     67     switch (samples) {
     68         case 0: // fall through
     69         case 1:
     70             *vkSamples = VK_SAMPLE_COUNT_1_BIT;
     71             return true;
     72         case 2:
     73             *vkSamples = VK_SAMPLE_COUNT_2_BIT;
     74             return true;
     75         case 4:
     76             *vkSamples = VK_SAMPLE_COUNT_2_BIT;
     77             return true;
     78         case 8:
     79             *vkSamples = VK_SAMPLE_COUNT_2_BIT;
     80             return true;
     81         case 16:
     82             *vkSamples = VK_SAMPLE_COUNT_2_BIT;
     83             return true;
     84         case 32:
     85             *vkSamples = VK_SAMPLE_COUNT_2_BIT;
     86             return true;
     87         case 64:
     88             *vkSamples = VK_SAMPLE_COUNT_2_BIT;
     89             return true;
     90         default:
     91             return false;
     92     }
     93 }
     94 
     95