Fix asserts in Metal tests.

Bug: skia:8243
Change-Id: I5d976e2740bd0348e1c71cea2cda05d93bc004e9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/201397
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Jim Van Verth 2019-03-15 15:22:39 -04:00 committed by Skia Commit-Bot
parent 17bd9fa346
commit a3407ab9a6
9 changed files with 81 additions and 33 deletions

View File

@ -304,7 +304,7 @@ void GrMtlCaps::initShaderCaps() {
} else {
if (kGray_8_GrPixelConfig == config) {
shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRA();
} else if (kRGB_888X_GrPixelConfig == config) {
} else if (kRGB_888X_GrPixelConfig == config || kRGB_888_GrPixelConfig == config ) {
shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGB1();
} else {
shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RGBA();
@ -360,6 +360,10 @@ void GrMtlCaps::initConfigTable() {
info = &fConfigTable[kAlpha_8_GrPixelConfig];
info->fFlags = ConfigInfo::kAllFlags;
// Alpha_8_as_Red uses R8Unorm
info = &fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
info->fFlags = ConfigInfo::kAllFlags;
// Gray_8 uses R8Unorm
info = &fConfigTable[kGray_8_GrPixelConfig];
info->fFlags = ConfigInfo::kAllFlags;
@ -388,6 +392,10 @@ void GrMtlCaps::initConfigTable() {
info = &fConfigTable[kRGB_888X_GrPixelConfig];
info->fFlags = ConfigInfo::kTextureable_Flag;
// RGB_888 uses RGBA8Unorm and we will swizzle the 1
info = &fConfigTable[kRGB_888_GrPixelConfig];
info->fFlags = ConfigInfo::kTextureable_Flag;
// BGRA_8888 uses BGRA8Unorm
info = &fConfigTable[kBGRA_8888_GrPixelConfig];
info->fFlags = ConfigInfo::kAllFlags;

View File

@ -344,4 +344,5 @@ void GrMtlGpuRTCommandBuffer::sendIndexedInstancedMeshToGpu(GrPrimitiveType prim
instanceCount:instanceCount
baseVertex:baseVertex
baseInstance:baseInstance];
fGpu->stats()->incNumDraws();
}

View File

@ -31,8 +31,8 @@ bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format) {
*format = MTLPixelFormatRGBA8Unorm;
return true;
case kRGB_888_GrPixelConfig:
// TODO: MTLPixelFormatRGB8Unorm
return false;
*format = MTLPixelFormatRGBA8Unorm;
return true;
case kRGB_888X_GrPixelConfig:
*format = MTLPixelFormatRGBA8Unorm;
return true;

View File

@ -9,10 +9,12 @@
static void finalize_helper(GrMtlVaryingHandler::VarArray& vars) {
int locationIndex;
int componentCount = 0;
for (locationIndex = 0; locationIndex < vars.count(); locationIndex++) {
GrShaderVar& var = vars[locationIndex];
// Metal only allows scalars (including bool and char) and vectors as varyings
SkASSERT(GrSLTypeVecLength(var.getType()) != -1);
componentCount += GrSLTypeVecLength(var.getType());
SkString location;
location.appendf("location = %d", locationIndex);
@ -20,9 +22,10 @@ static void finalize_helper(GrMtlVaryingHandler::VarArray& vars) {
}
// The max number of inputs is 60 for iOS and 32 for macOS. The max number of components is 60
// for iOS and 128 for macOS. To be conservative, we are going to assert that we have less than
// 15 varyings because in the worst case scenario, they are all vec4s (15 * 4 = 60). If we hit
// this assert, we can implement a function in GrMtlCaps to be less conservative.
SkASSERT(locationIndex <= 15);
// 32 varyings and less than 60 components across all varyings. If we hit this assert, we can
// implement a function in GrMtlCaps to be less conservative.
SkASSERT(locationIndex <= 32);
SkASSERT(componentCount <= 60);
}
void GrMtlVaryingHandler::onFinalize() {

View File

@ -138,9 +138,13 @@ static void run_test(skiatest::Reporter* reporter, GrContext* context, int array
static const int CONTROL_ARRAY_SIZE = DEV_W * DEV_H;
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGBA4444TextureTest, reporter, ctxInfo) {
run_test(reporter, ctxInfo.grContext(), CONTROL_ARRAY_SIZE, kARGB_4444_SkColorType);
if (ctxInfo.grContext()->colorTypeSupportedAsImage(kARGB_4444_SkColorType)) {
run_test(reporter, ctxInfo.grContext(), CONTROL_ARRAY_SIZE, kARGB_4444_SkColorType);
}
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGB565TextureTest, reporter, ctxInfo) {
run_test(reporter, ctxInfo.grContext(), CONTROL_ARRAY_SIZE, kRGB_565_SkColorType);
if (ctxInfo.grContext()->colorTypeSupportedAsImage(kRGB_565_SkColorType)) {
run_test(reporter, ctxInfo.grContext(), CONTROL_ARRAY_SIZE, kRGB_565_SkColorType);
}
}

View File

@ -63,8 +63,15 @@ private:
fAttributes.reset(new Attribute[numAttribs]);
for (auto i = 0; i < numAttribs; ++i) {
fAttribNames[i].printf("attr%d", i);
fAttributes[i] = {fAttribNames[i].c_str(), kFloat2_GrVertexAttribType,
kFloat2_GrSLType};
// This gives us more of a mix of attribute types, and allows the
// component count to fit within the limits for iOS Metal.
if (i & 0x1) {
fAttributes[i] = {fAttribNames[i].c_str(), kFloat_GrVertexAttribType,
kFloat_GrSLType};
} else {
fAttributes[i] = {fAttribNames[i].c_str(), kFloat2_GrVertexAttribType,
kFloat2_GrSLType};
}
}
this->setVertexAttributes(fAttributes.get(), numAttribs);
}

View File

@ -228,8 +228,10 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
#endif
#ifdef SK_METAL
case GrBackendApi::kMetal: {
SkASSERT(!masterContext);
testCtx.reset(CreatePlatformMtlTestContext(nullptr));
MtlTestContext* mtlSharedContext = masterContext
? static_cast<MtlTestContext*>(masterContext->fTestContext) : nullptr;
SkASSERT(kMetal_ContextType == type);
testCtx.reset(CreatePlatformMtlTestContext(mtlSharedContext));
if (!testCtx) {
return ContextInfo();
}

View File

@ -13,10 +13,24 @@
#ifdef SK_METAL
namespace sk_gpu_test {
TestContext* CreatePlatformMtlTestContext(TestContext*);
class MtlTestContext : public TestContext {
public:
GrBackendApi backend() override { return GrBackendApi::kMetal; }
protected:
MtlTestContext() {}
private:
typedef TestContext INHERITED;
};
/**
* Creates Metal context object bound to the native Metal library.
*/
MtlTestContext* CreatePlatformMtlTestContext(MtlTestContext*);
} // namespace sk_gpu_test
#endif
#endif /* MtlTestContext_h */

View File

@ -10,10 +10,10 @@
#include "GrContext.h"
#include "GrContextOptions.h"
#import <Metal/Metal.h>
#ifdef SK_METAL
#import <Metal/Metal.h>
// Helper macros for autorelease pools
#define SK_BEGIN_AUTORELEASE_BLOCK @autoreleasepool {
#define SK_END_AUTORELEASE_BLOCK }
@ -112,21 +112,26 @@ private:
GR_STATIC_ASSERT(sizeof(VkFence) <= sizeof(sk_gpu_test::PlatformFence));
#endif
class MtlTestContext : public sk_gpu_test::TestContext {
class MtlTestContextImpl : public sk_gpu_test::MtlTestContext {
public:
static MtlTestContext* Create(TestContext* sharedContext) {
SK_BEGIN_AUTORELEASE_BLOCK
SkASSERT(!sharedContext);
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> queue = [device newCommandQueue];
static MtlTestContext* Create(MtlTestContext* sharedContext) {
id<MTLDevice> device;
id<MTLCommandQueue> queue;
if (sharedContext) {
MtlTestContextImpl* sharedContextImpl = (MtlTestContextImpl*) sharedContext;
device = sharedContextImpl->device();
queue = sharedContextImpl->queue();
} else {
SK_BEGIN_AUTORELEASE_BLOCK
device = MTLCreateSystemDefaultDevice();
queue = [device newCommandQueue];
SK_END_AUTORELEASE_BLOCK
}
return new MtlTestContext(device, queue);
SK_END_AUTORELEASE_BLOCK
return new MtlTestContextImpl(device, queue);
}
~MtlTestContext() override { this->teardown(); }
GrBackendApi backend() override { return GrBackendApi::kMetal; }
~MtlTestContextImpl() override { this->teardown(); }
void testAbandon() override {}
@ -141,9 +146,12 @@ public:
options);
}
id<MTLDevice> device() { return fDevice; }
id<MTLCommandQueue> queue() { return fQueue; }
private:
MtlTestContext(id<MTLDevice> device, id<MTLCommandQueue> queue)
: fDevice(device), fQueue(queue) {
MtlTestContextImpl(id<MTLDevice> device, id<MTLCommandQueue> queue)
: INHERITED(), fDevice(device), fQueue(queue) {
fFenceSync.reset(nullptr);
}
@ -151,19 +159,20 @@ private:
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
void onPlatformSwapBuffers() const override {}
id<MTLDevice> fDevice;
id<MTLDevice> fDevice;
id<MTLCommandQueue> fQueue;
typedef sk_gpu_test::TestContext INHERITED;
typedef sk_gpu_test::MtlTestContext INHERITED;
};
} // anonymous namespace
namespace sk_gpu_test {
TestContext* CreatePlatformMtlTestContext(TestContext* sharedContext) {
return MtlTestContext::Create(sharedContext);
MtlTestContext* CreatePlatformMtlTestContext(MtlTestContext* sharedContext) {
return MtlTestContextImpl::Create(sharedContext);
}
} // namespace sk_gpu_test