2019-05-16 16:43:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-12-16 01:23:03 +00:00
|
|
|
#include "src/gpu/mtl/GrMtlCaps.h"
|
2019-05-16 16:43:11 +00:00
|
|
|
#include "tests/Test.h"
|
2020-12-16 01:23:03 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-07-07 23:31:14 +00:00
|
|
|
#import <Metal/Metal.h>
|
2020-12-16 01:23:03 +00:00
|
|
|
|
|
|
|
using sk_gpu_test::ManagedBackendTexture;
|
2019-05-16 16:43:11 +00:00
|
|
|
|
|
|
|
// In BackendAllocationTest.cpp
|
2020-07-17 18:15:51 +00:00
|
|
|
void test_wrapping(GrDirectContext*,
|
|
|
|
skiatest::Reporter*,
|
2020-12-16 01:23:03 +00:00
|
|
|
std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
|
|
|
|
GrMipmapped,
|
|
|
|
GrRenderable)> create,
|
2020-07-17 18:15:51 +00:00
|
|
|
GrColorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped,
|
2020-12-16 01:23:03 +00:00
|
|
|
GrRenderable);
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-07-17 18:15:51 +00:00
|
|
|
void test_color_init(GrDirectContext*,
|
|
|
|
skiatest::Reporter*,
|
2020-12-16 01:23:03 +00:00
|
|
|
std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
|
|
|
|
const SkColor4f&,
|
|
|
|
GrMipmapped,
|
|
|
|
GrRenderable)> create,
|
2020-07-17 18:15:51 +00:00
|
|
|
GrColorType,
|
|
|
|
const SkColor4f&,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped,
|
2020-12-16 01:23:03 +00:00
|
|
|
GrRenderable);
|
2019-05-23 13:38:27 +00:00
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
DEF_GPUTEST_FOR_METAL_CONTEXT(MtlBackendAllocationTest, reporter, ctxInfo) {
|
2020-07-17 18:15:51 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
const GrMtlCaps* mtlCaps = static_cast<const GrMtlCaps*>(dContext->priv().caps());
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
|
2019-09-26 18:01:36 +00:00
|
|
|
constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f };
|
2019-05-23 13:38:27 +00:00
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
struct {
|
2019-07-26 15:13:19 +00:00
|
|
|
GrColorType fColorType;
|
2019-09-26 18:01:36 +00:00
|
|
|
MTLPixelFormat fFormat;
|
2019-05-23 13:38:27 +00:00
|
|
|
SkColor4f fColor;
|
2019-05-16 16:43:11 +00:00
|
|
|
} combinations[] = {
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGBA_8888, MTLPixelFormatRGBA8Unorm, SkColors::kRed },
|
|
|
|
{ GrColorType::kRGBA_8888_SRGB, MTLPixelFormatRGBA8Unorm_sRGB, SkColors::kRed },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-08-14 14:43:28 +00:00
|
|
|
// In this configuration (i.e., an RGB_888x colortype with an RGBA8 backing format),
|
|
|
|
// there is nothing to tell Skia to make the provided color opaque. Clients will need
|
|
|
|
// to provide an opaque initialization color in this case.
|
|
|
|
{ GrColorType::kRGB_888x, MTLPixelFormatRGBA8Unorm, SkColors::kYellow },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kBGRA_8888, MTLPixelFormatBGRA8Unorm, SkColors::kBlue },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-04-29 12:58:39 +00:00
|
|
|
{ GrColorType::kRGBA_1010102, MTLPixelFormatRGB10A2Unorm,
|
|
|
|
{ 0.25f, 0.5f, 0.75f, 1.0f } },
|
2020-05-01 13:43:04 +00:00
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
2020-04-29 12:58:39 +00:00
|
|
|
{ GrColorType::kBGRA_1010102, MTLPixelFormatBGR10A2Unorm,
|
|
|
|
{ 0.25f, 0.5f, 0.75f, 1.0f } },
|
2020-05-01 13:43:04 +00:00
|
|
|
#endif
|
2019-05-16 16:43:11 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kBGR_565, MTLPixelFormatB5G6R5Unorm, SkColors::kRed },
|
|
|
|
{ GrColorType::kABGR_4444, MTLPixelFormatABGR4Unorm, SkColors::kGreen },
|
2019-05-16 16:43:11 +00:00
|
|
|
#endif
|
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kAlpha_8, MTLPixelFormatA8Unorm, kTransCol },
|
|
|
|
{ GrColorType::kAlpha_8, MTLPixelFormatR8Unorm, kTransCol },
|
2019-09-26 18:01:36 +00:00
|
|
|
{ GrColorType::kGray_8, MTLPixelFormatR8Unorm, kGrayCol },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGBA_F16_Clamped, MTLPixelFormatRGBA16Float, SkColors::kLtGray },
|
|
|
|
{ GrColorType::kRGBA_F16, MTLPixelFormatRGBA16Float, SkColors::kYellow },
|
|
|
|
|
2019-09-04 19:05:35 +00:00
|
|
|
{ GrColorType::kRG_88, MTLPixelFormatRG8Unorm, { 0.5f, 0.5f, 0, 1 } },
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kAlpha_F16, MTLPixelFormatR16Float, { 1.0f, 0, 0, 0.5f } },
|
|
|
|
|
2019-09-11 21:03:28 +00:00
|
|
|
{ GrColorType::kAlpha_16, MTLPixelFormatR16Unorm, kTransCol },
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRG_1616, MTLPixelFormatRG16Unorm, SkColors::kYellow },
|
|
|
|
|
|
|
|
{ GrColorType::kRGBA_16161616, MTLPixelFormatRGBA16Unorm, SkColors::kLtGray },
|
|
|
|
{ GrColorType::kRG_F16, MTLPixelFormatRG16Float, SkColors::kYellow },
|
2019-05-16 16:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeMtl(combo.fFormat);
|
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
if (!mtlCaps->isFormatTexturable(combo.fFormat)) {
|
2019-05-16 16:43:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skbug.com/9086 (Metal caps may not be handling RGBA32 correctly)
|
2019-07-26 15:13:19 +00:00
|
|
|
if (GrColorType::kRGBA_F32 == combo.fColorType) {
|
2019-05-16 16:43:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:27:25 +00:00
|
|
|
for (auto mipMapped : { GrMipmapped::kNo, GrMipmapped::kYes }) {
|
2020-07-21 14:49:25 +00:00
|
|
|
if (GrMipmapped::kYes == mipMapped && !mtlCaps->mipmapSupport()) {
|
2019-05-17 18:19:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
|
|
|
|
|
|
|
|
if (GrRenderable::kYes == renderable) {
|
2019-08-05 19:38:40 +00:00
|
|
|
// We must also check whether we allow rendering to the format using the
|
|
|
|
// color type.
|
2019-08-06 16:05:31 +00:00
|
|
|
if (!mtlCaps->isFormatAsColorTypeRenderable(
|
|
|
|
combo.fColorType, GrBackendFormat::MakeMtl(combo.fFormat), 1)) {
|
2019-05-17 18:19:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 21:24:31 +00:00
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
auto uninitCreateMtd = [format](GrDirectContext* dContext,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped mipMapped,
|
2019-05-21 21:24:31 +00:00
|
|
|
GrRenderable renderable) {
|
2020-12-16 01:23:03 +00:00
|
|
|
return ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
32, 32,
|
|
|
|
format,
|
|
|
|
mipMapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2019-05-21 21:24:31 +00:00
|
|
|
};
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
test_wrapping(dContext, reporter, uninitCreateMtd, combo.fColorType, mipMapped,
|
|
|
|
renderable);
|
2019-05-21 21:24:31 +00:00
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
|
|
|
|
{
|
2019-11-04 20:04:54 +00:00
|
|
|
// We're creating backend textures without specifying a color type "view" of
|
|
|
|
// them at the public API level. Therefore, Ganesh will not apply any swizzles
|
|
|
|
// before writing the color to the texture. However, our validation code does
|
|
|
|
// rely on interpreting the texture contents via a SkColorType and therefore
|
|
|
|
// swizzles may be applied during the read step.
|
|
|
|
// Ideally we'd update our validation code to use a "raw" read that doesn't
|
|
|
|
// impose a color type but for now we just munge the data we upload to match the
|
|
|
|
// expectation.
|
|
|
|
GrSwizzle swizzle;
|
|
|
|
switch (combo.fColorType) {
|
|
|
|
case GrColorType::kAlpha_8:
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
|
|
|
case GrColorType::kAlpha_16:
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
|
|
|
case GrColorType::kAlpha_F16:
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-05-06 15:40:03 +00:00
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
auto createWithColorMtd = [format, swizzle](GrDirectContext* dContext,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipmapped mipMapped,
|
|
|
|
GrRenderable renderable) {
|
2019-11-04 20:04:54 +00:00
|
|
|
auto swizzledColor = swizzle.applyTo(color);
|
2020-12-16 01:23:03 +00:00
|
|
|
return ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
32, 32,
|
|
|
|
format,
|
|
|
|
swizzledColor,
|
|
|
|
mipMapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2019-05-23 13:38:27 +00:00
|
|
|
};
|
2020-12-16 01:23:03 +00:00
|
|
|
test_color_init(dContext, reporter, createWithColorMtd, combo.fColorType,
|
|
|
|
combo.fColor, mipMapped, renderable);
|
2019-05-23 13:38:27 +00:00
|
|
|
}
|
2019-05-17 18:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-21 21:24:31 +00:00
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|