skia2/tests/graphite/CommandBufferTest.cpp
Jim Van Verth c7fa96c4e5 [graphite] Fix non-Metal compile error
Bug: skia:12466
Change-Id: I2e0421191d05c3e0f457425e0dab49c2afb9c2b9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/461477
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Auto-Submit: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Chris Dalton <csmartdalton@google.com>
2021-10-20 14:57:00 +00:00

74 lines
2.3 KiB
C++

/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tests/Test.h"
#include "experimental/graphite/include/Context.h"
#include "experimental/graphite/src/ContextPriv.h"
#include "experimental/graphite/include/mtl/MtlTypes.h"
#include "experimental/graphite/src/CommandBuffer.h"
#include "experimental/graphite/src/Gpu.h"
#include "experimental/graphite/src/RenderPipeline.h"
#include "experimental/graphite/src/ResourceProvider.h"
#include "experimental/graphite/src/Texture.h"
#if GRAPHITE_TEST_UTILS
// set to 1 if you want to do GPU capture of the commandBuffer
#define CAPTURE_COMMANDBUFFER 0
#endif
using namespace skgpu;
/*
* This is to test the various pieces of the CommandBuffer interface.
*/
DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) {
auto gpu = context->priv().gpu();
REPORTER_ASSERT(reporter, gpu);
#if GRAPHITE_TEST_UTILS && CAPTURE_COMMANDBUFFER
gpu->testingOnly_startCapture();
#endif
auto commandBuffer = gpu->resourceProvider()->createCommandBuffer();
SkISize textureSize = { 1024, 768 };
TextureInfo textureInfo;
#ifdef SK_METAL
skgpu::mtl::TextureInfo mtlTextureInfo = {
1,
1,
70, // MTLPixelFormatRGBA8Unorm
0x0005, // MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead
2, // MTLStorageModePrivate
};
textureInfo = TextureInfo(mtlTextureInfo);
#endif
sk_sp<Texture> texture = gpu->resourceProvider()->findOrCreateTexture(textureSize,
textureInfo);
RenderPassDesc renderPassDesc = {};
renderPassDesc.fColorAttachment.fTexture = std::move(texture);
renderPassDesc.fColorAttachment.fLoadOp = LoadOp::kClear;
renderPassDesc.fColorAttachment.fStoreOp = StoreOp::kStore;
renderPassDesc.fClearColor = { 1, 0, 0, 1 };
commandBuffer->beginRenderPass(renderPassDesc);
// add test commands here
commandBuffer->endRenderPass();
bool result = gpu->submit(commandBuffer);
REPORTER_ASSERT(reporter, result);
gpu->checkForFinishedWork(skgpu::SyncToCpu::kYes);
#if GRAPHITE_TEST_UTILS && CAPTURE_COMMANDBUFFER
gpu->testingOnly_endCapture();
#endif
}