skia2/dm/DMGpuTestProcs.cpp

108 lines
4.0 KiB
C++
Raw Normal View History

/*
* Copyright 2017 Google Inc.
*
* 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 "include/gpu/GrDirectContext.h"
#ifdef SK_GRAPHITE_ENABLED
#include "include/gpu/graphite/Context.h"
#include "tools/graphite/ContextFactory.h"
#endif
using sk_gpu_test::GrContextFactory;
Revert "[fuzzer] Remove GL from (now-Vulkan) build" This reverts commit 805acda3f3aa3d9fc85c84bac5aa52c472ec3bb1. Reason for revert: Looks to be breaking the Android roll. See https://android-build.googleplex.com/builds/pending/P29733268/aosp_bramble-userdebug/latest/view/logs/build_error.log Original change's description: > [fuzzer] Remove GL from (now-Vulkan) build > > The fuzzer runs against the Vulkan version of Swiftshader. > There are no libGL.so (etc) on the fuzz runtime, so we > want to avoid linking against those. > > The GL code that is #ifdef'd out is still necessary to > avoid timeouts on TSAN with our NVIDIA jobs. > https://skia-review.googlesource.com/c/skia/+/502638 > > Procedure for testing this locally (and iterating): > 1. In oss-fuzz checkout, run > `python infra/helper.py shell skia` > to pull up local interactive version of Docker > fuzzer build image. > 2. Run `compile` in fuzzer shell. Stop after > the swiftshader compiles and is copied into /out > with Ctrl + C. > 3. Comment out the swiftshader compilation part [1] > (no need to re-do this when modifying Skia code). > `apt-get install nano -y` > `nano ../build.sh` > 4. Make change to Skia repo using normal methods. > 5. Run the following in the Skia repo > `git diff origin main > foo.patch` > Copy the patch into the Docker shell using Ctrl+C > and nano. > 6. Apply the patch inside the Docker shell > `git apply foo.patch` > and re-compile (which should skip right to > building the fuzzer libs) > `compile` > 7. Repeat 4-7 or make small changes directly in > the Docker shell via nano. > 8. When compilation and link succeeds, run > `ldd /out/api_mock_gpu_canvas` > to verify GL and friends were not dynamically linked. > > [1] https://github.com/google/oss-fuzz/pull/7214/files#diff-76f13875e33875cdd372f1f0933206be599cd87952f1bd1eaa57ca928ee9e3e1R49-R53 > > Change-Id: Idf569820527c1304b0e5a68fd36295be89dfa2a0 > Bug: oss-fuzz:44132 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/503016 > Reviewed-by: Brian Osman <brianosman@google.com> > Commit-Queue: Kevin Lubick <kjlubick@google.com> Bug: oss-fuzz:44132 Change-Id: I3832417c60ff425572717d37dc9609419922b18e No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/503351 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Brian Osman <brianosman@google.com>
2022-02-02 22:03:33 +00:00
using sk_gpu_test::ContextInfo;
[fuzzer] Remove GL from (now-Vulkan) build The fuzzer runs against the Vulkan version of Swiftshader. There are no libGL.so (etc) on the fuzz runtime, so we want to avoid linking against those. The GL code that is #ifdef'd out is still necessary to avoid timeouts on TSAN with our NVIDIA jobs. https://skia-review.googlesource.com/c/skia/+/502638 Procedure for testing this locally (and iterating): 1. In oss-fuzz checkout, run `python infra/helper.py shell skia` to pull up local interactive version of Docker fuzzer build image. 2. Run `compile` in fuzzer shell. Stop after the swiftshader compiles and is copied into /out with Ctrl + C. 3. Comment out the swiftshader compilation part [1] (no need to re-do this when modifying Skia code). `apt-get install nano -y` `nano ../build.sh` 4. Make change to Skia repo using normal methods. 5. Run the following in the Skia repo `git diff origin main > foo.patch` Copy the patch into the Docker shell using Ctrl+C and nano. 6. Apply the patch inside the Docker shell `git apply foo.patch` and re-compile (which should skip right to building the fuzzer libs) `compile` 7. Repeat 4-7 or make small changes directly in the Docker shell via nano. 8. When compilation and link succeeds, run `ldd /out/api_mock_gpu_canvas` to verify GL and friends were not dynamically linked. [1] https://github.com/google/oss-fuzz/pull/7214/files#diff-76f13875e33875cdd372f1f0933206be599cd87952f1bd1eaa57ca928ee9e3e1R49-R53 Change-Id: Idf569820527c1304b0e5a68fd36295be89dfa2a0 Bug: oss-fuzz:44132 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/503016 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-02-02 14:55:42 +00:00
Reland "[fuzzer] Remove GL from (now-Vulkan) build" This is a reland of 805acda3f3aa3d9fc85c84bac5aa52c472ec3bb1 It fixes the #if SK_GL which was causing the Android roll to fail. This disables unit tests on Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-TSAN_Vulkan which were consistently crashing with OOM. Original change's description: > [fuzzer] Remove GL from (now-Vulkan) build > > The fuzzer runs against the Vulkan version of Swiftshader. > There are no libGL.so (etc) on the fuzz runtime, so we > want to avoid linking against those. > > The GL code that is #ifdef'd out is still necessary to > avoid timeouts on TSAN with our NVIDIA jobs. > https://skia-review.googlesource.com/c/skia/+/502638 > > Procedure for testing this locally (and iterating): > 1. In oss-fuzz checkout, run > `python infra/helper.py shell skia` > to pull up local interactive version of Docker > fuzzer build image. > 2. Run `compile` in fuzzer shell. Stop after > the swiftshader compiles and is copied into /out > with Ctrl + C. > 3. Comment out the swiftshader compilation part [1] > (no need to re-do this when modifying Skia code). > `apt-get install nano -y` > `nano ../build.sh` > 4. Make change to Skia repo using normal methods. > 5. Run the following in the Skia repo > `git diff origin main > foo.patch` > Copy the patch into the Docker shell using Ctrl+C > and nano. > 6. Apply the patch inside the Docker shell > `git apply foo.patch` > and re-compile (which should skip right to > building the fuzzer libs) > `compile` > 7. Repeat 4-7 or make small changes directly in > the Docker shell via nano. > 8. When compilation and link succeeds, run > `ldd /out/api_mock_gpu_canvas` > to verify GL and friends were not dynamically linked. > > [1] https://github.com/google/oss-fuzz/pull/7214/files#diff-76f13875e33875cdd372f1f0933206be599cd87952f1bd1eaa57ca928ee9e3e1R49-R53 > > Change-Id: Idf569820527c1304b0e5a68fd36295be89dfa2a0 > Bug: oss-fuzz:44132 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/503016 > Reviewed-by: Brian Osman <brianosman@google.com> > Commit-Queue: Kevin Lubick <kjlubick@google.com> Bug: oss-fuzz:44132, skia:12900 Change-Id: Ia2eff9403b0035e7f86098f296d7d9b1bbfd4876 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/503716 Reviewed-by: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
2022-02-03 15:54:07 +00:00
#ifdef SK_GL
using sk_gpu_test::GLTestContext;
#endif
namespace skiatest {
bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
return GrBackendApi::kOpenGL == GrContextFactory::ContextTypeBackend(type);
}
bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
return GrBackendApi::kVulkan == GrContextFactory::ContextTypeBackend(type);
}
bool IsMetalContextType(sk_gpu_test::GrContextFactory::ContextType type) {
return GrBackendApi::kMetal == GrContextFactory::ContextTypeBackend(type);
}
bool IsDirect3DContextType(sk_gpu_test::GrContextFactory::ContextType type) {
return GrBackendApi::kDirect3D == GrContextFactory::ContextTypeBackend(type);
}
bool IsDawnContextType(sk_gpu_test::GrContextFactory::ContextType type) {
return GrBackendApi::kDawn == GrContextFactory::ContextTypeBackend(type);
}
bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
}
bool IsMockContextType(sk_gpu_test::GrContextFactory::ContextType type) {
return type == GrContextFactory::kMock_ContextType;
}
void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
Reporter* reporter, const GrContextOptions& options) {
#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
#else
static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
#endif
for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
// Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
// desktop since tests do not account for not fixing http://skbug.com/2809
if (contextType == GrContextFactory::kGL_ContextType ||
contextType == GrContextFactory::kGLES_ContextType) {
if (contextType != kNativeGLType) {
continue;
}
}
// We destroy the factory and its associated contexts after each test. This is due to the
// fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
// also tracks which of its contexts is current above that API and gets tripped up if the
// native windowing API is used directly outside of the command buffer code.
GrContextFactory factory(options);
ContextInfo ctxInfo = factory.getContextInfo(contextType);
if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
continue;
}
ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
if (ctxInfo.directContext()) {
(*test)(reporter, ctxInfo);
// In case the test changed the current context make sure we move it back before
// calling flush.
ctxInfo.testContext()->makeCurrent();
// Sync so any release/finished procs get called.
ctxInfo.directContext()->flushAndSubmit(/*sync*/true);
}
}
}
#ifdef SK_GRAPHITE_ENABLED
namespace graphite {
void RunWithGraphiteTestContexts(GraphiteTestFn* test, Reporter* reporter) {
ContextFactory factory;
auto [_, context] = factory.getContextInfo(ContextFactory::ContextType::kMetal);
if (!context) {
return;
}
(*test)(reporter, context);
}
} // namespace graphite
#endif // SK_GRAPHITE_ENABLED
} // namespace skiatest