Skip to content

Commit 328e5d9

Browse files
committed
Fix clip path for d3d11 level
1 parent f925ce7 commit 328e5d9

3 files changed

Lines changed: 61 additions & 54 deletions

File tree

pathfinder/core/d3d11/renderer.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,13 @@ void RendererD3D11::prepare_tiles(TileBatchDataD3D11 &batch) {
633633
sort_tiles(tiles_d3d11_buffer_id, first_tile_map_buffer_id, z_buffer_id);
634634

635635
// Record tile batch info.
636-
tile_batch_info.insert(tile_batch_info.begin() + batch.batch_id,
637-
TileBatchInfoD3D11{
638-
batch.tile_count,
639-
z_buffer_id,
640-
tiles_d3d11_buffer_id,
641-
propagate_metadata_buffer_ids.propagate_metadata,
642-
first_tile_map_buffer_id,
643-
});
636+
tile_batch_info[batch.batch_id] = TileBatchInfoD3D11{
637+
batch.tile_count,
638+
z_buffer_id,
639+
tiles_d3d11_buffer_id,
640+
propagate_metadata_buffer_ids.propagate_metadata,
641+
first_tile_map_buffer_id,
642+
};
644643
}
645644

646645
std::shared_ptr<MicrolinesBufferIDsD3D11> RendererD3D11::dice_segments(std::vector<DiceMetadataD3D11> &dice_metadata,
@@ -1067,20 +1066,15 @@ void RendererD3D11::sort_tiles(uint64_t tiles_d3d11_buffer_id,
10671066
}
10681067

10691068
void RendererD3D11::free_tile_batch_buffers() {
1070-
while (true) {
1071-
if (tile_batch_info.empty()) {
1072-
break;
1073-
}
1074-
1075-
auto &info = tile_batch_info.back();
1069+
for (auto &it : tile_batch_info) {
1070+
auto &info = it.second;
10761071

10771072
allocator->free_buffer(info.z_buffer_id);
10781073
allocator->free_buffer(info.tiles_d3d11_buffer_id);
10791074
allocator->free_buffer(info.propagate_metadata_buffer_id);
10801075
allocator->free_buffer(info.first_tile_map_buffer_id);
1081-
1082-
tile_batch_info.pop_back();
10831076
}
1077+
tile_batch_info.clear();
10841078
}
10851079

10861080
TextureFormat RendererD3D11::mask_texture_format() const {

pathfinder/core/d3d11/renderer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../renderer.h"
77
#include "../scene.h"
88
#include "gpu_data.h"
9+
#include <map>
910

1011
#ifdef PATHFINDER_ENABLE_D3D11
1112

@@ -209,7 +210,7 @@ class RendererD3D11 : public Renderer {
209210

210211
SceneBuffers scene_buffers;
211212

212-
std::vector<TileBatchInfoD3D11> tile_batch_info;
213+
std::map<uint32_t, TileBatchInfoD3D11> tile_batch_info;
213214
};
214215

215216
} // namespace Pathfinder

pathfinder/core/d3d11/scene_builder.cpp

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ std::shared_ptr<GlobalPathId> add_clip_path_to_batch(Scene &scene,
2020
uint32_t clip_level,
2121
const Transform2 &transform,
2222
LastSceneInfo &last_scene,
23+
uint32_t &next_batch_id,
2324
ClipBatchesD3D11 &clip_batches_d3d11);
2425

2526
std::shared_ptr<BuiltDrawPath> prepare_draw_path_for_gpu_binning(Scene &scene,
@@ -61,13 +62,19 @@ PreparedClipPath prepare_clip_path_for_gpu_binning(Scene &scene,
6162
const Transform2 &transform,
6263
LastSceneInfo &last_scene,
6364
size_t clip_level,
65+
uint32_t &next_batch_id,
6466
ClipBatchesD3D11 &clip_batches_d3d11) {
6567
auto effective_view_box = scene.get_view_box();
6668
auto clip_path = scene.clip_paths[clip_path_id];
6769

6870
// Add subclip path if necessary.
69-
auto subclip_id =
70-
add_clip_path_to_batch(scene, clip_path.clip_path, clip_level + 1, transform, last_scene, clip_batches_d3d11);
71+
auto subclip_id = add_clip_path_to_batch(scene,
72+
clip_path.clip_path,
73+
clip_level + 1,
74+
transform,
75+
last_scene,
76+
next_batch_id,
77+
clip_batches_d3d11);
7178

7279
auto path_bounds = transform * clip_path.outline.bounds;
7380

@@ -87,42 +94,42 @@ std::shared_ptr<GlobalPathId> add_clip_path_to_batch(Scene &scene,
8794
uint32_t clip_level,
8895
const Transform2 &transform,
8996
LastSceneInfo &last_scene,
97+
uint32_t &next_batch_id,
9098
ClipBatchesD3D11 &clip_batches_d3d11) {
91-
if (clip_path_id) {
92-
auto &map = clip_batches_d3d11.clip_id_to_path_batch_index;
93-
94-
if (map.find(*clip_path_id) != map.end()) {
95-
auto clip_path_batch_index = map[*clip_path_id];
96-
return std::make_shared<GlobalPathId>(GlobalPathId{clip_level, clip_path_batch_index});
97-
} else {
98-
auto prepared_clip_path = prepare_clip_path_for_gpu_binning(scene,
99-
*clip_path_id,
100-
transform,
101-
last_scene,
102-
clip_level,
103-
clip_batches_d3d11);
104-
105-
auto clip_path = prepared_clip_path.built_path;
106-
auto subclip_id = prepared_clip_path.subclip_id;
107-
108-
while (clip_level >= clip_batches_d3d11.prepare_batches.size()) {
109-
auto clip_tile_batch_id = clip_batches_d3d11.prepare_batches.size();
110-
clip_batches_d3d11.prepare_batches.emplace_back(clip_tile_batch_id, PathSource::Clip);
111-
}
112-
113-
auto clip_path_batch_index = clip_batches_d3d11.prepare_batches[clip_level].push(clip_path,
114-
*clip_path_id,
115-
subclip_id,
116-
true,
117-
last_scene);
118-
119-
map[*clip_path_id] = clip_path_batch_index;
120-
121-
return std::make_shared<GlobalPathId>(GlobalPathId{clip_level, clip_path_batch_index});
122-
}
99+
if (!clip_path_id) {
100+
return nullptr;
101+
}
102+
103+
auto &map = clip_batches_d3d11.clip_id_to_path_batch_index;
104+
if (map.find(*clip_path_id) != map.end()) {
105+
auto clip_path_batch_index = map[*clip_path_id];
106+
auto &batch = clip_batches_d3d11.prepare_batches[clip_level];
107+
return std::make_shared<GlobalPathId>(GlobalPathId{batch.batch_id, clip_path_batch_index});
108+
}
109+
110+
auto prepared_clip_path = prepare_clip_path_for_gpu_binning(scene,
111+
*clip_path_id,
112+
transform,
113+
last_scene,
114+
clip_level,
115+
next_batch_id,
116+
clip_batches_d3d11);
117+
118+
auto clip_path = prepared_clip_path.built_path;
119+
auto subclip_id = prepared_clip_path.subclip_id;
120+
121+
while (clip_level >= clip_batches_d3d11.prepare_batches.size()) {
122+
auto clip_tile_batch_id = next_batch_id++;
123+
clip_batches_d3d11.prepare_batches.emplace_back(clip_tile_batch_id, PathSource::Clip);
123124
}
124125

125-
return nullptr;
126+
auto clip_path_batch_index =
127+
clip_batches_d3d11.prepare_batches[clip_level].push(clip_path, *clip_path_id, subclip_id, true, last_scene);
128+
129+
map[*clip_path_id] = clip_path_batch_index;
130+
131+
auto &batch = clip_batches_d3d11.prepare_batches[clip_level];
132+
return std::make_shared<GlobalPathId>(GlobalPathId{batch.batch_id, clip_path_batch_index});
126133
}
127134

128135
/// Create tile batches.
@@ -176,8 +183,13 @@ std::vector<DrawTileBatchD3D11> build_tile_batches_for_draw_path_display_item(
176183
// Add clip path if necessary.
177184
std::shared_ptr<GlobalPathId> clip_path;
178185
if (clip_batches_d3d11) {
179-
clip_path =
180-
add_clip_path_to_batch(scene, draw_path->clip_path_id, 0, transform, last_scene, *clip_batches_d3d11);
186+
clip_path = add_clip_path_to_batch(scene,
187+
draw_path->clip_path_id,
188+
0,
189+
transform,
190+
last_scene,
191+
next_batch_id,
192+
*clip_batches_d3d11);
181193
}
182194

183195
draw_tile_batch->tile_batch_data.push(draw_path->path,

0 commit comments

Comments
 (0)