Skip to content

Commit 009c7b3

Browse files
committed
Use the backend test cleanup helper more extensively
BUGS=[408310509]
1 parent 86a500c commit 009c7b3

13 files changed

+372
-400
lines changed

filament/backend/test/test_Blit.cpp

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

146146
TEST_F(BlitTest, ColorMagnify) {
147147
auto& api = getDriverApi();
148-
mCleanup.addPostCall([&]() { executeCommands(); });
149148

150149
constexpr int kSrcTexWidth = 256;
151150
constexpr int kSrcTexHeight = 256;
@@ -207,7 +206,6 @@ TEST_F(BlitTest, ColorMagnify) {
207206

208207
TEST_F(BlitTest, ColorMinify) {
209208
auto& api = getDriverApi();
210-
mCleanup.addPostCall([&]() { executeCommands(); });
211209

212210
constexpr int kSrcTexWidth = 1024;
213211
constexpr int kSrcTexHeight = 1024;
@@ -346,7 +344,6 @@ TEST_F(BlitTest, ColorResolve) {
346344

347345
TEST_F(BlitTest, Blit2DTextureArray) {
348346
auto& api = getDriverApi();
349-
mCleanup.addPostCall([&]() { executeCommands(); });
350347

351348
api.startCapture(0);
352349
mCleanup.addPostCall([&]() { api.stopCapture(0); });
@@ -416,7 +413,6 @@ TEST_F(BlitTest, Blit2DTextureArray) {
416413

417414
TEST_F(BlitTest, BlitRegion) {
418415
auto& api = getDriverApi();
419-
mCleanup.addPostCall([&]() { executeCommands(); });
420416

421417
constexpr int kSrcTexWidth = 1024;
422418
constexpr int kSrcTexHeight = 1024;
@@ -492,7 +488,6 @@ TEST_F(BlitTest, BlitRegion) {
492488
TEST_F(BlitTest, BlitRegionToSwapChain) {
493489
FAIL_IF(Backend::VULKAN, "Crashes due to not finding color attachment");
494490
auto& api = getDriverApi();
495-
mCleanup.addPostCall([&]() { executeCommands(); });
496491

497492
constexpr int kSrcTexWidth = 1024;
498493
constexpr int kSrcTexHeight = 1024;
@@ -545,13 +540,13 @@ TEST_F(BlitTest, BlitRegionToSwapChain) {
545540
dstRect, srcRenderTargets[srcLevel],
546541
srcRect, SamplerMagFilter::LINEAR);
547542

548-
api.commit(swapChain);
549-
}
543+
api.commit(swapChain);
550544

551-
// TODO: for some reason, this test has been disabled. It needs to be tested on all
552-
// machines.
553-
// EXPECT_IMAGE(dstRenderTarget, expectations,
554-
// ScreenshotParams(kDstTexWidth, kDstTexHeight, "BlitRegionToSwapChain", 0x0));
545+
// TODO: for some reason, this test has been disabled. It needs to be tested on all
546+
// machines.
547+
// EXPECT_IMAGE(dstRenderTarget, expectations,
548+
// ScreenshotParams(kDstTexWidth, kDstTexHeight, "BlitRegionToSwapChain", 0x0));
549+
}
555550
}
556551

557552
} // namespace test

filament/backend/test/test_BufferUpdates.cpp

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

101101
api.startCapture(0);
102+
cleanup.addPostCall([&]() { api.stopCapture(0); });
102103

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

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

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

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

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

153-
api.stopCapture(0);
151+
api.flush();
152+
api.commit(swapChain);
153+
}
154154
}
155-
156-
executeCommands();
157155
}
158156

159157
// This test renders two triangles in two separate draw calls. Between the draw calls, a uniform
@@ -226,15 +224,13 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
226224
ScreenshotParams(512, 512, "BufferObjectUpdateWithOffset", 91322442));
227225

228226
api.flush();
229-
api.commit(swapChain);
230-
api.endFrame(0);
227+
{
228+
RenderFrame frame(api);
229+
api.commit(swapChain);
230+
}
231231

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

240236
} // 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(Backend::OPENGL, "Frame callbacks are unsupported in 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(Backend::OPENGL, "Frame callbacks are unsupported in 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)