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