KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_gal_resize_strategy.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21
22#include <gal/opengl/utils.h>
23
26
31BOOST_AUTO_TEST_SUITE( GalResizeStrategy )
32
33static const size_t MB = static_cast<size_t>( 1024 ) * 1024;
34
35// Unknown VRAM (no NVX/ATI extension, e.g. Intel/Mesa) must preserve the historical fast path.
36BOOST_AUTO_TEST_CASE( UnknownVramKeepsGpuCopy )
37{
38 BOOST_CHECK( chooseResizeStrategy( 0, 64 * MB, 128 * MB, 0.15 )
39 == VRAM_RESIZE_STRATEGY::GPU_COPY );
40
41 // Even an absurd request stays on the fast path when VRAM is unknown.
42 BOOST_CHECK( chooseResizeStrategy( 0, 4096 * MB, 8192 * MB, 0.15 )
43 == VRAM_RESIZE_STRATEGY::GPU_COPY );
44}
45
46// Plenty of headroom for both buffers plus margin -> fast GPU-side copy.
47BOOST_AUTO_TEST_CASE( AmpleVramUsesGpuCopy )
48{
49 // old + new = 192 MB, +15% margin = ~221 MB; 2 GB free is plenty.
50 BOOST_CHECK( chooseResizeStrategy( 2048 * MB, 64 * MB, 128 * MB, 0.15 )
51 == VRAM_RESIZE_STRATEGY::GPU_COPY );
52}
53
54// Room for the new buffer (plus margin) but not both -> stage through RAM.
55BOOST_AUTO_TEST_CASE( TightVramStagesThroughRam )
56{
57 // old=64, new=128. Both+margin = ~221 MB (too big). New+margin = ~147 MB (fits in 160).
58 BOOST_CHECK( chooseResizeStrategy( 160 * MB, 64 * MB, 128 * MB, 0.15 )
59 == VRAM_RESIZE_STRATEGY::RAM_STAGE );
60}
61
62// Not even the new buffer (plus margin) fits -> refuse and fall back to software.
63BOOST_AUTO_TEST_CASE( InsufficientVramRefuses )
64{
65 BOOST_CHECK( chooseResizeStrategy( 100 * MB, 64 * MB, 128 * MB, 0.15 )
66 == VRAM_RESIZE_STRATEGY::REFUSE );
67}
68
69// The margin is honored at the boundary between strategies.
70BOOST_AUTO_TEST_CASE( MarginBoundaries )
71{
72 const size_t oldBytes = 100 * MB;
73 const size_t newBytes = 100 * MB;
74
75 // Exactly old+new with a zero margin -> GPU_COPY (>= comparison).
76 BOOST_CHECK( chooseResizeStrategy( 200 * MB, oldBytes, newBytes, 0.0 )
77 == VRAM_RESIZE_STRATEGY::GPU_COPY );
78
79 // One byte short of old+new -> drops to RAM_STAGE.
80 BOOST_CHECK( chooseResizeStrategy( 200 * MB - 1, oldBytes, newBytes, 0.0 )
81 == VRAM_RESIZE_STRATEGY::RAM_STAGE );
82
83 // Exactly the new buffer with zero margin -> RAM_STAGE.
84 BOOST_CHECK( chooseResizeStrategy( 100 * MB, oldBytes, newBytes, 0.0 )
85 == VRAM_RESIZE_STRATEGY::RAM_STAGE );
86
87 // One byte short of the new buffer -> REFUSE.
88 BOOST_CHECK( chooseResizeStrategy( 100 * MB - 1, oldBytes, newBytes, 0.0 )
89 == VRAM_RESIZE_STRATEGY::REFUSE );
90}
91
92// A negative margin is clamped to zero rather than loosening the budget.
93BOOST_AUTO_TEST_CASE( NegativeMarginClampedToZero )
94{
95 BOOST_CHECK( chooseResizeStrategy( 200 * MB, 100 * MB, 100 * MB, -0.5 )
96 == VRAM_RESIZE_STRATEGY::GPU_COPY );
97
98 BOOST_CHECK( chooseResizeStrategy( 200 * MB - 1, 100 * MB, 100 * MB, -0.5 )
99 == VRAM_RESIZE_STRATEGY::RAM_STAGE );
100}
101
VRAM_RESIZE_STRATEGY
Strategy for growing a GPU vertex buffer, trading copy speed against peak video memory.
Definition utils.h:58
VRAM_RESIZE_STRATEGY chooseResizeStrategy(size_t aFreeVRAM, size_t aOldBytes, size_t aNewBytes, double aMarginFrac)
Decide how to grow a GPU vertex buffer given the free video memory budget.
Definition utils.cpp:234
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static const size_t MB
Tests for the predictive GPU buffer resize strategy guard that keeps a large-board defragmentResize()...
BOOST_AUTO_TEST_CASE(UnknownVramKeepsGpuCopy)
VRAM_RESIZE_STRATEGY chooseResizeStrategy(size_t aFreeVRAM, size_t aOldBytes, size_t aNewBytes, double aMarginFrac)
Decide how to grow a GPU vertex buffer given the free video memory budget.
Definition utils.cpp:234
BOOST_AUTO_TEST_SUITE_END()