Blender V4.3
vk_render_graph_test_types.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include <locale>
8#include <sstream>
9
11#include "vk_common.hh"
12#include "vk_to_string.hh"
13
15
16BLI_INLINE std::string &endl()
17{
18 static std::string endl;
19 if (endl.empty()) {
20 std::stringstream ss;
21 ss << std::endl;
22 endl = ss.str();
23 }
24 return endl;
25}
26
29 bool is_recording_ = false;
30 bool is_cpu_synchronizing_ = false;
31
32 public:
34 virtual ~CommandBufferLog() {}
35
36 void begin_recording() override
37 {
38 EXPECT_FALSE(is_recording_);
39 is_recording_ = true;
40 }
41
42 void end_recording() override
43 {
44 EXPECT_TRUE(is_recording_);
45 is_recording_ = false;
46 }
47
48 void submit_with_cpu_synchronization(VkFence /*vk_fence*/) override
49 {
50 EXPECT_FALSE(is_recording_);
51 EXPECT_FALSE(is_cpu_synchronizing_);
52 is_cpu_synchronizing_ = true;
53 };
54 void wait_for_cpu_synchronization(VkFence /*vk_fence*/) override
55 {
56 EXPECT_FALSE(is_recording_);
57 EXPECT_TRUE(is_cpu_synchronizing_);
58 is_cpu_synchronizing_ = false;
59 };
60
61 void bind_pipeline(VkPipelineBindPoint pipeline_bind_point, VkPipeline pipeline) override
62 {
63 EXPECT_TRUE(is_recording_);
64 std::stringstream ss;
65 ss << "bind_pipeline(";
66 ss << "pipeline_bind_point=" << to_string(pipeline_bind_point);
67 ss << ", pipeline=" << to_string(pipeline);
68 ss << ")";
69 log_.append(ss.str());
70 }
71
72 void bind_descriptor_sets(VkPipelineBindPoint pipeline_bind_point,
73 VkPipelineLayout layout,
74 uint32_t first_set,
75 uint32_t descriptor_set_count,
76 const VkDescriptorSet *p_descriptor_sets,
77 uint32_t dynamic_offset_count,
78 const uint32_t *p_dynamic_offsets) override
79 {
80 UNUSED_VARS(pipeline_bind_point,
81 layout,
82 first_set,
83 descriptor_set_count,
84 p_descriptor_sets,
85 dynamic_offset_count,
86 p_dynamic_offsets);
87 EXPECT_TRUE(is_recording_);
88 std::stringstream ss;
89 ss << "bind_descriptor_sets(";
90 ss << "pipeline_bind_point=" << to_string(pipeline_bind_point);
91 ss << ", layout=" << to_string(layout);
92 ss << ", p_descriptor_sets=" << to_string(p_descriptor_sets[0]);
93 ss << ")";
94 log_.append(ss.str());
95 }
96
97 void bind_index_buffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType index_type) override
98 {
99 UNUSED_VARS(buffer, offset, index_type);
100 EXPECT_TRUE(is_recording_);
101 GTEST_FAIL() << __func__ << " not implemented!";
102 }
103
104 void bind_vertex_buffers(uint32_t first_binding,
105 uint32_t binding_count,
106 const VkBuffer *p_buffers,
107 const VkDeviceSize *p_offsets) override
108 {
109 UNUSED_VARS(first_binding, binding_count, p_buffers, p_offsets);
110 EXPECT_TRUE(is_recording_);
111 GTEST_FAIL() << __func__ << " not implemented!";
112 }
113
114 void draw(uint32_t vertex_count,
115 uint32_t instance_count,
116 uint32_t first_vertex,
117 uint32_t first_instance) override
118 {
119 EXPECT_TRUE(is_recording_);
120 std::stringstream ss;
121 ss << "draw(";
122 ss << "vertex_count=" << vertex_count;
123 ss << ", instance_count=" << instance_count;
124 ss << ", first_vertex=" << first_vertex;
125 ss << ", first_instance=" << first_instance;
126 ss << ")";
127 log_.append(ss.str());
128 }
129
130 void draw_indexed(uint32_t index_count,
131 uint32_t instance_count,
132 uint32_t first_index,
133 int32_t vertex_offset,
134 uint32_t first_instance) override
135 {
136 EXPECT_TRUE(is_recording_);
137 std::stringstream ss;
138 ss << "draw_indexed(";
139 ss << "index_count=" << index_count;
140 ss << ", instance_count=" << instance_count;
141 ss << ", first_index=" << first_index;
142 ss << ", vertex_offset=" << vertex_offset;
143 ss << ", first_instance=" << first_instance;
144 ss << ")";
145 log_.append(ss.str());
146 }
147
148 void draw_indirect(VkBuffer buffer,
149 VkDeviceSize offset,
150 uint32_t draw_count,
151 uint32_t stride) override
152 {
153 UNUSED_VARS(buffer, offset, draw_count, stride);
154 EXPECT_TRUE(is_recording_);
155 GTEST_FAIL() << __func__ << " not implemented!";
156 }
157
158 void draw_indexed_indirect(VkBuffer buffer,
159 VkDeviceSize offset,
160 uint32_t draw_count,
161 uint32_t stride) override
162 {
163 UNUSED_VARS(buffer, offset, draw_count, stride);
164 EXPECT_TRUE(is_recording_);
165 GTEST_FAIL() << __func__ << " not implemented!";
166 }
167
168 void dispatch(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override
169 {
170 UNUSED_VARS(group_count_x, group_count_y, group_count_z);
171 EXPECT_TRUE(is_recording_);
172 std::stringstream ss;
173 ss << "dispatch(";
174 ss << "group_count_x=" << group_count_x;
175 ss << ", group_count_y=" << group_count_y;
176 ss << ", group_count_z=" << group_count_z;
177 ss << ")";
178 log_.append(ss.str());
179 }
180
181 void dispatch_indirect(VkBuffer buffer, VkDeviceSize offset) override
182 {
183 EXPECT_TRUE(is_recording_);
184 std::stringstream ss;
185 ss << "dispatch_indirect(";
186 ss << "buffer=" << to_string(buffer);
187 ss << ", offset=" << offset;
188 ss << ")";
189 log_.append(ss.str());
190 }
191
192 void update_buffer(VkBuffer dst_buffer,
193 VkDeviceSize dst_offset,
194 VkDeviceSize data_size,
195 const void * /*p_data*/) override
196 {
197 EXPECT_TRUE(is_recording_);
198 std::stringstream ss;
199 ss << "update_buffer(";
200 ss << "dst_buffer=" << to_string(dst_buffer);
201 ss << ", dst_offset=" << dst_offset;
202 ss << ", data_size=" << data_size;
203 ss << ")";
204 log_.append(ss.str());
205 }
206 void copy_buffer(VkBuffer src_buffer,
207 VkBuffer dst_buffer,
208 uint32_t region_count,
209 const VkBufferCopy *p_regions) override
210 {
211 EXPECT_TRUE(is_recording_);
212 std::stringstream ss;
213 ss << "copy_buffer(";
214 ss << "src_buffer=" << to_string(src_buffer);
215 ss << ", dst_buffer=" << to_string(dst_buffer);
216 ss << std::endl;
217 for (const VkBufferCopy &region : Span<const VkBufferCopy>(p_regions, region_count)) {
218 ss << " - region(" << to_string(region, 1) << ")" << std::endl;
219 }
220 ss << ")";
221 log_.append(ss.str());
222 }
223
224 void copy_image(VkImage src_image,
225 VkImageLayout src_image_layout,
226 VkImage dst_image,
227 VkImageLayout dst_image_layout,
228 uint32_t region_count,
229 const VkImageCopy *p_regions) override
230 {
231 EXPECT_TRUE(is_recording_);
232 std::stringstream ss;
233 ss << "copy_image(";
234 ss << "src_image=" << to_string(src_image);
235 ss << ", src_image_layout=" << to_string(src_image_layout);
236 ss << ", dst_image=" << to_string(dst_image);
237 ss << ", dst_image_layout=" << to_string(dst_image_layout);
238 ss << std::endl;
239 for (const VkImageCopy &region : Span<const VkImageCopy>(p_regions, region_count)) {
240 ss << " - region(" << to_string(region, 1) << ")" << std::endl;
241 }
242 ss << ")";
243 log_.append(ss.str());
244 }
245
246 void blit_image(VkImage src_image,
247 VkImageLayout src_image_layout,
248 VkImage dst_image,
249 VkImageLayout dst_image_layout,
250 uint32_t region_count,
251 const VkImageBlit *p_regions,
252 VkFilter filter) override
253 {
254 EXPECT_TRUE(is_recording_);
255 std::stringstream ss;
256 ss << "blit_image(";
257 ss << "src_image=" << to_string(src_image);
258 ss << ", src_image_layout=" << to_string(src_image_layout);
259 ss << ", dst_image=" << to_string(dst_image);
260 ss << ", dst_image_layout=" << to_string(dst_image_layout);
261 ss << ", filter=" << to_string(filter);
262 ss << std::endl;
263 for (const VkImageBlit &region : Span<const VkImageBlit>(p_regions, region_count)) {
264 ss << " - region(" << to_string(region, 1) << ")" << std::endl;
265 }
266 ss << ")";
267 log_.append(ss.str());
268 }
269
270 void copy_buffer_to_image(VkBuffer src_buffer,
271 VkImage dst_image,
272 VkImageLayout dst_image_layout,
273 uint32_t region_count,
274 const VkBufferImageCopy *p_regions) override
275 {
276 EXPECT_TRUE(is_recording_);
277 std::stringstream ss;
278 ss << "copy_buffer_to_image(";
279 ss << "src_buffer=" << to_string(src_buffer);
280 ss << ", dst_image=" << to_string(dst_image);
281 ss << ", src_image_layout=" << to_string(dst_image_layout);
282 ss << std::endl;
283 for (const VkBufferImageCopy &region : Span<const VkBufferImageCopy>(p_regions, region_count))
284 {
285 ss << " - region(" << to_string(region, 1) << ")" << std::endl;
286 }
287 ss << ")";
288 log_.append(ss.str());
289 }
290
291 void copy_image_to_buffer(VkImage src_image,
292 VkImageLayout src_image_layout,
293 VkBuffer dst_buffer,
294 uint32_t region_count,
295 const VkBufferImageCopy *p_regions) override
296 {
297 EXPECT_TRUE(is_recording_);
298 std::stringstream ss;
299 ss << "copy_image_to_buffer(";
300 ss << "src_image=" << to_string(src_image);
301 ss << ", src_image_layout=" << to_string(src_image_layout);
302 ss << ", dst_buffer=" << to_string(dst_buffer);
303 ss << std::endl;
304 for (const VkBufferImageCopy &region : Span<const VkBufferImageCopy>(p_regions, region_count))
305 {
306 ss << " - region(" << to_string(region, 1) << ")" << std::endl;
307 }
308 ss << ")";
309 log_.append(ss.str());
310 }
311
312 void fill_buffer(VkBuffer dst_buffer,
313 VkDeviceSize dst_offset,
314 VkDeviceSize size,
315 uint32_t data) override
316 {
317 EXPECT_TRUE(is_recording_);
318 std::stringstream ss;
319 ss << "fill_buffer(";
320 ss << "dst_buffer=" << to_string(dst_buffer);
321 ss << ", dst_offset=" << dst_offset;
322 ss << ", size=" << size;
323 ss << ", data=" << data;
324 ss << ")";
325 log_.append(ss.str());
326 }
327
328 void clear_color_image(VkImage image,
329 VkImageLayout image_layout,
330 const VkClearColorValue *p_color,
331 uint32_t range_count,
332 const VkImageSubresourceRange *p_ranges) override
333 {
334 UNUSED_VARS(p_color, range_count, p_ranges);
335 EXPECT_TRUE(is_recording_);
336 std::stringstream ss;
337 ss << "clear_color_image(";
338 ss << "image=" << to_string(image);
339 ss << ", image_layout=" << to_string(image_layout);
340 ss << ")";
341 log_.append(ss.str());
342 }
343
344 void clear_depth_stencil_image(VkImage image,
345 VkImageLayout image_layout,
346 const VkClearDepthStencilValue *p_depth_stencil,
347 uint32_t range_count,
348 const VkImageSubresourceRange *p_ranges) override
349 {
350 UNUSED_VARS(image, image_layout, p_depth_stencil, range_count, p_ranges);
351 EXPECT_TRUE(is_recording_);
352 GTEST_FAIL() << __func__ << " not implemented!";
353 }
354
355 void clear_attachments(uint32_t attachment_count,
356 const VkClearAttachment *p_attachments,
357 uint32_t rect_count,
358 const VkClearRect *p_rects) override
359 {
360 UNUSED_VARS(attachment_count, p_attachments, rect_count, p_rects);
361 EXPECT_TRUE(is_recording_);
362 std::stringstream ss;
363 ss << "clear_attachments(";
364 for (const VkClearAttachment &attachment :
365 Span<VkClearAttachment>(p_attachments, attachment_count))
366 {
367 ss << " - attachment(" << to_string(attachment, 1) << ")" << std::endl;
368 }
369 for (const VkClearRect &rect : Span<VkClearRect>(p_rects, rect_count)) {
370 ss << " - rect(" << to_string(rect, 1) << ")" << std::endl;
371 }
372 ss << ")";
373
374 log_.append(ss.str());
375 }
376
377 void pipeline_barrier(VkPipelineStageFlags src_stage_mask,
378 VkPipelineStageFlags dst_stage_mask,
379 VkDependencyFlags dependency_flags,
380 uint32_t memory_barrier_count,
381 const VkMemoryBarrier *p_memory_barriers,
382 uint32_t buffer_memory_barrier_count,
383 const VkBufferMemoryBarrier *p_buffer_memory_barriers,
384 uint32_t image_memory_barrier_count,
385 const VkImageMemoryBarrier *p_image_memory_barriers) override
386 {
387 UNUSED_VARS(dependency_flags, memory_barrier_count, p_memory_barriers);
388 EXPECT_TRUE(is_recording_);
389 std::stringstream ss;
390 ss << "pipeline_barrier(";
391 ss << "src_stage_mask=" << to_string_vk_pipeline_stage_flags(src_stage_mask);
392 ss << ", dst_stage_mask=" << to_string_vk_pipeline_stage_flags(dst_stage_mask);
393 ss << std::endl;
394 for (VkImageMemoryBarrier image_barrier :
395 Span<VkImageMemoryBarrier>(p_image_memory_barriers, image_memory_barrier_count))
396 {
397 ss << " - image_barrier(" << to_string(image_barrier, 1) << ")" << std::endl;
398 }
399 for (VkBufferMemoryBarrier buffer_barrier :
400 Span<VkBufferMemoryBarrier>(p_buffer_memory_barriers, buffer_memory_barrier_count))
401 {
402 ss << " - buffer_barrier(" << to_string(buffer_barrier, 1) << ")" << std::endl;
403 }
404 ss << ")";
405
406 log_.append(ss.str());
407 }
408
409 void push_constants(VkPipelineLayout layout,
410 VkShaderStageFlags stage_flags,
411 uint32_t offset,
412 uint32_t size,
413 const void *p_values) override
414 {
415 UNUSED_VARS(layout, stage_flags, offset, size, p_values);
416 EXPECT_TRUE(is_recording_);
417 GTEST_FAIL() << __func__ << " not implemented!";
418 }
419
420 void begin_rendering(const VkRenderingInfo *p_rendering_info) override
421 {
422 EXPECT_TRUE(is_recording_);
423 std::stringstream ss;
424 ss << "begin_rendering(";
425 ss << "p_rendering_info=" << to_string(*p_rendering_info);
426 ss << ")";
427 log_.append(ss.str());
428 }
429
430 void end_rendering() override
431 {
432 EXPECT_TRUE(is_recording_);
433 std::stringstream ss;
434 ss << "end_rendering()";
435 log_.append(ss.str());
436 }
437
438 void begin_query(VkQueryPool /*vk_query_pool*/,
439 uint32_t /*query_index*/,
440 VkQueryControlFlags /*vk_query_control_flags*/) override
441 {
442 }
443 void end_query(VkQueryPool /*vk_query_pool*/, uint32_t /*query_index*/) override {}
444 void reset_query_pool(VkQueryPool /*vk_query_pool*/,
445 uint32_t /*first_query*/,
446 uint32_t /*query_count*/) override
447 {
448 }
449 void begin_debug_utils_label(const VkDebugUtilsLabelEXT * /*vk_debug_utils_label*/) override {}
450 void end_debug_utils_label() override {}
451};
452
459template<typename VKObjectType> union VkHandle {
460 VKObjectType vk_handle;
462
463 VkHandle(uint64_t handle) : handle(handle) {}
464
465 operator VKObjectType() const
466 {
467 return vk_handle;
468 }
469};
470
471} // namespace blender::gpu::render_graph
#define BLI_INLINE
#define UNUSED_VARS(...)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void append(const T &value)
void clear_attachments(uint32_t attachment_count, const VkClearAttachment *p_attachments, uint32_t rect_count, const VkClearRect *p_rects) override
void begin_rendering(const VkRenderingInfo *p_rendering_info) override
void update_buffer(VkBuffer dst_buffer, VkDeviceSize dst_offset, VkDeviceSize data_size, const void *) override
void begin_debug_utils_label(const VkDebugUtilsLabelEXT *) override
void push_constants(VkPipelineLayout layout, VkShaderStageFlags stage_flags, uint32_t offset, uint32_t size, const void *p_values) override
void clear_depth_stencil_image(VkImage image, VkImageLayout image_layout, const VkClearDepthStencilValue *p_depth_stencil, uint32_t range_count, const VkImageSubresourceRange *p_ranges) override
void pipeline_barrier(VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask, VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, const VkMemoryBarrier *p_memory_barriers, uint32_t buffer_memory_barrier_count, const VkBufferMemoryBarrier *p_buffer_memory_barriers, uint32_t image_memory_barrier_count, const VkImageMemoryBarrier *p_image_memory_barriers) override
void copy_image_to_buffer(VkImage src_image, VkImageLayout src_image_layout, VkBuffer dst_buffer, uint32_t region_count, const VkBufferImageCopy *p_regions) override
void draw(uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) override
void bind_pipeline(VkPipelineBindPoint pipeline_bind_point, VkPipeline pipeline) override
void draw_indirect(VkBuffer buffer, VkDeviceSize offset, uint32_t draw_count, uint32_t stride) override
void copy_image(VkImage src_image, VkImageLayout src_image_layout, VkImage dst_image, VkImageLayout dst_image_layout, uint32_t region_count, const VkImageCopy *p_regions) override
void bind_vertex_buffers(uint32_t first_binding, uint32_t binding_count, const VkBuffer *p_buffers, const VkDeviceSize *p_offsets) override
void reset_query_pool(VkQueryPool, uint32_t, uint32_t) override
void begin_query(VkQueryPool, uint32_t, VkQueryControlFlags) override
void dispatch_indirect(VkBuffer buffer, VkDeviceSize offset) override
void draw_indexed_indirect(VkBuffer buffer, VkDeviceSize offset, uint32_t draw_count, uint32_t stride) override
void copy_buffer_to_image(VkBuffer src_buffer, VkImage dst_image, VkImageLayout dst_image_layout, uint32_t region_count, const VkBufferImageCopy *p_regions) override
void fill_buffer(VkBuffer dst_buffer, VkDeviceSize dst_offset, VkDeviceSize size, uint32_t data) override
void draw_indexed(uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t vertex_offset, uint32_t first_instance) override
void clear_color_image(VkImage image, VkImageLayout image_layout, const VkClearColorValue *p_color, uint32_t range_count, const VkImageSubresourceRange *p_ranges) override
void copy_buffer(VkBuffer src_buffer, VkBuffer dst_buffer, uint32_t region_count, const VkBufferCopy *p_regions) override
void dispatch(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override
void bind_index_buffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType index_type) override
void bind_descriptor_sets(VkPipelineBindPoint pipeline_bind_point, VkPipelineLayout layout, uint32_t first_set, uint32_t descriptor_set_count, const VkDescriptorSet *p_descriptor_sets, uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets) override
void blit_image(VkImage src_image, VkImageLayout src_image_layout, VkImage dst_image, VkImageLayout dst_image_layout, uint32_t region_count, const VkImageBlit *p_regions, VkFilter filter) override
ccl_device_inline float3 log(float3 v)
const char * to_string(ShaderStage stage)
Definition mtl_shader.mm:52
std::string to_string_vk_pipeline_stage_flags(const VkPipelineStageFlags vk_pipeline_stage_flags)
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
unsigned __int64 uint64_t
Definition stdint.h:90