aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2016-02-22 09:56:40 -0500
committerGravatar Greg Daniel <egdaniel@google.com>2016-02-22 09:56:40 -0500
commit164a9f061c5186ae931cc23a3c73f32472e80ff5 (patch)
tree79929f22803c622a2e0c8dbc333717c275ca0405 /tests
parent129ed1cd6d792f3f6cf563aefa9756fc6308289d (diff)
Add vulkan files into skia repo. This is an incomplete backend with only partial functionality at this time.
Diffstat (limited to 'tests')
-rw-r--r--tests/VkClearTests.cpp218
-rw-r--r--tests/VkUploadPixelsTests.cpp160
2 files changed, 378 insertions, 0 deletions
diff --git a/tests/VkClearTests.cpp b/tests/VkClearTests.cpp
new file mode 100644
index 0000000000..60e7981528
--- /dev/null
+++ b/tests/VkClearTests.cpp
@@ -0,0 +1,218 @@
+
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// This is a GPU-backend specific test. It relies on static intializers to work
+
+#include "SkTypes.h"
+
+#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_VULKAN)
+
+#include "GrContextFactory.h"
+#include "GrTest.h"
+#include "Test.h"
+#include "vk/GrVkGpu.h"
+
+bool does_full_buffer_contain_correct_color(GrColor* buffer,
+ GrColor clearColor,
+ GrPixelConfig config,
+ int width,
+ int height) {
+ GrColor matchColor;
+ if (kRGBA_8888_GrPixelConfig == config) {
+ matchColor = clearColor;
+ } else if (kBGRA_8888_GrPixelConfig) {
+ // Hack to flip the R, B componets in the GrColor so that the comparrison will work below
+ matchColor = GrColorPackRGBA(GrColorUnpackB(clearColor),
+ GrColorUnpackG(clearColor),
+ GrColorUnpackR(clearColor),
+ GrColorUnpackA(clearColor));
+ } else {
+ // currently only supporting rgba_8888 and bgra_8888
+ return false;
+ }
+
+ for (int j = 0; j < height; ++j) {
+ for (int i = 0; i < width; ++i) {
+ if (buffer[j * width + i] != matchColor) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+void basic_clear_test(skiatest::Reporter* reporter, GrContext* context, GrPixelConfig config) {
+ GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu());
+ gpu->discard(NULL);
+ SkAutoTMalloc<GrColor> buffer(25);
+
+ GrSurfaceDesc surfDesc;
+ surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
+ surfDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ surfDesc.fWidth = 5;
+ surfDesc.fHeight = 5;
+ surfDesc.fConfig = config;
+ surfDesc.fSampleCnt = 0;
+ GrTexture* tex = gpu->createTexture(surfDesc, false, nullptr, 0);
+ SkASSERT(tex);
+ SkASSERT(tex->asRenderTarget());
+ SkIRect rect = SkIRect::MakeWH(5, 5);
+
+ gpu->clear(rect, GrColor_TRANSPARENT_BLACK, tex->asRenderTarget());
+
+ gpu->readPixels(tex, 0, 0, 5, 5, config, (void*)buffer.get(), 0);
+
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
+ GrColor_TRANSPARENT_BLACK,
+ config,
+ 5,
+ 5));
+
+ gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
+
+ gpu->readPixels(tex, 0, 0, 5, 5, config, (void*)buffer.get(), 0);
+
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
+ GrColor_WHITE,
+ config,
+ 5,
+ 5));
+
+ GrColor myColor = GrColorPackRGBA(0xFF, 0x7F, 0x40, 0x20);
+
+ gpu->clear(rect, myColor, tex->asRenderTarget());
+
+ gpu->readPixels(tex, 0, 0, 5, 5, config, (void*)buffer.get(), 0);
+
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
+ myColor,
+ config,
+ 5,
+ 5));
+}
+
+void sub_clear_test(skiatest::Reporter* reporter, GrContext* context, GrPixelConfig config) {
+ const int width = 10;
+ const int height = 10;
+ const int subWidth = width/2;
+ const int subHeight = height/2;
+ GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu());
+ gpu->discard(NULL);
+ SkAutoTMalloc<GrColor> buffer(width * height);
+ SkAutoTMalloc<GrColor> subBuffer(subWidth * subHeight);
+
+ GrSurfaceDesc surfDesc;
+ surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
+ surfDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ surfDesc.fWidth = width;
+ surfDesc.fHeight = height;
+ surfDesc.fConfig = config;
+ surfDesc.fSampleCnt = 0;
+ GrTexture* tex = gpu->createTexture(surfDesc, false, nullptr, 0);
+ SkASSERT(tex);
+ SkASSERT(tex->asRenderTarget());
+
+ SkIRect fullRect = SkIRect::MakeWH(10, 10);
+ gpu->clear(fullRect, GrColor_TRANSPARENT_BLACK, tex->asRenderTarget());
+
+ gpu->readPixels(tex, 0, 0, width, height, config, (void*)buffer.get(), 0);
+
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
+ GrColor_TRANSPARENT_BLACK,
+ config,
+ width,
+ height));
+ SkIRect rect;
+ rect = SkIRect::MakeXYWH(0, 0, subWidth, subHeight);
+ gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
+ rect = SkIRect::MakeXYWH(subWidth, 0, subWidth, subHeight);
+ gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
+ rect = SkIRect::MakeXYWH(0, subHeight, subWidth, subHeight);
+ gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
+
+ // Should fail since bottom right sub area has not been cleared to white
+ gpu->readPixels(tex, 0, 0, width, height, config, (void*)buffer.get(), 0);
+ REPORTER_ASSERT(reporter, !does_full_buffer_contain_correct_color(buffer.get(),
+ GrColor_WHITE,
+ config,
+ width,
+ height));
+
+ rect = SkIRect::MakeXYWH(subWidth, subHeight, subWidth, subHeight);
+ gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
+
+ gpu->readPixels(tex, 0, 0, width, height, config, (void*)buffer.get(), 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
+ GrColor_WHITE,
+ config,
+ width,
+ height));
+
+ // Try different colors and that each sub area has correct color
+ GrColor subColor1 = GrColorPackRGBA(0xFF, 0x00, 0x00, 0xFF);
+ GrColor subColor2 = GrColorPackRGBA(0x00, 0xFF, 0x00, 0xFF);
+ GrColor subColor3 = GrColorPackRGBA(0x00, 0x00, 0xFF, 0xFF);
+ GrColor subColor4 = GrColorPackRGBA(0xFF, 0xFF, 0x00, 0xFF);
+
+ rect = SkIRect::MakeXYWH(0, 0, subWidth, subHeight);
+ gpu->clear(rect, subColor1, tex->asRenderTarget());
+ rect = SkIRect::MakeXYWH(subWidth, 0, subWidth, subHeight);
+ gpu->clear(rect, subColor2, tex->asRenderTarget());
+ rect = SkIRect::MakeXYWH(0, subHeight, subWidth, subHeight);
+ gpu->clear(rect, subColor3, tex->asRenderTarget());
+ rect = SkIRect::MakeXYWH(subWidth, subHeight, subWidth, subHeight);
+ gpu->clear(rect, subColor4, tex->asRenderTarget());
+
+ gpu->readPixels(tex, 0, 0, subWidth, subHeight, config, (void*)subBuffer.get(), 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
+ subColor1,
+ config,
+ subWidth,
+ subHeight));
+ gpu->readPixels(tex, subWidth, 0, subWidth, subHeight, config, (void*)subBuffer.get(), 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
+ subColor2,
+ config,
+ subWidth,
+ subHeight));
+ gpu->readPixels(tex, 0, subHeight, subWidth, subHeight, config, (void*)subBuffer.get(), 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
+ subColor3,
+ config,
+ subWidth,
+ subHeight));
+ gpu->readPixels(tex, subWidth, subHeight, subWidth, subHeight,
+ config, (void*)subBuffer.get(), 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
+ subColor4,
+ config,
+ subWidth,
+ subHeight));
+}
+
+DEF_GPUTEST(VkClearTests, reporter, factory) {
+ GrContextOptions opts;
+ opts.fSuppressPrints = true;
+ GrContextFactory debugFactory(opts);
+ for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
+ if (static_cast<GrContextFactory::GLContextType>(type) !=
+ GrContextFactory::kNative_GLContextType) {
+ continue;
+ }
+ GrContext* context = debugFactory.get(static_cast<GrContextFactory::GLContextType>(type));
+ if (context) {
+ basic_clear_test(reporter, context, kRGBA_8888_GrPixelConfig);
+ basic_clear_test(reporter, context, kBGRA_8888_GrPixelConfig);
+ sub_clear_test(reporter, context, kRGBA_8888_GrPixelConfig);
+ sub_clear_test(reporter, context, kBGRA_8888_GrPixelConfig);
+ }
+
+ }
+}
+
+#endif
diff --git a/tests/VkUploadPixelsTests.cpp b/tests/VkUploadPixelsTests.cpp
new file mode 100644
index 0000000000..043ea45a81
--- /dev/null
+++ b/tests/VkUploadPixelsTests.cpp
@@ -0,0 +1,160 @@
+
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// This is a GPU-backend specific test. It relies on static intializers to work
+
+#include "SkTypes.h"
+
+#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_VULKAN)
+
+#include "GrContextFactory.h"
+#include "GrTest.h"
+#include "Test.h"
+#include "vk/GrVkGpu.h"
+
+
+void fill_pixel_data(int width, int height, GrColor* data) {
+
+ // build red-green gradient
+ for (int j = 0; j < height; ++j) {
+ for (int i = 0; i < width; ++i) {
+ unsigned int red = (unsigned int)(256.f*(i / (float)width));
+ unsigned int green = (unsigned int)(256.f*(j / (float)height));
+ data[i + j*width] = GrColorPackRGBA(red - (red>>8), green - (green>>8), 0xff, 0xff);
+ }
+ }
+}
+
+bool does_full_buffer_contain_correct_color(GrColor* srcBuffer,
+ GrColor* dstBuffer,
+ GrPixelConfig config,
+ int width,
+ int height) {
+ GrColor* srcPtr = srcBuffer;
+ GrColor* dstPtr = dstBuffer;
+ for (int j = 0; j < height; ++j) {
+ for (int i = 0; i < width; ++i) {
+ if (srcPtr[i] != dstPtr[i]) {
+ return false;
+ }
+ }
+ srcPtr += width;
+ dstPtr += width;
+ }
+ return true;
+}
+
+void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, GrPixelConfig config,
+ bool renderTarget, bool linearTiling) {
+ GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu());
+ gpu->discard(NULL);
+
+ const int kWidth = 16;
+ const int kHeight = 16;
+ SkAutoTMalloc<GrColor> srcBuffer(kWidth*kHeight);
+ SkAutoTMalloc<GrColor> dstBuffer(kWidth*kHeight);
+
+ fill_pixel_data(kWidth, kHeight, srcBuffer.get());
+
+ const GrVkCaps* caps = reinterpret_cast<const GrVkCaps*>(context->caps());
+
+ bool canCreate = true;
+ // the expectation is that the given config is texturable/renderable with optimal tiling
+ // but may not be with linear tiling
+ if (linearTiling) {
+ if (!caps->isConfigTexurableLinearly(config) ||
+ (renderTarget && !caps->isConfigRenderableLinearly(config, false))) {
+ canCreate = false;
+ }
+ }
+
+ GrSurfaceDesc surfDesc;
+ surfDesc.fFlags = renderTarget ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
+ if (linearTiling) {
+ surfDesc.fFlags |= kZeroCopy_GrSurfaceFlag;
+ }
+ surfDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ surfDesc.fWidth = kWidth;
+ surfDesc.fHeight = kHeight;
+ surfDesc.fConfig = config;
+ surfDesc.fSampleCnt = 0;
+ GrTexture* tex0 = gpu->createTexture(surfDesc, false, srcBuffer, 0);
+ if (tex0) {
+ REPORTER_ASSERT(reporter, canCreate);
+ gpu->readPixels(tex0, 0, 0, kWidth, kHeight, config, dstBuffer, 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
+ dstBuffer,
+ config,
+ kWidth,
+ kHeight));
+
+ tex0->writePixels(2, 10, 10, 2, config, srcBuffer);
+ memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
+ gpu->readPixels(tex0, 2, 10, 10, 2, config, dstBuffer, 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
+ dstBuffer,
+ config,
+ 10,
+ 2));
+
+ tex0->unref();
+ } else {
+ REPORTER_ASSERT(reporter, !canCreate);
+ }
+
+ surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
+ GrTexture* tex1 = gpu->createTexture(surfDesc, false, srcBuffer, 0);
+ if (tex1) {
+ REPORTER_ASSERT(reporter, canCreate);
+ gpu->readPixels(tex1, 0, 0, kWidth, kHeight, config, dstBuffer, 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
+ dstBuffer,
+ config,
+ kWidth,
+ kHeight));
+
+ tex1->writePixels(5, 4, 4, 5, config, srcBuffer);
+ memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
+ gpu->readPixels(tex1, 5, 4, 4, 5, config, dstBuffer, 0);
+ REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
+ dstBuffer,
+ config,
+ 4,
+ 5));
+
+ tex1->unref();
+ } else {
+ REPORTER_ASSERT(reporter, !canCreate);
+ }
+}
+
+DEF_GPUTEST(VkUploadPixelsTests, reporter, factory) {
+ GrContextOptions opts;
+ opts.fSuppressPrints = true;
+ GrContextFactory debugFactory(opts);
+ for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
+ if (static_cast<GrContextFactory::GLContextType>(type) !=
+ GrContextFactory::kNative_GLContextType) {
+ continue;
+ }
+ GrContext* context = debugFactory.get(static_cast<GrContextFactory::GLContextType>(type));
+ if (context) {
+ basic_texture_test(reporter, context, kRGBA_8888_GrPixelConfig, false, false);
+ basic_texture_test(reporter, context, kRGBA_8888_GrPixelConfig, true, false);
+ basic_texture_test(reporter, context, kRGBA_8888_GrPixelConfig, false, true);
+ basic_texture_test(reporter, context, kRGBA_8888_GrPixelConfig, true, true);
+ basic_texture_test(reporter, context, kBGRA_8888_GrPixelConfig, false, false);
+ basic_texture_test(reporter, context, kBGRA_8888_GrPixelConfig, true, false);
+ basic_texture_test(reporter, context, kBGRA_8888_GrPixelConfig, false, true);
+ basic_texture_test(reporter, context, kBGRA_8888_GrPixelConfig, true, true);
+ }
+
+ }
+}
+
+#endif