Flutter Engine
The Flutter Engine
Functions
OpChainTest.cpp File Reference
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/base/SkTDArray.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/base/SkRandom.h"
#include "src/gpu/AtlasTypes.h"
#include "src/gpu/SkBackingFit.h"
#include "src/gpu/Swizzle.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrOpFlushState.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrRenderTargetProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "src/gpu/ganesh/GrTextureResolveManager.h"
#include "src/gpu/ganesh/ops/GrOp.h"
#include "src/gpu/ganesh/ops/OpsTask.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <utility>
#include <vector>

Go to the source code of this file.

Functions

 DEF_GANESH_TEST (OpChainTest, reporter,, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST()

DEF_GANESH_TEST ( OpChainTest  ,
reporter  ,
CtsEnforcement::kApiLevel_T   
)

Tests adding kNumOps to an op list with all possible allowed chaining configurations. Tests adding the ops in all possible orders and verifies that the chained executions don't violate painter's order.

Definition at line 209 of file OpChainTest.cpp.

209 {
211 SkASSERT(dContext);
212 const GrCaps* caps = dContext->priv().caps();
213 static constexpr SkISize kDims = {kNumOps + 1, 1};
214
217
218 static const GrSurfaceOrigin kOrigin = kTopLeft_GrSurfaceOrigin;
219 auto proxy = dContext->priv().proxyProvider()->createProxy(format,
220 kDims,
222 1,
227 /*label=*/"OpChainTest",
229 SkASSERT(proxy);
230 proxy->instantiate(dContext->priv().resourceProvider());
231
233
234 int result[result_width()];
235 int validResult[result_width()];
236
237 int permutation[kNumOps];
238 for (int i = 0; i < kNumOps; ++i) {
239 permutation[i] = i;
240 }
241 // Op order permutations.
242 static constexpr int kNumPermutations = 100;
243 // For a given number of chainability groups, this is the number of random combinability reuslts
244 // we will test.
245 static constexpr int kNumCombinabilitiesPerGrouping = 20;
246 SkRandom random;
247 bool repeat = false;
248 Combinable combinable;
249 GrDrawingManager* drawingMgr = dContext->priv().drawingManager();
250 sk_sp<GrArenas> arenas = sk_make_sp<GrArenas>();
251 for (int p = 0; p < kNumPermutations; ++p) {
252 for (int i = 0; i < kNumOps - 2 && !repeat; ++i) {
253 // The current implementation of nextULessThan() is biased. :(
254 unsigned j = i + random.nextULessThan(kNumOps - i);
255 std::swap(permutation[i], permutation[j]);
256 }
257 // g is the number of chainable groups that we partition the ops into.
258 for (int g = 1; g < kNumOps; ++g) {
259 for (int c = 0; c < kNumCombinabilitiesPerGrouping; ++c) {
260 init_combinable(g, &combinable, &random);
261 skgpu::TokenTracker tracker;
262 GrOpFlushState flushState(dContext->priv().getGpu(),
263 dContext->priv().resourceProvider(),
264 &tracker);
265 skgpu::ganesh::OpsTask opsTask(drawingMgr,
266 GrSurfaceProxyView(proxy, kOrigin, writeSwizzle),
267 dContext->priv().auditTrail(),
268 arenas);
269 // This assumes the particular values of kRanges.
270 std::fill_n(result, result_width(), -1);
271 std::fill_n(validResult, result_width(), -1);
272 for (int i = 0; i < kNumOps; ++i) {
273 int value = permutation[i];
274 // factor out the repeats and then use the canonical starting position and range
275 // to determine an actual range.
276 int j = value % (kNumRanges * kNumOpPositions);
277 int pos = j % kNumOpPositions;
278 Range range = kRanges[j / kNumOpPositions];
279 range.fOffset += pos;
280 auto op = TestOp::Make(dContext.get(), value, range, result, &combinable);
281 TestOp* testOp = (TestOp*)op.get();
282 testOp->writeResult(validResult);
283 opsTask.addOp(drawingMgr, std::move(op),
285 *caps);
286 }
287 opsTask.makeClosed(dContext.get());
288 opsTask.prepare(&flushState);
289 opsTask.execute(&flushState);
290 opsTask.endFlush(drawingMgr);
291 opsTask.disown(drawingMgr);
292#if 0 // Useful to repeat a random configuration that fails the test while debugger attached.
293 if (!std::equal(result, result + result_width(), validResult)) {
294 repeat = true;
295 }
296#endif
297 (void)repeat;
298 REPORTER_ASSERT(reporter, std::equal(result, result + result_width(), validResult));
299 }
300 }
301 }
302}
reporter
Definition: FontMgrTest.cpp:39
GrSurfaceOrigin
Definition: GrTypes.h:147
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
SkPoint pos
static bool equal(const SkBitmap &a, const SkBitmap &b)
Definition: ImageTest.cpp:1395
#define SkASSERT(cond)
Definition: SkAssert.h:116
static unsigned repeat(SkFixed fx, int max)
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
const GrCaps * caps() const
Definition: GrCaps.h:57
virtual skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &, GrColorType) const =0
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
GrResourceProvider * resourceProvider()
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)
GrDirectContextPriv priv()
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
GrDrawingManager * drawingManager()
GrProxyProvider * proxyProvider()
uint32_t nextULessThan(uint32_t count)
Definition: SkRandom.h:93
T * get() const
Definition: SkRefCnt.h:303
uint8_t value
GAsyncResult * result
uint32_t uint32_t * format
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
Definition: SkSize.h:16