Skip to content

Commit debd39b

Browse files
committed
Use the backend test cleanup helper more extensively
BUGS=[408310509]
1 parent 21dd131 commit debd39b

13 files changed

+380
-426
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
@@ -98,6 +98,7 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
9898
shader.bindUniform<SimpleMaterialParams>(api, ubuffer, kBindingConfig);
9999

100100
api.startCapture(0);
101+
cleanup.addPostCall([&]() { api.stopCapture(0); });
101102

102103
// Upload the uniform, but with an offset to accommodate the padding in the shader's
103104
// uniform definition.
@@ -108,51 +109,48 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
108109
});
109110

110111
api.makeCurrent(swapChain, swapChain);
111-
api.beginFrame(0, 0, 0);
112-
113-
// Draw 10 triangles, updating the vertex buffer / index buffer each time.
114-
size_t triangleIndex = 0;
115-
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
116-
const float low = i, high = i + 0.2;
117-
const filament::math::float2 v[3]{{ low, low },
118-
{ high, low },
119-
{ low, high }};
120-
triangle.updateVertices(v);
121-
122-
if (updateIndices) {
123-
if (triangleIndex % 2 == 0) {
124-
// Upload each index separately, to test offsets.
125-
const TrianglePrimitive::index_type i[3]{ 0, 1, 2 };
126-
triangle.updateIndices(i + 0, 1, 0);
127-
triangle.updateIndices(i + 1, 1, 1);
128-
triangle.updateIndices(i + 2, 1, 2);
129-
} else {
130-
// This effectively hides this triangle.
131-
const TrianglePrimitive::index_type i[3]{ 0, 0, 0 };
132-
triangle.updateIndices(i);
112+
{
113+
RenderFrame frame(api);
114+
115+
// Draw 10 triangles, updating the vertex buffer / index buffer each time.
116+
size_t triangleIndex = 0;
117+
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
118+
const float low = i, high = i + 0.2;
119+
const filament::math::float2 v[3]{{ low, low },
120+
{ high, low },
121+
{ low, high }};
122+
triangle.updateVertices(v);
123+
124+
if (updateIndices) {
125+
if (triangleIndex % 2 == 0) {
126+
// Upload each index separately, to test offsets.
127+
const TrianglePrimitive::index_type i[3]{ 0, 1, 2 };
128+
triangle.updateIndices(i + 0, 1, 0);
129+
triangle.updateIndices(i + 1, 1, 1);
130+
triangle.updateIndices(i + 2, 1, 2);
131+
} else {
132+
// This effectively hides this triangle.
133+
const TrianglePrimitive::index_type i[3]{ 0, 0, 0 };
134+
triangle.updateIndices(i);
135+
}
133136
}
134-
}
135137

136-
if (triangleIndex > 0) {
137-
params.flags.clear = TargetBufferFlags::NONE;
138-
params.flags.discardStart = TargetBufferFlags::NONE;
139-
}
138+
if (triangleIndex > 0) {
139+
params.flags.clear = TargetBufferFlags::NONE;
140+
params.flags.discardStart = TargetBufferFlags::NONE;
141+
}
140142

141-
api.beginRenderPass(defaultRenderTarget, params);
142-
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
143-
api.endRenderPass();
143+
api.beginRenderPass(defaultRenderTarget, params);
144+
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
145+
api.endRenderPass();
144146

145-
triangleIndex++;
146-
}
147-
148-
api.flush();
149-
api.commit(swapChain);
150-
api.endFrame(0);
147+
triangleIndex++;
148+
}
151149

152-
api.stopCapture(0);
150+
api.flush();
151+
api.commit(swapChain);
152+
}
153153
}
154-
155-
executeCommands();
156154
}
157155

158156
// This test renders two triangles in two separate draw calls. Between the draw calls, a uniform
@@ -225,15 +223,13 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
225223
"BufferObjectUpdateWithOffset", 512, 512, renderTarget, expectedHash, true);
226224

227225
api.flush();
228-
api.commit(swapChain);
229-
api.endFrame(0);
226+
{
227+
RenderFrame frame(api);
228+
api.commit(swapChain);
229+
}
230230

231231
// This ensures all driver commands have finished before exiting the test.
232232
api.finish();
233-
234-
executeCommands();
235-
236-
getDriver().purge();
237233
}
238234

239235
} // namespace test

filament/backend/test/test_Callbacks.cpp

Lines changed: 92 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -27,102 +27,109 @@ namespace test {
2727
TEST_F(BackendTest, FrameScheduledCallback) {
2828
SKIP_IF(SkipEnvironment(OperatingSystem::APPLE, Backend::OPENGL));
2929

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

8689
TEST_F(BackendTest, FrameCompletedCallback) {
8790
SKIP_IF(SkipEnvironment(OperatingSystem::APPLE, Backend::OPENGL));
8891

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

127134
EXPECT_EQ(callbackCountA, 2);
128135
EXPECT_EQ(callbackCountB, 1);

0 commit comments

Comments
 (0)