Skip to content

Commit b7cfd7e

Browse files
committed
Use the backend test cleanup helper more extensively
BUGS=[408310509]
1 parent 169c8d5 commit b7cfd7e

13 files changed

+460
-448
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;
@@ -342,7 +340,6 @@ TEST_F(BlitTest, ColorResolve) {
342340

343341
TEST_F(BlitTest, Blit2DTextureArray) {
344342
auto& api = getDriverApi();
345-
mCleanup.addPostCall([&]() { executeCommands(); });
346343

347344
api.startCapture(0);
348345
mCleanup.addPostCall([&]() { api.stopCapture(0); });
@@ -412,7 +409,6 @@ TEST_F(BlitTest, Blit2DTextureArray) {
412409

413410
TEST_F(BlitTest, BlitRegion) {
414411
auto& api = getDriverApi();
415-
mCleanup.addPostCall([&]() { executeCommands(); });
416412

417413
constexpr int kSrcTexWidth = 1024;
418414
constexpr int kSrcTexHeight = 1024;
@@ -488,7 +484,6 @@ TEST_F(BlitTest, BlitRegion) {
488484
TEST_F(BlitTest, BlitRegionToSwapChain) {
489485
FAIL_IF(Backend::VULKAN, "Crashes due to not finding color attachment, see b/417481493");
490486
auto& api = getDriverApi();
491-
mCleanup.addPostCall([&]() { executeCommands(); });
492487

493488
constexpr int kSrcTexWidth = 1024;
494489
constexpr int kSrcTexHeight = 1024;
@@ -541,13 +536,13 @@ TEST_F(BlitTest, BlitRegionToSwapChain) {
541536
dstRect, srcRenderTargets[srcLevel],
542537
srcRect, SamplerMagFilter::LINEAR);
543538

544-
api.commit(swapChain);
545-
}
539+
api.commit(swapChain);
546540

547-
// TODO: for some reason, this test has been disabled. It needs to be tested on all
548-
// machines.
549-
// EXPECT_IMAGE(dstRenderTarget, expectations,
550-
// ScreenshotParams(kDstTexWidth, kDstTexHeight, "BlitRegionToSwapChain", 0x0));
541+
// TODO: for some reason, this test has been disabled. It needs to be tested on all
542+
// machines.
543+
// EXPECT_IMAGE(dstRenderTarget, expectations,
544+
// ScreenshotParams(kDstTexWidth, kDstTexHeight, "BlitRegionToSwapChain", 0x0));
545+
}
551546
}
552547

553548
} // namespace test

filament/backend/test/test_BufferUpdates.cpp

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
9191
shader.bindUniform<SimpleMaterialParams>(api, ubuffer, kBindingConfig);
9292

9393
api.startCapture(0);
94+
cleanup.addPostCall([&]() { api.stopCapture(0); });
9495

9596
// Upload the uniform, but with an offset to accommodate the padding in the shader's
9697
// uniform definition.
@@ -101,29 +102,42 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
101102
});
102103

103104
api.makeCurrent(swapChain, swapChain);
104-
api.beginFrame(0, 0, 0);
105-
106-
// Draw 10 triangles, updating the vertex buffer / index buffer each time.
107-
size_t triangleIndex = 0;
108-
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
109-
const float low = i, high = i + 0.2;
110-
const filament::math::float2 v[3]{{ low, low },
111-
{ high, low },
112-
{ low, high }};
113-
triangle.updateVertices(v);
114-
115-
if (updateIndices) {
116-
if (triangleIndex % 2 == 0) {
117-
// Upload each index separately, to test offsets.
118-
const TrianglePrimitive::index_type i[3]{ 0, 1, 2 };
119-
triangle.updateIndices(i + 0, 1, 0);
120-
triangle.updateIndices(i + 1, 1, 1);
121-
triangle.updateIndices(i + 2, 1, 2);
122-
} else {
123-
// This effectively hides this triangle.
124-
const TrianglePrimitive::index_type i[3]{ 0, 0, 0 };
125-
triangle.updateIndices(i);
105+
{
106+
RenderFrame frame(api);
107+
108+
// Draw 10 triangles, updating the vertex buffer / index buffer each time.
109+
size_t triangleIndex = 0;
110+
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
111+
const float low = i, high = i + 0.2;
112+
const filament::math::float2 v[3]{{ low, low },
113+
{ high, low },
114+
{ low, high }};
115+
triangle.updateVertices(v);
116+
117+
if (updateIndices) {
118+
if (triangleIndex % 2 == 0) {
119+
// Upload each index separately, to test offsets.
120+
const TrianglePrimitive::index_type i[3]{ 0, 1, 2 };
121+
triangle.updateIndices(i + 0, 1, 0);
122+
triangle.updateIndices(i + 1, 1, 1);
123+
triangle.updateIndices(i + 2, 1, 2);
124+
} else {
125+
// This effectively hides this triangle.
126+
const TrianglePrimitive::index_type i[3]{ 0, 0, 0 };
127+
triangle.updateIndices(i);
128+
}
126129
}
130+
131+
if (triangleIndex > 0) {
132+
params.flags.clear = TargetBufferFlags::NONE;
133+
params.flags.discardStart = TargetBufferFlags::NONE;
134+
}
135+
136+
api.beginRenderPass(defaultRenderTarget, params);
137+
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
138+
api.endRenderPass();
139+
140+
triangleIndex++;
127141
}
128142

129143
if (triangleIndex > 0) {
@@ -141,15 +155,7 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
141155

142156
triangleIndex++;
143157
}
144-
145-
api.flush();
146-
api.commit(swapChain);
147-
api.endFrame(0);
148-
149-
api.stopCapture(0);
150158
}
151-
152-
executeCommands();
153159
}
154160

155161
// This test renders two triangles in two separate draw calls. Between the draw calls, a uniform
@@ -242,15 +248,13 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
242248
ScreenshotParams(kTexWidth, kTexHeight, "BufferObjectUpdateWithOffset", 2320747245));
243249

244250
api.flush();
245-
api.commit(swapChain);
246-
api.endFrame(0);
251+
{
252+
RenderFrame frame(api);
253+
api.commit(swapChain);
254+
}
247255

248256
// This ensures all driver commands have finished before exiting the test.
249257
api.finish();
250-
251-
executeCommands();
252-
253-
getDriver().purge();
254258
}
255259

256260
} // namespace test

filament/backend/test/test_Callbacks.cpp

Lines changed: 92 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,61 @@ TEST_F(BackendTest, FrameScheduledCallback) {
2828
SKIP_IF(Backend::OPENGL, "Frame callbacks are unsupported in OpenGL");
2929
SKIP_IF(Backend::VULKAN, "Frame callbacks are unsupported in Vulkan, see b/417254479");
3030

31-
auto& api = getDriverApi();
32-
Cleanup cleanup(api);
33-
34-
// Create a SwapChain.
35-
// In order for the frameScheduledCallback to be called, this must be a real SwapChain (not
36-
// headless) so we obtain a drawable.
37-
auto swapChain = cleanup.add(createSwapChain());
38-
39-
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createDefaultRenderTarget());
40-
4131
int callbackCountA = 0;
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-
api.beginFrame(0, 0, 0);
50-
api.beginRenderPass(renderTarget, {});
51-
api.endRenderPass(0);
52-
api.commit(swapChain);
53-
api.endFrame(0);
54-
55-
// Render the next frame. The same callback should be called.
56-
api.makeCurrent(swapChain, swapChain);
57-
api.beginFrame(0, 0, 0);
58-
api.beginRenderPass(renderTarget, {});
59-
api.endRenderPass(0);
60-
api.commit(swapChain);
61-
api.endFrame(0);
62-
63-
// Now switch out the callback.
6432
int callbackCountB = 0;
65-
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountB](PresentCallable callable) {
66-
callable();
67-
callbackCountB++;
68-
}, 0);
69-
70-
// Render one final frame.
71-
api.makeCurrent(swapChain, swapChain);
72-
api.beginFrame(0, 0, 0);
73-
api.beginRenderPass(renderTarget, {});
74-
api.endRenderPass(0);
75-
api.commit(swapChain);
76-
api.endFrame(0);
77-
78-
api.finish();
79-
80-
executeCommands();
81-
getDriver().purge();
82-
33+
{
34+
auto& api = getDriverApi();
35+
Cleanup cleanup(api);
36+
cleanup.addPostCall([&]() { executeCommands(); });
37+
cleanup.addPostCall([&]() { getDriver().purge(); });
38+
39+
// Create a SwapChain.
40+
// In order for the frameScheduledCallback to be called, this must be a real SwapChain (not
41+
// headless) so we obtain a drawable.
42+
auto swapChain = cleanup.add(createSwapChain());
43+
44+
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createDefaultRenderTarget());
45+
46+
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountA](PresentCallable callable) {
47+
callable();
48+
callbackCountA++;
49+
}, 0);
50+
51+
// Render the first frame.
52+
api.makeCurrent(swapChain, swapChain);
53+
{
54+
RenderFrame frame(api);
55+
api.beginRenderPass(renderTarget, {});
56+
api.endRenderPass(0);
57+
api.commit(swapChain);
58+
}
59+
60+
// Render the next frame. The same callback should be called.
61+
api.makeCurrent(swapChain, swapChain);
62+
{
63+
RenderFrame frame(api);
64+
api.beginRenderPass(renderTarget, {});
65+
api.endRenderPass(0);
66+
api.commit(swapChain);
67+
}
68+
69+
// Now switch out the callback.
70+
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountB](PresentCallable callable) {
71+
callable();
72+
callbackCountB++;
73+
}, 0);
74+
75+
// Render one final frame.
76+
api.makeCurrent(swapChain, swapChain);
77+
{
78+
RenderFrame frame(api);
79+
api.beginRenderPass(renderTarget, {});
80+
api.endRenderPass(0);
81+
api.commit(swapChain);
82+
}
83+
84+
api.finish();
85+
}
8386
EXPECT_EQ(callbackCountA, 2);
8487
EXPECT_EQ(callbackCountB, 1);
8588
}
@@ -88,43 +91,47 @@ TEST_F(BackendTest, FrameCompletedCallback) {
8891
SKIP_IF(Backend::OPENGL, "Frame callbacks are unsupported in OpenGL");
8992
SKIP_IF(Backend::VULKAN, "Frame callbacks are unsupported in Vulkan, see b/417254479");
9093

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

129136
EXPECT_EQ(callbackCountA, 2);
130137
EXPECT_EQ(callbackCountB, 1);

0 commit comments

Comments
 (0)