Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 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; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame^] | 26 | case kSBGRA_8888_GrPixelConfig: |
| 27 | *format = VK_FORMAT_B8G8R8A8_SRGB; |
| 28 | break; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 29 | case kRGB_565_GrPixelConfig: |
| 30 | *format = VK_FORMAT_R5G6B5_UNORM_PACK16; |
| 31 | break; |
| 32 | case kRGBA_4444_GrPixelConfig: |
| 33 | *format = VK_FORMAT_R4G4B4A4_UNORM_PACK16; |
| 34 | break; |
| 35 | case kIndex_8_GrPixelConfig: |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame^] | 36 | // No current vulkan support for this config |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | return false; |
| 38 | case kAlpha_8_GrPixelConfig: |
| 39 | *format = VK_FORMAT_R8_UNORM; |
| 40 | break; |
| 41 | case kETC1_GrPixelConfig: |
| 42 | // converting to ETC2 which is a superset of ETC1 |
| 43 | *format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
| 44 | break; |
| 45 | case kLATC_GrPixelConfig: |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame^] | 46 | // No current vulkan support for this config |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 47 | return false; |
| 48 | case kR11_EAC_GrPixelConfig: |
| 49 | *format = VK_FORMAT_EAC_R11_UNORM_BLOCK; |
| 50 | break; |
| 51 | case kASTC_12x12_GrPixelConfig: |
| 52 | *format = VK_FORMAT_ASTC_12x12_UNORM_BLOCK; |
| 53 | break; |
| 54 | case kRGBA_float_GrPixelConfig: |
| 55 | *format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 56 | break; |
| 57 | case kRGBA_half_GrPixelConfig: |
| 58 | *format = VK_FORMAT_R16G16B16A16_SFLOAT; |
| 59 | break; |
| 60 | case kAlpha_half_GrPixelConfig: |
| 61 | *format = VK_FORMAT_R16_SFLOAT; |
| 62 | break; |
| 63 | default: |
| 64 | return false; |
| 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame^] | 69 | bool GrVkFormatToPixelConfig(VkFormat format, GrPixelConfig* config) { |
| 70 | GrPixelConfig dontCare; |
| 71 | if (!config) { |
| 72 | config = &dontCare; |
| 73 | } |
| 74 | |
| 75 | switch (format) { |
| 76 | case VK_FORMAT_R8G8B8A8_UNORM: |
| 77 | *config = kRGBA_8888_GrPixelConfig; |
| 78 | break; |
| 79 | case VK_FORMAT_B8G8R8A8_UNORM: |
| 80 | *config = kBGRA_8888_GrPixelConfig; |
| 81 | break; |
| 82 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 83 | *config = kSRGBA_8888_GrPixelConfig; |
| 84 | break; |
| 85 | case VK_FORMAT_B8G8R8A8_SRGB: |
| 86 | *config = kSBGRA_8888_GrPixelConfig; |
| 87 | break; |
| 88 | case VK_FORMAT_R5G6B5_UNORM_PACK16: |
| 89 | *config = kRGB_565_GrPixelConfig; |
| 90 | break; |
| 91 | case VK_FORMAT_R4G4B4A4_UNORM_PACK16: |
| 92 | *config = kRGBA_4444_GrPixelConfig; |
| 93 | break; |
| 94 | case VK_FORMAT_R8_UNORM: |
| 95 | *config = kAlpha_8_GrPixelConfig; |
| 96 | break; |
| 97 | case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: |
| 98 | *config = kETC1_GrPixelConfig; |
| 99 | break; |
| 100 | case VK_FORMAT_EAC_R11_UNORM_BLOCK: |
| 101 | *config = kR11_EAC_GrPixelConfig; |
| 102 | break; |
| 103 | case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: |
| 104 | *config = kASTC_12x12_GrPixelConfig; |
| 105 | break; |
| 106 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 107 | *config = kRGBA_float_GrPixelConfig; |
| 108 | break; |
| 109 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 110 | *config = kRGBA_half_GrPixelConfig; |
| 111 | break; |
| 112 | case VK_FORMAT_R16_SFLOAT: |
| 113 | *config = kAlpha_half_GrPixelConfig; |
| 114 | break; |
| 115 | default: |
| 116 | return false; |
| 117 | } |
| 118 | return true; |
| 119 | } |
| 120 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 121 | bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples) { |
| 122 | switch (samples) { |
| 123 | case 0: // fall through |
| 124 | case 1: |
| 125 | *vkSamples = VK_SAMPLE_COUNT_1_BIT; |
| 126 | return true; |
| 127 | case 2: |
| 128 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 129 | return true; |
| 130 | case 4: |
| 131 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 132 | return true; |
| 133 | case 8: |
| 134 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 135 | return true; |
| 136 | case 16: |
| 137 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 138 | return true; |
| 139 | case 32: |
| 140 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 141 | return true; |
| 142 | case 64: |
| 143 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 144 | return true; |
| 145 | default: |
| 146 | return false; |
| 147 | } |
| 148 | } |