Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/mtl/GrMtlUtil.h" |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrSurface.h" |
| 11 | #include "include/private/GrTypesPriv.h" |
| 12 | #include "src/gpu/mtl/GrMtlGpu.h" |
| 13 | #include "src/gpu/mtl/GrMtlRenderTarget.h" |
| 14 | #include "src/gpu/mtl/GrMtlTexture.h" |
| 15 | #include "src/sksl/SkSLCompiler.h" |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 16 | |
| 17 | #import <Metal/Metal.h> |
| 18 | |
Jim Van Verth | cf23f58 | 2019-05-22 09:46:57 -0400 | [diff] [blame] | 19 | #if !__has_feature(objc_arc) |
| 20 | #error This file must be compiled with Arc. Use -fobjc-arc flag |
| 21 | #endif |
| 22 | |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 23 | #define PRINT_MSL 0 // print out the MSL code generated |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 24 | |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 25 | bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format) { |
| 26 | MTLPixelFormat dontCare; |
| 27 | if (!format) { |
| 28 | format = &dontCare; |
| 29 | } |
| 30 | |
| 31 | switch (config) { |
| 32 | case kUnknown_GrPixelConfig: |
| 33 | return false; |
| 34 | case kRGBA_8888_GrPixelConfig: |
| 35 | *format = MTLPixelFormatRGBA8Unorm; |
| 36 | return true; |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 37 | case kRGB_888_GrPixelConfig: |
Jim Van Verth | a3407ab | 2019-03-15 15:22:39 -0400 | [diff] [blame] | 38 | *format = MTLPixelFormatRGBA8Unorm; |
| 39 | return true; |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 40 | case kRGB_888X_GrPixelConfig: |
| 41 | *format = MTLPixelFormatRGBA8Unorm; |
| 42 | return true; |
Jim Van Verth | 69e5785 | 2018-12-05 13:38:59 -0500 | [diff] [blame] | 43 | case kRG_88_GrPixelConfig: |
Jim Van Verth | 46431bf | 2019-04-09 15:26:38 -0400 | [diff] [blame] | 44 | *format = MTLPixelFormatRG8Unorm; |
| 45 | return true; |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 46 | case kBGRA_8888_GrPixelConfig: |
| 47 | *format = MTLPixelFormatBGRA8Unorm; |
| 48 | return true; |
| 49 | case kSRGBA_8888_GrPixelConfig: |
| 50 | *format = MTLPixelFormatRGBA8Unorm_sRGB; |
| 51 | return true; |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 52 | case kRGBA_1010102_GrPixelConfig: |
| 53 | *format = MTLPixelFormatRGB10A2Unorm; |
| 54 | return true; |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 55 | case kRGB_565_GrPixelConfig: |
| 56 | #ifdef SK_BUILD_FOR_IOS |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 57 | *format = MTLPixelFormatB5G6R5Unorm; |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 58 | return true; |
| 59 | #else |
| 60 | return false; |
| 61 | #endif |
| 62 | case kRGBA_4444_GrPixelConfig: |
| 63 | #ifdef SK_BUILD_FOR_IOS |
| 64 | *format = MTLPixelFormatABGR4Unorm; |
| 65 | return true; |
| 66 | #else |
| 67 | return false; |
| 68 | #endif |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 69 | case kAlpha_8_GrPixelConfig: // fall through |
| 70 | case kAlpha_8_as_Red_GrPixelConfig: |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 71 | *format = MTLPixelFormatR8Unorm; |
| 72 | return true; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 73 | case kAlpha_8_as_Alpha_GrPixelConfig: |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 74 | *format = MTLPixelFormatA8Unorm; |
| 75 | return true; |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 76 | case kGray_8_GrPixelConfig: // fall through |
| 77 | case kGray_8_as_Red_GrPixelConfig: |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 78 | *format = MTLPixelFormatR8Unorm; |
| 79 | return true; |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 80 | case kGray_8_as_Lum_GrPixelConfig: |
| 81 | return false; |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 82 | case kRGBA_float_GrPixelConfig: |
| 83 | *format = MTLPixelFormatRGBA32Float; |
| 84 | return true; |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 85 | case kRGBA_half_GrPixelConfig: |
| 86 | *format = MTLPixelFormatRGBA16Float; |
| 87 | return true; |
Brian Osman | d0626aa | 2019-03-11 15:28:06 -0400 | [diff] [blame] | 88 | case kRGBA_half_Clamped_GrPixelConfig: |
| 89 | *format = MTLPixelFormatRGBA16Float; |
| 90 | return true; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 91 | case kAlpha_half_GrPixelConfig: // fall through |
| 92 | case kAlpha_half_as_Red_GrPixelConfig: |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 93 | *format = MTLPixelFormatR16Float; |
| 94 | return true; |
Robert Phillips | ebab03f | 2019-07-22 08:48:18 -0400 | [diff] [blame] | 95 | case kAlpha_half_as_Lum_GrPixelConfig: |
| 96 | return false; |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 97 | case kRGB_ETC1_GrPixelConfig: |
| 98 | #ifdef SK_BUILD_FOR_IOS |
| 99 | *format = MTLPixelFormatETC2_RGB8; |
| 100 | return true; |
| 101 | #else |
| 102 | return false; |
| 103 | #endif |
Robert Phillips | 429f0d3 | 2019-09-11 17:03:28 -0400 | [diff] [blame] | 104 | case kAlpha_16_GrPixelConfig: |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 105 | *format = MTLPixelFormatR16Unorm; |
| 106 | return true; |
| 107 | case kRG_1616_GrPixelConfig: |
| 108 | *format = MTLPixelFormatRG16Unorm; |
| 109 | return true; |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 110 | case kRGBA_16161616_GrPixelConfig: |
| 111 | *format = MTLPixelFormatRGBA16Unorm; |
| 112 | return true; |
| 113 | case kRG_half_GrPixelConfig: |
| 114 | *format = MTLPixelFormatRG16Float; |
| 115 | return true; |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 116 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 117 | SK_ABORT("Unexpected config"); |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 118 | } |
| 119 | |
Timothy Liang | ff19c8f | 2018-07-11 13:27:21 -0400 | [diff] [blame] | 120 | MTLTextureDescriptor* GrGetMTLTextureDescriptor(id<MTLTexture> mtlTexture) { |
| 121 | MTLTextureDescriptor* texDesc = [[MTLTextureDescriptor alloc] init]; |
| 122 | texDesc.textureType = mtlTexture.textureType; |
| 123 | texDesc.pixelFormat = mtlTexture.pixelFormat; |
| 124 | texDesc.width = mtlTexture.width; |
| 125 | texDesc.height = mtlTexture.height; |
| 126 | texDesc.depth = mtlTexture.depth; |
| 127 | texDesc.mipmapLevelCount = mtlTexture.mipmapLevelCount; |
| 128 | texDesc.arrayLength = mtlTexture.arrayLength; |
| 129 | texDesc.sampleCount = mtlTexture.sampleCount; |
| 130 | texDesc.usage = mtlTexture.usage; |
| 131 | return texDesc; |
| 132 | } |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 133 | |
| 134 | #if PRINT_MSL |
| 135 | void print_msl(const char* source) { |
| 136 | SkTArray<SkString> lines; |
| 137 | SkStrSplit(source, "\n", kStrict_SkStrSplitMode, &lines); |
| 138 | for (int i = 0; i < lines.count(); i++) { |
| 139 | SkString& line = lines[i]; |
| 140 | line.prependf("%4i\t", i + 1); |
| 141 | SkDebugf("%s\n", line.c_str()); |
| 142 | } |
| 143 | } |
| 144 | #endif |
| 145 | |
| 146 | id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu, |
| 147 | const char* shaderString, |
| 148 | SkSL::Program::Kind kind, |
| 149 | const SkSL::Program::Settings& settings, |
| 150 | SkSL::Program::Inputs* outInputs) { |
| 151 | std::unique_ptr<SkSL::Program> program = |
| 152 | gpu->shaderCompiler()->convertProgram(kind, |
| 153 | SkSL::String(shaderString), |
| 154 | settings); |
| 155 | |
| 156 | if (!program) { |
| 157 | SkDebugf("SkSL error:\n%s\n", gpu->shaderCompiler()->errorText().c_str()); |
| 158 | SkASSERT(false); |
Jim Van Verth | 0c9ac58 | 2019-07-24 15:41:54 -0400 | [diff] [blame] | 159 | return nil; |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | *outInputs = program->fInputs; |
| 163 | SkSL::String code; |
| 164 | if (!gpu->shaderCompiler()->toMetal(*program, &code)) { |
| 165 | SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str()); |
| 166 | SkASSERT(false); |
| 167 | return nil; |
| 168 | } |
| 169 | NSString* mtlCode = [[NSString alloc] initWithCString: code.c_str() |
| 170 | encoding: NSASCIIStringEncoding]; |
| 171 | #if PRINT_MSL |
| 172 | print_msl([mtlCode cStringUsingEncoding: NSASCIIStringEncoding]); |
| 173 | #endif |
| 174 | |
| 175 | MTLCompileOptions* defaultOptions = [[MTLCompileOptions alloc] init]; |
Jim Van Verth | ccd895e | 2019-06-28 13:01:58 -0400 | [diff] [blame] | 176 | #if defined(SK_BUILD_FOR_MAC) && defined(GR_USE_COMPLETION_HANDLER) |
Jim Van Verth | a885b89 | 2019-06-24 15:09:57 -0400 | [diff] [blame] | 177 | bool timedout; |
| 178 | id<MTLLibrary> compiledLibrary = GrMtlNewLibraryWithSource(gpu->device(), mtlCode, |
| 179 | defaultOptions, &timedout); |
| 180 | if (timedout) { |
| 181 | // try again |
| 182 | compiledLibrary = GrMtlNewLibraryWithSource(gpu->device(), mtlCode, |
| 183 | defaultOptions, &timedout); |
| 184 | } |
| 185 | #else |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 186 | NSError* error = nil; |
| 187 | id<MTLLibrary> compiledLibrary = [gpu->device() newLibraryWithSource: mtlCode |
| 188 | options: defaultOptions |
| 189 | error: &error]; |
| 190 | if (error) { |
Ethan Nicholas | f931e40 | 2019-07-26 15:40:33 -0400 | [diff] [blame] | 191 | SkDebugf("Error compiling MSL shader: %s\n%s\n", |
| 192 | code.c_str(), |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 193 | [[error localizedDescription] cStringUsingEncoding: NSASCIIStringEncoding]); |
| 194 | return nil; |
| 195 | } |
Jim Van Verth | a885b89 | 2019-06-24 15:09:57 -0400 | [diff] [blame] | 196 | #endif |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 197 | return compiledLibrary; |
| 198 | } |
| 199 | |
Jim Van Verth | a885b89 | 2019-06-24 15:09:57 -0400 | [diff] [blame] | 200 | id<MTLLibrary> GrMtlNewLibraryWithSource(id<MTLDevice> device, NSString* mslCode, |
| 201 | MTLCompileOptions* options, bool* timedout) { |
| 202 | dispatch_semaphore_t compilerSemaphore = dispatch_semaphore_create(0); |
| 203 | |
| 204 | __block dispatch_semaphore_t semaphore = compilerSemaphore; |
| 205 | __block id<MTLLibrary> compiledLibrary; |
| 206 | [device newLibraryWithSource: mslCode |
| 207 | options: options |
| 208 | completionHandler: |
| 209 | ^(id<MTLLibrary> library, NSError* error) { |
| 210 | if (error) { |
Ethan Nicholas | f931e40 | 2019-07-26 15:40:33 -0400 | [diff] [blame] | 211 | SkDebugf("Error compiling MSL shader: %s\n%s\n", |
| 212 | mslCode, |
Jim Van Verth | a885b89 | 2019-06-24 15:09:57 -0400 | [diff] [blame] | 213 | [[error localizedDescription] cStringUsingEncoding: NSASCIIStringEncoding]); |
| 214 | } |
| 215 | compiledLibrary = library; |
| 216 | dispatch_semaphore_signal(semaphore); |
| 217 | } |
| 218 | ]; |
| 219 | |
| 220 | // Wait 100 ms for the compiler |
| 221 | if (dispatch_semaphore_wait(compilerSemaphore, dispatch_time(DISPATCH_TIME_NOW, 100000))) { |
| 222 | SkDebugf("Timeout compiling MSL shader\n"); |
| 223 | *timedout = true; |
| 224 | return nil; |
| 225 | } |
| 226 | |
| 227 | *timedout = false; |
| 228 | return compiledLibrary; |
| 229 | } |
| 230 | |
| 231 | id<MTLRenderPipelineState> GrMtlNewRenderPipelineStateWithDescriptor( |
| 232 | id<MTLDevice> device, MTLRenderPipelineDescriptor* pipelineDescriptor, bool* timedout) { |
| 233 | dispatch_semaphore_t pipelineSemaphore = dispatch_semaphore_create(0); |
| 234 | |
| 235 | __block dispatch_semaphore_t semaphore = pipelineSemaphore; |
| 236 | __block id<MTLRenderPipelineState> pipelineState; |
| 237 | [device newRenderPipelineStateWithDescriptor: pipelineDescriptor |
| 238 | completionHandler: |
| 239 | ^(id<MTLRenderPipelineState> state, NSError* error) { |
| 240 | if (error) { |
| 241 | SkDebugf("Error creating pipeline: %s\n", |
| 242 | [[error localizedDescription] cStringUsingEncoding: NSASCIIStringEncoding]); |
| 243 | } |
| 244 | pipelineState = state; |
| 245 | dispatch_semaphore_signal(semaphore); |
| 246 | } |
| 247 | ]; |
| 248 | |
| 249 | // Wait 500 ms for pipeline creation |
| 250 | if (dispatch_semaphore_wait(pipelineSemaphore, dispatch_time(DISPATCH_TIME_NOW, 500000))) { |
| 251 | SkDebugf("Timeout creating pipeline.\n"); |
| 252 | *timedout = true; |
| 253 | return nil; |
| 254 | } |
| 255 | |
| 256 | *timedout = false; |
| 257 | return pipelineState; |
| 258 | } |
| 259 | |
Jim Van Verth | d361e64 | 2019-07-11 15:40:53 -0400 | [diff] [blame] | 260 | id<MTLTexture> GrGetMTLTextureFromSurface(GrSurface* surface) { |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 261 | id<MTLTexture> mtlTexture = nil; |
| 262 | |
| 263 | GrMtlRenderTarget* renderTarget = static_cast<GrMtlRenderTarget*>(surface->asRenderTarget()); |
| 264 | GrMtlTexture* texture; |
| 265 | if (renderTarget) { |
Jim Van Verth | d361e64 | 2019-07-11 15:40:53 -0400 | [diff] [blame] | 266 | // We should not be using this for multisampled rendertargets |
| 267 | if (renderTarget->numSamples() > 1) { |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 268 | SkASSERT(false); |
Jim Van Verth | d361e64 | 2019-07-11 15:40:53 -0400 | [diff] [blame] | 269 | return nil; |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 270 | } |
Jim Van Verth | d361e64 | 2019-07-11 15:40:53 -0400 | [diff] [blame] | 271 | mtlTexture = renderTarget->mtlColorTexture(); |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 272 | } else { |
| 273 | texture = static_cast<GrMtlTexture*>(surface->asTexture()); |
| 274 | if (texture) { |
| 275 | mtlTexture = texture->mtlTexture(); |
| 276 | } |
| 277 | } |
| 278 | return mtlTexture; |
| 279 | } |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 280 | |
| 281 | |
| 282 | ////////////////////////////////////////////////////////////////////////////// |
| 283 | // CPP Utils |
| 284 | |
| 285 | GrMTLPixelFormat GrGetMTLPixelFormatFromMtlTextureInfo(const GrMtlTextureInfo& info) { |
Jim Van Verth | dac1e55 | 2019-05-31 09:10:55 -0400 | [diff] [blame] | 286 | id<MTLTexture> mtlTexture = GrGetMTLTexture(info.fTexture.get()); |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 287 | return static_cast<GrMTLPixelFormat>(mtlTexture.pixelFormat); |
| 288 | } |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 289 | |
| 290 | size_t GrMtlBytesPerFormat(MTLPixelFormat format) { |
| 291 | switch (format) { |
Robert Phillips | b7f95d1 | 2019-07-26 11:13:19 -0400 | [diff] [blame] | 292 | case MTLPixelFormatA8Unorm: |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 293 | case MTLPixelFormatR8Unorm: |
| 294 | return 1; |
| 295 | |
| 296 | #ifdef SK_BUILD_FOR_IOS |
| 297 | case MTLPixelFormatB5G6R5Unorm: |
| 298 | case MTLPixelFormatABGR4Unorm: |
| 299 | #endif |
| 300 | case MTLPixelFormatRG8Unorm: |
| 301 | case MTLPixelFormatR16Float: |
| 302 | case MTLPixelFormatR16Unorm: |
| 303 | return 2; |
| 304 | |
| 305 | case MTLPixelFormatRGBA8Unorm: |
| 306 | case MTLPixelFormatBGRA8Unorm: |
| 307 | case MTLPixelFormatRGBA8Unorm_sRGB: |
| 308 | case MTLPixelFormatRGB10A2Unorm: |
| 309 | case MTLPixelFormatRG16Unorm: |
| 310 | case MTLPixelFormatRG16Float: |
| 311 | return 4; |
| 312 | |
| 313 | case MTLPixelFormatRGBA16Float: |
| 314 | case MTLPixelFormatRGBA16Unorm: |
| 315 | return 8; |
| 316 | |
| 317 | case MTLPixelFormatRGBA32Float: |
| 318 | return 16; |
| 319 | |
| 320 | #ifdef SK_BUILD_FOR_IOS |
| 321 | case MTLPixelFormatETC2_RGB8: |
| 322 | return 0; |
| 323 | #endif |
| 324 | default: |
| 325 | SK_ABORT("Invalid Mtl format"); |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | SK_ABORT("Invalid Mtl format"); |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 329 | } |
| 330 | |
Jim Van Verth | e367101 | 2019-09-18 09:53:31 -0400 | [diff] [blame] | 331 | bool GrMtlFormatIsCompressed(MTLPixelFormat mtlFormat) { |
| 332 | switch (mtlFormat) { |
| 333 | #ifdef SK_BUILD_FOR_IOS |
| 334 | case MTLPixelFormatETC2_RGB8: |
| 335 | return true; |
| 336 | #endif |
| 337 | default: |
| 338 | return false; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | bool GrMtlFormatToCompressionType(MTLPixelFormat mtlFormat, |
| 343 | SkImage::CompressionType* compressionType) { |
| 344 | switch (mtlFormat) { |
| 345 | #ifdef SK_BUILD_FOR_IOS |
| 346 | case MTLPixelFormatETC2_RGB8: |
| 347 | *compressionType = SkImage::kETC1_CompressionType; |
| 348 | return true; |
| 349 | #endif |
| 350 | default: |
| 351 | return false; |
| 352 | } |
| 353 | } |
| 354 | |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 355 | #if GR_TEST_UTILS |
Robert Phillips | 7f36798 | 2019-09-26 14:01:36 -0400 | [diff] [blame^] | 356 | bool GrMtlFormatIsBGRA(GrMTLPixelFormat mtlFormat) { |
| 357 | return mtlFormat == MTLPixelFormatBGRA8Unorm; |
| 358 | } |
| 359 | |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 360 | const char* GrMtlFormatToStr(GrMTLPixelFormat mtlFormat) { |
| 361 | switch (mtlFormat) { |
| 362 | case MTLPixelFormatInvalid: return "Invalid"; |
| 363 | case MTLPixelFormatRGBA8Unorm: return "RGBA8Unorm"; |
| 364 | case MTLPixelFormatR8Unorm: return "R8Unorm"; |
| 365 | case MTLPixelFormatA8Unorm: return "A8Unorm"; |
| 366 | case MTLPixelFormatBGRA8Unorm: return "BGRA8Unorm"; |
| 367 | #ifdef SK_BUILD_FOR_IOS |
| 368 | case MTLPixelFormatB5G6R5Unorm: return "B5G6R5Unorm"; |
| 369 | #endif |
| 370 | case MTLPixelFormatRGBA16Float: return "RGBA16Float"; |
| 371 | case MTLPixelFormatR16Float: return "R16Float"; |
| 372 | case MTLPixelFormatRG8Unorm: return "RG8Unorm"; |
| 373 | case MTLPixelFormatRGB10A2Unorm: return "RGB10A2Unorm"; |
| 374 | #ifdef SK_BUILD_FOR_IOS |
| 375 | case MTLPixelFormatABGR4Unorm: return "ABGR4Unorm"; |
| 376 | #endif |
| 377 | case MTLPixelFormatRGBA32Float: return "RGBA32Float"; |
| 378 | case MTLPixelFormatRGBA8Unorm_sRGB: return "RGBA8Unorm_sRGB"; |
| 379 | case MTLPixelFormatR16Unorm: return "R16Unorm"; |
| 380 | case MTLPixelFormatRG16Unorm: return "RG16Unorm"; |
| 381 | #ifdef SK_BUILD_FOR_IOS |
| 382 | case MTLPixelFormatETC2_RGB8: return "ETC2_RGB8"; |
| 383 | #endif |
| 384 | case MTLPixelFormatRGBA16Unorm: return "RGBA16Unorm"; |
| 385 | case MTLPixelFormatRG16Float: return "RG16Float"; |
| 386 | |
| 387 | default: return "Unknown"; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | #endif |
| 392 | |
| 393 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 394 | |