Skip to content

Commit c5e6456

Browse files
committed
Use the backend test cleanup helper more extensively
BUGS=[408310509]
1 parent 6b28049 commit c5e6456

13 files changed

+324
-357
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,
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,
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
@@ -241,15 +247,13 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
241247
"BufferObjectUpdateWithOffset", 2320747245));
242248

243249
api.flush();
244-
api.commit(swapChain);
245-
api.endFrame(0);
250+
{
251+
RenderFrame frame(api);
252+
api.commit(swapChain);
253+
}
246254

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

255259
} // namespace test

filament/backend/test/test_Callbacks.cpp

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

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

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

131138
EXPECT_EQ(callbackCountA, 2);
132139
EXPECT_EQ(callbackCountB, 1);

0 commit comments

Comments
 (0)