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