Skip to content

Commit 3ce9374

Browse files
committed
Use the backend test cleanup helper more extensively
BUGS=[408310509]
1 parent a42bfcc commit 3ce9374

13 files changed

+379
-425
lines changed

filament/backend/test/test_Blit.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ static void createFaces(DriverApi& dapi, Handle<HwTexture> texture, int baseWidt
144144

145145
TEST_F(BlitTest, ColorMagnify) {
146146
auto& api = getDriverApi();
147-
mCleanup.addPostCall([&]() { executeCommands(); });
148147

149148
constexpr int kSrcTexWidth = 256;
150149
constexpr int kSrcTexHeight = 256;
@@ -205,14 +204,11 @@ TEST_F(BlitTest, ColorMagnify) {
205204
ScreenshotParams(kDstTexWidth, kDstTexHeight, "ColorMagnify", 0x410bdd31));
206205
api.commit(swapChain);
207206
}
208-
209-
flushAndWait();
210207
}
211208
}
212209

213210
TEST_F(BlitTest, ColorMinify) {
214211
auto& api = getDriverApi();
215-
mCleanup.addPostCall([&]() { executeCommands(); });
216212

217213
constexpr int kSrcTexWidth = 1024;
218214
constexpr int kSrcTexHeight = 1024;
@@ -266,7 +262,6 @@ TEST_F(BlitTest, ColorMinify) {
266262
EXPECT_IMAGE(dstRenderTargets[0], expectations,
267263
ScreenshotParams(kDstTexWidth, kDstTexHeight, "ColorMinify", 0xf3d9c53f));
268264

269-
flushAndWait();
270265
}
271266
}
272267

@@ -357,13 +352,11 @@ TEST_F(BlitTest, ColorResolve) {
357352
EXPECT_IMAGE(dstRenderTarget, expectations,
358353
ScreenshotParams(kDstTexWidth, kDstTexHeight, "ColorResolve", 0xebfac2ef));
359354

360-
flushAndWait();
361355
}
362356
}
363357

364358
TEST_F(BlitTest, Blit2DTextureArray) {
365359
auto& api = getDriverApi();
366-
mCleanup.addPostCall([&]() { executeCommands(); });
367360

368361
api.startCapture(0);
369362
mCleanup.addPostCall([&]() { api.stopCapture(0); });
@@ -432,14 +425,11 @@ TEST_F(BlitTest, Blit2DTextureArray) {
432425
0x8de7d55b));
433426
api.commit(swapChain);
434427
}
435-
436-
flushAndWait();
437428
}
438429
}
439430

440431
TEST_F(BlitTest, BlitRegion) {
441432
auto& api = getDriverApi();
442-
mCleanup.addPostCall([&]() { executeCommands(); });
443433

444434
constexpr int kSrcTexWidth = 1024;
445435
constexpr int kSrcTexHeight = 1024;
@@ -513,14 +503,11 @@ TEST_F(BlitTest, BlitRegion) {
513503
// kDstTexHeight, "BlitRegion", 0x74fa34ed));
514504
api.commit(swapChain);
515505
}
516-
517-
flushAndWait();
518506
}
519507
}
520508

521509
TEST_F(BlitTest, BlitRegionToSwapChain) {
522510
auto& api = getDriverApi();
523-
mCleanup.addPostCall([&]() { executeCommands(); });
524511

525512
constexpr int kSrcTexWidth = 1024;
526513
constexpr int kSrcTexHeight = 1024;
@@ -584,7 +571,6 @@ TEST_F(BlitTest, BlitRegionToSwapChain) {
584571
// EXPECT_IMAGE(dstRenderTarget, expectations,
585572
// ScreenshotParams(kDstTexWidth, kDstTexHeight, "BlitRegionToSwapChain", 0x0));
586573
}
587-
flushAndWait();
588574
}
589575
}
590576

filament/backend/test/test_BufferUpdates.cpp

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
147147
shader.bindUniform<SimpleMaterialParams>(api, ubuffer, kBindingConfig);
148148

149149
api.startCapture(0);
150+
cleanup.addPostCall([&]() { api.stopCapture(0); });
150151

151152
// Upload the uniform, but with an offset to accommodate the padding in the shader's
152153
// uniform definition.
@@ -157,51 +158,48 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
157158
});
158159

159160
api.makeCurrent(swapChain, swapChain);
160-
api.beginFrame(0, 0, 0);
161-
162-
// Draw 10 triangles, updating the vertex buffer / index buffer each time.
163-
size_t triangleIndex = 0;
164-
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
165-
const float low = i, high = i + 0.2;
166-
const filament::math::float2 v[3]{{ low, low },
167-
{ high, low },
168-
{ low, high }};
169-
triangle.updateVertices(v);
170-
171-
if (updateIndices) {
172-
if (triangleIndex % 2 == 0) {
173-
// Upload each index separately, to test offsets.
174-
const TrianglePrimitive::index_type i[3]{ 0, 1, 2 };
175-
triangle.updateIndices(i + 0, 1, 0);
176-
triangle.updateIndices(i + 1, 1, 1);
177-
triangle.updateIndices(i + 2, 1, 2);
178-
} else {
179-
// This effectively hides this triangle.
180-
const TrianglePrimitive::index_type i[3]{ 0, 0, 0 };
181-
triangle.updateIndices(i);
161+
{
162+
RenderFrame frame(api);
163+
164+
// Draw 10 triangles, updating the vertex buffer / index buffer each time.
165+
size_t triangleIndex = 0;
166+
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
167+
const float low = i, high = i + 0.2;
168+
const filament::math::float2 v[3]{{ low, low },
169+
{ high, low },
170+
{ low, high }};
171+
triangle.updateVertices(v);
172+
173+
if (updateIndices) {
174+
if (triangleIndex % 2 == 0) {
175+
// Upload each index separately, to test offsets.
176+
const TrianglePrimitive::index_type i[3]{ 0, 1, 2 };
177+
triangle.updateIndices(i + 0, 1, 0);
178+
triangle.updateIndices(i + 1, 1, 1);
179+
triangle.updateIndices(i + 2, 1, 2);
180+
} else {
181+
// This effectively hides this triangle.
182+
const TrianglePrimitive::index_type i[3]{ 0, 0, 0 };
183+
triangle.updateIndices(i);
184+
}
182185
}
183-
}
184186

185-
if (triangleIndex > 0) {
186-
params.flags.clear = TargetBufferFlags::NONE;
187-
params.flags.discardStart = TargetBufferFlags::NONE;
188-
}
187+
if (triangleIndex > 0) {
188+
params.flags.clear = TargetBufferFlags::NONE;
189+
params.flags.discardStart = TargetBufferFlags::NONE;
190+
}
189191

190-
api.beginRenderPass(defaultRenderTarget, params);
191-
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
192-
api.endRenderPass();
192+
api.beginRenderPass(defaultRenderTarget, params);
193+
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
194+
api.endRenderPass();
193195

194-
triangleIndex++;
195-
}
196-
197-
api.flush();
198-
api.commit(swapChain);
199-
api.endFrame(0);
196+
triangleIndex++;
197+
}
200198

201-
api.stopCapture(0);
199+
api.flush();
200+
api.commit(swapChain);
201+
}
202202
}
203-
204-
executeCommands();
205203
}
206204

207205
// This test renders two triangles in two separate draw calls. Between the draw calls, a uniform
@@ -275,15 +273,13 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
275273
"BufferObjectUpdateWithOffset", 512, 512, renderTarget, expectedHash, true);
276274

277275
api.flush();
278-
api.commit(swapChain);
279-
api.endFrame(0);
276+
{
277+
RenderFrame frame(api);
278+
api.commit(swapChain);
279+
}
280280

281281
// This ensures all driver commands have finished before exiting the test.
282282
api.finish();
283-
284-
executeCommands();
285-
286-
getDriver().purge();
287283
}
288284

289285
} // namespace test

filament/backend/test/test_Callbacks.cpp

Lines changed: 92 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -24,100 +24,107 @@ using namespace filament::backend;
2424
namespace test {
2525

2626
TEST_F(BackendTest, FrameScheduledCallback) {
27-
auto& api = getDriverApi();
28-
Cleanup cleanup(api);
29-
30-
// Create a SwapChain.
31-
// In order for the frameScheduledCallback to be called, this must be a real SwapChain (not
32-
// headless) so we obtain a drawable.
33-
auto swapChain = cleanup.add(createSwapChain());
34-
35-
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createDefaultRenderTarget());
36-
3727
int callbackCountA = 0;
38-
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountA](PresentCallable callable) {
39-
callable();
40-
callbackCountA++;
41-
}, 0);
42-
43-
// Render the first frame.
44-
api.makeCurrent(swapChain, swapChain);
45-
api.beginFrame(0, 0, 0);
46-
api.beginRenderPass(renderTarget, {});
47-
api.endRenderPass(0);
48-
api.commit(swapChain);
49-
api.endFrame(0);
50-
51-
// Render the next frame. The same callback should be called.
52-
api.makeCurrent(swapChain, swapChain);
53-
api.beginFrame(0, 0, 0);
54-
api.beginRenderPass(renderTarget, {});
55-
api.endRenderPass(0);
56-
api.commit(swapChain);
57-
api.endFrame(0);
58-
59-
// Now switch out the callback.
6028
int callbackCountB = 0;
61-
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountB](PresentCallable callable) {
62-
callable();
63-
callbackCountB++;
64-
}, 0);
65-
66-
// Render one final frame.
67-
api.makeCurrent(swapChain, swapChain);
68-
api.beginFrame(0, 0, 0);
69-
api.beginRenderPass(renderTarget, {});
70-
api.endRenderPass(0);
71-
api.commit(swapChain);
72-
api.endFrame(0);
73-
74-
api.finish();
75-
76-
executeCommands();
77-
getDriver().purge();
78-
29+
{
30+
auto& api = getDriverApi();
31+
Cleanup cleanup(api);
32+
cleanup.addPostCall([&]() { executeCommands(); });
33+
cleanup.addPostCall([&]() { getDriver().purge(); });
34+
35+
// Create a SwapChain.
36+
// In order for the frameScheduledCallback to be called, this must be a real SwapChain (not
37+
// headless) so we obtain a drawable.
38+
auto swapChain = cleanup.add(createSwapChain());
39+
40+
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createDefaultRenderTarget());
41+
42+
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountA](PresentCallable callable) {
43+
callable();
44+
callbackCountA++;
45+
}, 0);
46+
47+
// Render the first frame.
48+
api.makeCurrent(swapChain, swapChain);
49+
{
50+
RenderFrame frame(api);
51+
api.beginRenderPass(renderTarget, {});
52+
api.endRenderPass(0);
53+
api.commit(swapChain);
54+
}
55+
56+
// Render the next frame. The same callback should be called.
57+
api.makeCurrent(swapChain, swapChain);
58+
{
59+
RenderFrame frame(api);
60+
api.beginRenderPass(renderTarget, {});
61+
api.endRenderPass(0);
62+
api.commit(swapChain);
63+
}
64+
65+
// Now switch out the callback.
66+
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountB](PresentCallable callable) {
67+
callable();
68+
callbackCountB++;
69+
}, 0);
70+
71+
// Render one final frame.
72+
api.makeCurrent(swapChain, swapChain);
73+
{
74+
RenderFrame frame(api);
75+
api.beginRenderPass(renderTarget, {});
76+
api.endRenderPass(0);
77+
api.commit(swapChain);
78+
}
79+
80+
api.finish();
81+
}
7982
EXPECT_EQ(callbackCountA, 2);
8083
EXPECT_EQ(callbackCountB, 1);
8184
}
8285

8386
TEST_F(BackendTest, FrameCompletedCallback) {
84-
auto& api = getDriverApi();
85-
Cleanup cleanup(api);
86-
87-
// Create a SwapChain.
88-
auto swapChain = cleanup.add(api.createSwapChainHeadless(256, 256, 0));
89-
9087
int callbackCountA = 0;
91-
api.setFrameCompletedCallback(swapChain, nullptr,
92-
[&callbackCountA]() { callbackCountA++; });
93-
94-
// Render the first frame.
95-
api.makeCurrent(swapChain, swapChain);
96-
api.beginFrame(0, 0, 0);
97-
api.commit(swapChain);
98-
api.endFrame(0);
99-
100-
// Render the next frame. The same callback should be called.
101-
api.makeCurrent(swapChain, swapChain);
102-
api.beginFrame(0, 0, 0);
103-
api.commit(swapChain);
104-
api.endFrame(0);
105-
106-
// Now switch out the callback.
10788
int callbackCountB = 0;
108-
api.setFrameCompletedCallback(swapChain, nullptr,
109-
[&callbackCountB]() { callbackCountB++; });
110-
111-
// Render one final frame.
112-
api.makeCurrent(swapChain, swapChain);
113-
api.beginFrame(0, 0, 0);
114-
api.commit(swapChain);
115-
api.endFrame(0);
116-
117-
api.finish();
118-
119-
executeCommands();
120-
getDriver().purge();
89+
{
90+
auto& api = getDriverApi();
91+
Cleanup cleanup(api);
92+
cleanup.addPostCall([&]() { executeCommands(); });
93+
cleanup.addPostCall([&]() { getDriver().purge(); });
94+
95+
// Create a SwapChain.
96+
auto swapChain = cleanup.add(api.createSwapChainHeadless(256, 256, 0));
97+
98+
api.setFrameCompletedCallback(swapChain, nullptr,
99+
[&callbackCountA]() { callbackCountA++; });
100+
101+
// Render the first frame.
102+
api.makeCurrent(swapChain, swapChain);
103+
{
104+
RenderFrame frame(api);
105+
api.commit(swapChain);
106+
}
107+
108+
// Render the next frame. The same callback should be called.
109+
api.makeCurrent(swapChain, swapChain);
110+
{
111+
RenderFrame frame(api);
112+
api.commit(swapChain);
113+
}
114+
115+
// Now switch out the callback.
116+
api.setFrameCompletedCallback(swapChain, nullptr,
117+
[&callbackCountB]() { callbackCountB++; });
118+
119+
// Render one final frame.
120+
api.makeCurrent(swapChain, swapChain);
121+
{
122+
RenderFrame frame(api);
123+
api.commit(swapChain);
124+
}
125+
126+
api.finish();
127+
}
121128

122129
EXPECT_EQ(callbackCountA, 2);
123130
EXPECT_EQ(callbackCountB, 1);

0 commit comments

Comments
 (0)