1/* 2 * Copyright 2021 Google LLC 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 "tests/Test.h" 9 10#include "include/gpu/graphite/BackendTexture.h" 11#include "include/gpu/graphite/Context.h" 12#include "include/gpu/graphite/Recorder.h" 13#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" 14 15#import <Metal/Metal.h> 16 17using namespace skgpu::graphite; 18 19namespace { 20 const SkISize kSize = {16, 16}; 21} 22 23DEF_GRAPHITE_TEST_FOR_METAL_CONTEXT(MtlBackendTextureTest, reporter, context, testContext) { 24 auto recorder = context->makeRecorder(); 25 26 MtlTextureInfo textureInfo; 27 textureInfo.fSampleCount = 1; 28 textureInfo.fMipmapped = skgpu::Mipmapped::kNo; 29 textureInfo.fFormat = MTLPixelFormatRGBA8Unorm; 30 textureInfo.fStorageMode = MTLStorageModePrivate; 31 textureInfo.fUsage = MTLTextureUsageShaderRead; 32 33 // TODO: For now we are just testing the basic case of RGBA single sample because that is what 34 // we've added to the backend. However, once we expand the backend support to handle all the 35 // formats this test should iterate over a large set of combinations. See the Ganesh 36 // MtlBackendAllocationTest for example of doing this. 37 38 auto beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeMetal(textureInfo)); 39 REPORTER_ASSERT(reporter, beTexture.isValid()); 40 recorder->deleteBackendTexture(beTexture); 41 42 // It should also pass if we set the usage to be a render target 43 textureInfo.fUsage |= MTLTextureUsageRenderTarget; 44 beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeMetal(textureInfo)); 45 REPORTER_ASSERT(reporter, beTexture.isValid()); 46 recorder->deleteBackendTexture(beTexture); 47 48 // It should fail with a format that isn't one of our supported formats 49 textureInfo.fFormat = MTLPixelFormatRGB9E5Float; 50 beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeMetal(textureInfo)); 51 REPORTER_ASSERT(reporter, !beTexture.isValid()); 52 recorder->deleteBackendTexture(beTexture); 53 54 // It should fail with a sample count greater than 1 55 textureInfo.fFormat = MTLPixelFormatRGBA8Unorm; 56 textureInfo.fSampleCount = 4; 57 beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeMetal(textureInfo)); 58 REPORTER_ASSERT(reporter, !beTexture.isValid()); 59 recorder->deleteBackendTexture(beTexture); 60} 61