Flutter Engine
The Flutter Engine
BufferManagerTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "tests/Test.h"
9
19
20namespace skgpu::graphite {
21namespace {
22
23static bool is_offset_aligned(size_t offset, size_t alignment) {
24 return 0 == (offset & (alignment - 1));
25}
26
27} // namespace
28
29DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(BufferManagerGpuOnlyBufferTest, reporter, context,
31 std::unique_ptr<Recorder> recorder = context->makeRecorder();
32 DrawBufferManager* mgr = recorder->priv().drawBufferManager();
33
34 // Allocate a series of GPU-only buffers. These buffers should not be mapped before and after
35 // they get transferred to the recording.
36 auto ssbo = mgr->getStorage(10);
37 auto vertex = mgr->getVertexStorage(10);
38 auto index = mgr->getIndexStorage(10);
39 auto indirect = mgr->getIndirectStorage(10);
40
41 REPORTER_ASSERT(reporter, !ssbo.fBuffer->isMapped());
42 REPORTER_ASSERT(reporter, !vertex.fBuffer->isMapped());
43 REPORTER_ASSERT(reporter, !index.fBuffer->isMapped());
44 REPORTER_ASSERT(reporter, !indirect.fBuffer->isMapped());
45
46 // Ensure that the buffers' starting alignment matches the required storage buffer alignment.
47 size_t requiredAlignment = context->priv().caps()->requiredStorageBufferAlignment();
48 REPORTER_ASSERT(reporter, is_offset_aligned(ssbo.fOffset, requiredAlignment));
49 REPORTER_ASSERT(reporter, is_offset_aligned(vertex.fOffset, requiredAlignment));
50 REPORTER_ASSERT(reporter, is_offset_aligned(index.fOffset, requiredAlignment));
51 REPORTER_ASSERT(reporter, is_offset_aligned(indirect.fOffset, requiredAlignment));
52
53 // Transfers the ownership of used buffers to a Recording.
54 auto recording = recorder->snap();
55
56 // Ensure that the buffers are still unmapped.
57 REPORTER_ASSERT(reporter, !ssbo.fBuffer->isMapped());
58 REPORTER_ASSERT(reporter, !vertex.fBuffer->isMapped());
59 REPORTER_ASSERT(reporter, !index.fBuffer->isMapped());
60 REPORTER_ASSERT(reporter, !indirect.fBuffer->isMapped());
61
62 // Since these buffers never need their contents to be host-visible, no buffer transfer/copy
63 // tasks should have been created for them.
64 REPORTER_ASSERT(reporter, !recording->priv().hasTasks());
65
66 // Request a mapped ssbo followed by an unmapped one. The two buffers should be distinct.
67 auto [ssboPtr, mappedSsbo] = mgr->getStoragePointer(10);
68 ssbo = mgr->getStorage(10);
69 REPORTER_ASSERT(reporter, !ssbo.fBuffer->isMapped());
70 REPORTER_ASSERT(reporter, ssbo.fBuffer != mappedSsbo.fBuffer);
71}
72
73} // namespace skgpu::graphite
reporter
Definition: FontMgrTest.cpp:39
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
BindBufferInfo getIndexStorage(size_t requiredBytes)
std::pair< void *, BindBufferInfo > getStoragePointer(size_t requiredBytes)
BindBufferInfo getStorage(size_t requiredBytes, ClearBuffer cleared=ClearBuffer::kNo)
BindBufferInfo getIndirectStorage(size_t requiredBytes, ClearBuffer cleared=ClearBuffer::kNo)
BindBufferInfo getVertexStorage(size_t requiredBytes)
DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(BufferManagerGpuOnlyBufferTest, reporter, context, CtsEnforcement::kNextRelease)
SeparatedVector2 offset