Blender V5.3
vk_texture_pool.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <fmt/format.h>
10
11#include "vk_backend.hh"
12#include "vk_texture_pool.hh"
13
14#include "BKE_global.hh"
15
16#include "CLG_log.h"
17
18namespace blender {
19
20static CLG_LogRef LOG = {"gpu.vulkan"};
21
22namespace detail {
23/* Wrap non-hardcoded arguments of VkImageCreateInfo as tuple of lvalues.
24 * Keep in sync with `VKTexturePool::acquire_texture_impl()`. */
25constexpr auto tie(const VkImageCreateInfo &info)
26{
27 return std::tie(info.format,
28 info.imageType,
29 info.flags,
30 info.usage,
31 info.extent.width,
32 info.extent.height,
33 info.extent.depth,
34 info.arrayLayers,
35 info.mipLevels);
36}
37} // namespace detail
38
39/* DefaultHash implementation over non-hardcoded arguments of VkImageCreateInfo.
40 * Keep in sync with `VKTexturePool::acquire_texture()`. */
41template<> struct DefaultHash<VkImageCreateInfo> {
42 constexpr uint64_t operator()(const VkImageCreateInfo &value) const
43 {
44 const auto &[_1, _2, _3, _4, _5, _6, _7, _8, _9] = detail::tie(value);
45 return get_default_hash(_1, _2, _3, _4, get_default_hash(_5, _6, _7, _8, _9));
46 }
47};
48
49namespace gpu {
50
55
60
62{
63 return std::tuple_cat(detail::tie(create_info), std::tie(allocation, segment)) ==
64 std::tuple_cat(detail::tie(o.create_info), std::tie(o.allocation, o.segment));
65}
66
68 const std::string &name_str)
69{
70 VKDevice &device = VKBackend::get().device;
71
72 /* Create VkImage handle from provided VkImageCreateInfo */
73 VkImage image;
74 VkResult create_result = device.functions.vkCreateImage(
75 device.vk_handle(), &info.create_info, nullptr, &image);
76 UNUSED_VARS_NDEBUG(create_result);
77 BLI_assert(create_result == VK_SUCCESS);
78
79 /* Bind VkImage handle to provided VmaAllocation. */
80 VkResult bind_result = vmaBindImageMemory2(
81 device.mem_allocator_get(), info.allocation, info.segment.offset, image, nullptr);
82 UNUSED_VARS_NDEBUG(bind_result);
83 BLI_assert(bind_result == VK_SUCCESS);
84
85 /* Register VkImage handle as resource for synchronization. */
86 bool use_subresource_tracking = info.create_info.arrayLayers > 1 ||
87 info.create_info.mipLevels > 1;
88 /* `VK_NULL_HANDLE` on purpose: the `AllocationHandle` owns the allocation; passing it here
89 * would double-free it in `vmaDestroyImage`. */
90 ResourceHandle resource_handle = device.resources.add_aliased_image(
91 image, use_subresource_tracking, VK_NULL_HANDLE, name_str.c_str());
92
93 return {.resource_handle = resource_handle, .vk_handle = image};
94}
95
96/* Query memory requirements from VkImageCreateInfo. If VK_KHR_MAINTENANCE4 is supported,
97 * we avoid instantiating a VkImage handle. Otherwise, the image handle is destroyed as a
98 * matching handle is provided by VKImageCache. */
99inline VkMemoryRequirements get_image_memory_requirements(const VkImageCreateInfo &image_info)
100{
101 VKDevice &device = VKBackend::get().device;
102 VkMemoryRequirements2 reqs_out = {.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2};
103
104 if (device.extensions_get().maintenance4) {
105 VkDeviceImageMemoryRequirements reqs_info = {
106 .sType = VK_STRUCTURE_TYPE_DEVICE_IMAGE_MEMORY_REQUIREMENTS,
107 .pNext = nullptr,
108 .pCreateInfo = &image_info,
109 .planeAspect = VK_IMAGE_ASPECT_NONE,
110 };
111 device.functions.vkGetDeviceImageMemoryRequirementsKHR(
112 device.vk_handle(), &reqs_info, &reqs_out);
113 }
114 else {
115 VkImage image = VK_NULL_HANDLE;
116 VkResult result = device.functions.vkCreateImage(
117 device.vk_handle(), &image_info, nullptr, &image);
119 BLI_assert(result == VK_SUCCESS);
120
121 VkImageMemoryRequirementsInfo2 reqs_info = {
122 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
123 .pNext = nullptr,
124 .image = image,
125 };
126 device.functions.vkGetImageMemoryRequirements2(device.vk_handle(), &reqs_info, &reqs_out);
127 device.functions.vkDestroyImage(device.vk_handle(), image, nullptr);
128 }
129
130 return reqs_out.memoryRequirements;
131}
132
134{
135 /* If a bound VkImage handle exists in the map, reset its counter and return it. */
136 VKImageHandle *image_handle = cache_.lookup_ptr(info);
137 if (image_handle) {
138 image_handle->unused_cycles_count = 0;
139 return image_handle->resource;
140 }
141
142 /* Generate debug label name, if one is needed in the rendergraph. */
143 std::string name_str;
144 if (G.debug & G_DEBUG_GPU) {
145 name_str = fmt::format("VkImageFromPool_{}", cache_.size());
146 }
147
148 /* Otherwise, create VkImage handle and insert into cache. */
150 cache_.add_new(info, {.resource = resource});
151
152 return resource;
153}
154
156{
157 VKImageHandle &image_handle = cache_.lookup(info);
158 return std::move(image_handle.image_views);
159}
160
162{
163 VKImageHandle &image_handle = cache_.lookup(info);
164 image_handle.image_views = std::move(image_views);
165}
166
168{
169 VKImageHandle *image_handle = cache_.lookup_ptr(info);
170 BLI_assert_msg(image_handle,
171 "Uninitialized VkImage passed to VKImageCache::reset_unused_cycles_count()");
172 image_handle->unused_cycles_count = 0;
173}
174
175void VKImageCache::reset(bool force_reset)
176{
177 /* Iterate cache; add keys of images hitting `unused_cycles_count` to `unused_images`. */
178 Vector<VKImageInfo> unused_keys;
179 for (decltype(cache_)::MutableItem item : cache_.items()) {
180 if (force_reset == true || item.value.unused_cycles_count >= max_unused_cycles_) {
181 unused_keys.append(item.key);
182 }
183 else {
184 item.value.unused_cycles_count++;
185 }
186 }
187
188 /* Remove unused images from cache and release the pool's reference to them. */
189 for (const VKImageInfo &key : unused_keys) {
190 VKImageHandle handle = cache_.pop(key);
191 VKDevice &device = VKBackend::get().device;
192 device.resources.deref_resource(handle.resource.resource_handle);
193 }
194}
195
196void VKImageCache::discard_all_of(VmaAllocation allocation)
197{
198 /* Gather images bound to the provided allocation. */
199 Vector<VKImageInfo> unused_keys;
200 for (const VKImageInfo &key : cache_.keys()) {
201 if (key.allocation == allocation) {
202 unused_keys.append(key);
203 }
204 }
205
206 /* Remove unused images from cache and release the pool's reference to them. */
207 for (const VKImageInfo &key : unused_keys) {
208 VKImageHandle handle = cache_.pop(key);
209 VKDevice &device = VKBackend::get().device;
210 device.resources.deref_resource(handle.resource.resource_handle);
211 }
212}
213
214std::optional<VKMemorySegment> VKTexturePool::AllocationHandle::acquire(
215 VkMemoryRequirements requirements)
216{
217 /* `memoryType` uses 0 as special value to indicate no memory type restrictions.
218 * If there are restrictions, we check as a mask against `memoryTypeBits`. */
219 uint32_t memory_type_bit = 1u << allocation_info.memoryType;
220 if (allocation_info.memoryType != 0 && !bool(requirements.memoryTypeBits & memory_type_bit)) {
221 return {};
222 }
223
224 /* Find the first compatible segment. If a segment is found, we keep the iterator
225 * to modify the existing segment in the list, as it may be shrunk or split. */
226 auto found_segment = std::ranges::find_if(segments, [&](const VKMemorySegment &segment) {
227 VkDeviceSize aligned_offset = ceil_to_multiple_ul(segment.offset, requirements.alignment);
228 VkDeviceSize remaining_size = segment.size - (aligned_offset - segment.offset);
229 return
230 /* Check: the aligned offset does not lie past the segment's end. */
231 aligned_offset < segment.offset + segment.size &&
232 /* Check: the segment's remaining size is large enough. */
233 remaining_size >= requirements.size;
234 });
235 if (found_segment == segments.end()) {
236 return {};
237 }
238
239 /* The return segment is split from the found segment, starting at the aligned offset. This
240 * implies there are now segments before/after it. */
241 VkDeviceSize aligned_offset = ceil_to_multiple_ul(found_segment->offset, requirements.alignment);
242 VKMemorySegment segment = {.offset = aligned_offset, .size = requirements.size};
243 VKMemorySegment segment_prev = {.offset = found_segment->offset,
244 .size = segment.offset - found_segment->offset};
245 VKMemorySegment segment_next = {.offset = segment.offset + segment.size,
246 .size = found_segment->size - segment.size - segment_prev.size};
247
248 /* Depending on the segments before/after, we shrink/split/remove the stored segment. */
249 if (segment_prev.size > 0 && segment_next.size > 0) {
250 *found_segment = segment_next;
251 segments.insert(found_segment, segment_prev);
252 }
253 else if (segment_prev.size > 0) {
254 *found_segment = segment_prev;
255 }
256 else if (segment_next.size > 0) {
257 *found_segment = segment_next;
258 }
259 else {
260 segments.erase(found_segment);
261 }
262
263 /* Remove allocation offset from the segment. `vmaBindImageMemory()` expects
264 * an offset that is local to the allocation.*/
265 segment.offset -= allocation_info.offset;
266
267 return segment;
268}
269
270void VKTexturePool::AllocationHandle::release(VKMemorySegment segment)
271{
272 /* Re-add allocation offset to the segment, undoing removal in `AllocationHandle::acquire`. */
273 segment.offset += allocation_info.offset;
274
275 /* Find the segments directly before/after the released segment, if they exist. */
276 auto segment_next = std::ranges::find_if(
277 segments, [segment](VKMemorySegment next) { return segment.offset < next.offset; });
278 auto segment_prev = segment_next;
279 if (segment_prev != segments.begin()) {
280 --segment_prev;
281 }
282
283 /* Extend the previous/next segment, if they connect to the released segment. */
284 bool extend_prev = segment_prev != segments.end() &&
285 segment.offset == (segment_prev->offset + segment_prev->size);
286 bool extend_next = segment_next != segments.end() &&
287 segment_next->offset == (segment.offset + segment.size);
288 if (extend_prev) {
289 segment_prev->size += segment.size;
290 }
291 if (extend_next) {
292 segment_next->offset = segment.offset;
293 segment_next->size += segment.size;
294 }
295
296 /* If both segments are extended, we join them. If neither was extended, we
297 * insert the released segment in between, as it doesn't connect to either. */
298 if (extend_prev && extend_next) {
299 segment_prev->size += segment_next->size - segment.size;
300 segments.erase(segment_next);
301 }
302 else if (!(extend_prev || extend_next)) {
303 segments.insert(segment_next, segment);
304 }
305}
306
307void VKTexturePool::AllocationHandle::alloc(VkMemoryRequirements requirements)
308{
309 VKDevice &device = VKBackend::get().device;
310
311 VmaAllocationCreateInfo create_info = {
312 .flags = VMA_ALLOCATION_CREATE_CAN_ALIAS_BIT,
313 .preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
314 .memoryTypeBits = requirements.memoryTypeBits,
315 .priority = 1.0f,
316 };
317
318 if (G.debug & G_DEBUG_GPU) {
319 create_info.flags |= VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT;
320 create_info.pUserData = (void *)__func__;
321 }
322
323 VkResult result = vmaAllocateMemory(
324 device.mem_allocator_get(), &requirements, &create_info, &allocation, &allocation_info);
326 BLI_assert(result == VK_SUCCESS);
327
328 /* Start with a single segment, sized to the full range of the allocation. */
329 segments = {{.offset = allocation_info.offset, .size = allocation_info.size}};
330}
331
332void VKTexturePool::AllocationHandle::free()
333{
334 VKDiscardPool &discard_pool = VKDiscardPool::discard_pool_get();
335 discard_pool.discard_allocation(allocation);
336 segments = {};
337}
338
340{
341 /* VKImageCache causes sporadic crashes on many RDNA2 Mesa configs (dGPU, iGPU; #154768,
342 * #155202). As Mesa has fast VkImage handle creation, it is simply not instantiated there. */
344 image_cache_ = VKImageCache();
345 }
346}
347
349{
350 if (image_cache_) {
351 image_cache_->reset(true);
352 image_cache_ = {};
353 }
354 for (TextureHandle handle : acquired_) {
355 delete handle.texture;
356 }
357 for (AllocationHandle handle : allocations_) {
358 handle.free();
359 }
360}
361
363 int mip_len,
364 GPUTextureType type,
365 TextureFormat format,
366 eGPUTextureUsage usage,
367 const char *name)
368{
369 /* Determine actual mipmap depth. */
370 int mip_len_max = 1 + floorf(log2f(std::max({extent.x, extent.y, extent.z})));
371 mip_len = min_ii(mip_len, mip_len_max);
372
373 /* Initialize VKTexture return object. */
374 VKTexture *texture = new VKTexture(name);
375 texture->w_ = extent.x;
376 texture->h_ = extent.y;
377 texture->d_ = extent.z;
378 texture->format_ = format;
379 texture->format_flag_ = to_format_flag(format);
380 texture->type_ = type;
381 texture->gpu_image_usage_flags_ = usage;
382 texture->mipmaps_ = mip_len;
383 texture->mip_min_ = 0;
384 texture->mip_max_ = mip_len - 1;
385 /* R16G16F16 formats are typically not supported (<1%). */
386 texture->device_format_ = format;
387 if (texture->device_format_ == TextureFormat::SFLOAT_16_16_16) {
388 texture->device_format_ = TextureFormat::SFLOAT_16_16_16_16;
389 }
390 if (texture->device_format_ == TextureFormat::SFLOAT_32_32_32) {
391 texture->device_format_ = TextureFormat::SFLOAT_32_32_32_32;
392 }
393 /* Mirrors behavior in gpu::Texture::init_2d(...). */
394 if ((texture->format_flag_ & (GPU_FORMAT_DEPTH_STENCIL | GPU_FORMAT_INTEGER)) == 0) {
395 texture->sampler_state.filtering = GPU_SAMPLER_FILTERING_LINEAR;
396 }
397
398 /* Fill VkImageCreateInfo to obtain VkMemoryRequirements. */
399 VkImageCreateInfo create_info = {
400 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
401 .pNext = nullptr,
402 .flags = to_vk_image_create(type, to_format_flag(format), usage) | VK_IMAGE_CREATE_ALIAS_BIT,
403 .imageType = to_vk_image_type(type),
404 .format = to_vk_format(format),
405 .extent = texture->vk_extent_3d(0),
406 .mipLevels = uint32_t(max_ii(texture->mip_count(), 1)),
407 .arrayLayers = uint32_t(texture->layer_count()),
408 .samples = VK_SAMPLE_COUNT_1_BIT,
409 .tiling = VK_IMAGE_TILING_OPTIMAL,
410 .usage = to_vk_image_usage(usage, to_format_flag(format), false),
411 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
412 };
413 VkMemoryRequirements requirements = get_image_memory_requirements(create_info);
414
415 /* Info object describing the VkImage and its backing allocation. */
416 VKImageInfo image_info = {.create_info = create_info};
417
418 /* Find a compatible segment of allocated memory. */
419 for (AllocationHandle allocation_handle : allocations_) {
420 std::optional<VKMemorySegment> segment_opt = allocation_handle.acquire(requirements);
421 if (segment_opt) {
422 image_info.allocation = allocation_handle.allocation;
423 image_info.segment = segment_opt.value();
424 allocation_handle.unused_cycles_count = 0;
425 allocations_.add_overwrite(allocation_handle);
426 break;
427 }
428 }
429
430 /* If no compatible region was found, allocate new memory. */
431 if (image_info.allocation == VK_NULL_HANDLE) {
432 VkMemoryRequirements allocation_requirements = requirements;
433 allocation_requirements.size = std::max(allocation_size, requirements.size);
434
435 AllocationHandle handle;
436 handle.alloc(allocation_requirements);
437
438 std::optional<VKMemorySegment> segment_opt = handle.acquire(requirements);
439 if (segment_opt) {
440 image_info.allocation = handle.allocation;
441 image_info.segment = segment_opt.value();
442 allocations_.add(handle);
443 }
444 else {
446 }
447 }
448
449 /* Generate debug label name, attempt to associate it with texture object. */
450 std::string name_str;
451 if (G.debug & G_DEBUG_GPU) {
452 name_str = name ? name : fmt::format("TexFromPool_{}", acquired_.size());
453 }
454
455 /* Get or create a VkImage handle and assign it to the texture. */
456 if (image_cache_) {
457 texture->resource_ = image_cache_->get_or_create(image_info);
458 /* Reuse views of the cached image, as they are only destroyed together with the image. */
459 texture->image_views_ = image_cache_->take_image_views(image_info);
460 }
461 else {
462 texture->resource_ = create_and_bind_vk_image(image_info, name_str);
463 }
464 texture->vk_image_usage_ = create_info.usage;
465 debug::object_label(texture->resource_.vk_handle, name_str);
466
467 if (G.debug & G_DEBUG_GPU) {
468 /* Accumulate usage data for debug log. */
469 current_usage_data_.acquired_segment_size += image_info.segment.size;
470 current_usage_data_.acquired_segment_size_max = std::max(
471 current_usage_data_.acquired_segment_size_max, current_usage_data_.acquired_segment_size);
472 }
473
474 /* Track acquired texture and its backing image. */
475 acquired_.add(TextureHandle{.texture = texture, .image_info = image_info});
476
477 return wrap(texture);
478}
479
481{
482 BLI_assert_msg(acquired_.contains({unwrap(texture)}),
483 "Unacquired texture passed to VKTexturePool::offset_users_count()");
484
485 TextureHandle texture_handle = acquired_.lookup_key({unwrap(texture)});
486 VKImageInfo image_info = texture_handle.image_info;
487 AllocationHandle allocation_handle = allocations_.lookup_key({image_info.allocation});
488
489 /* Avoiding WRITE_AFTER_WRITE/READ_AFTER_WRITE hazards (#161990) when reusing the same cached
490 * VkImage. Reset the tracked layout to undefined so the next alias to use this memory
491 * transitions from VK_IMAGE_LAYOUT_UNDEFINED, as required for memory aliasing.
492 * Textures can be released without an active context, when freeing windows. */
493 VKContext *context = VKContext::get();
494 if (context != nullptr) {
496 .vk_image = texture_handle.texture->vk_image_handle(),
497 .vk_image_layout = VK_IMAGE_LAYOUT_GENERAL,
498 .vk_image_aspect = to_vk_image_aspect_flag_bits(
499 texture_handle.texture->device_format_get()),
500 .vk_access_flags = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
501 .reset_layout_to_undefined = true,
502 };
503 context->render_graph().add_node(synchronization);
504 }
505
506 if (G.debug & G_DEBUG_GPU) {
507 current_usage_data_.acquired_segment_size -= image_info.segment.size;
508 }
509
510 /* Release acquired segment back to allocation. */
511 allocation_handle.release(image_info.segment);
512 allocations_.add_overwrite(allocation_handle);
513
514 /* Release the pool's reference to the VkImage (the cache owns it when in use). */
515 if (image_cache_) {
516 image_cache_->store_image_views(image_info, std::move(texture_handle.texture->image_views_));
517 }
518 else {
519 VKDevice &device = VKBackend::get().device;
520 device.resources.deref_resource(texture_handle.texture->resource_.resource_handle);
521 }
522
523 /* Delete texture and remove it from the acquired set.
524 * VKTexture destructor is skipped as VKTexture::allocation_ is VK_NULL_HANDLE. */
525 acquired_.remove(texture_handle);
526 delete texture_handle.texture;
527}
528
530{
531 BLI_assert_msg(acquired_.contains({unwrap(texture)}),
532 "Unacquired texture passed to VKTexturePool::offset_users_count()");
533 TextureHandle texture_handle = acquired_.lookup_key({unwrap(texture)});
534 texture_handle.users_count += offset;
535 acquired_.add_overwrite(texture_handle);
536}
537
538void VKTexturePool::reset(bool force_free)
539{
540 /* Iterate acquired textures. */
541 for (const TextureHandle &tex : acquired_) {
542 /* Reset the texture's backing image's unused cycles counter in VKImageCache. */
543 if (image_cache_) {
544 image_cache_->reset_unused_cycles_count(tex.image_info);
545 }
546
547 /* Ensure the internal user counter equals 0; otherwise this indicates
548 * a missing `::retain()` or `::release()`. */
549 BLI_assert_msg(tex.users_count == 0,
550 "Missing texture release/retain. Likely TextureFromPool::release(), "
551 "TextureFromPool::retain() or TexturePool::release_texture().");
552 }
553
554 /* Iterate allocations; gather handles hitting `unused_cycles_count`. */
555 Vector<AllocationHandle> unused_allocations;
556 for (AllocationHandle handle : allocations_) {
557 if (handle.is_unused() && (handle.unused_cycles_count >= max_unused_cycles_ || force_free)) {
558 unused_allocations.append(handle);
559 }
560 else {
561 handle.unused_cycles_count++;
562 allocations_.add_overwrite(handle);
563 }
564 }
565
566 /* Remove unused allocations. */
567 for (AllocationHandle handle : unused_allocations) {
568 if (image_cache_) {
569 image_cache_->discard_all_of(handle.allocation);
570 }
571 handle.free();
572 allocations_.remove(handle);
573 }
574
575 /* Remove unused images from cache. */
576 if (image_cache_) {
577 image_cache_->reset();
578 }
579
580 /* Log debug usage data if it differs from the last `::reset()`. */
581 if (G.debug & G_DEBUG_GPU) {
582 /* Log debug usage data if it differs from the last `::reset()`. */
583 current_usage_data_.allocation_count = allocations_.size();
584 current_usage_data_.image_cache_size = image_cache_ ? image_cache_->size() : 0;
585
586 if (!(previous_usage_data_ == current_usage_data_)) {
587 log_usage_data();
588 }
589
590 /* Reset usage data; don't forget to add up persistent textures to current usage. */
591 previous_usage_data_ = current_usage_data_;
592 current_usage_data_ = {};
593 for (const TextureHandle &tex : acquired_) {
594 current_usage_data_.acquired_segment_size += tex.image_info.segment.size;
595 }
596 }
597}
598
599void VKTexturePool::log_usage_data()
600{
601 VkDeviceSize total_allocation_size = 0;
602 for (const AllocationHandle &handle : allocations_) {
603 total_allocation_size += handle.allocation_info.size;
604 }
605 float ratio = float(current_usage_data_.acquired_segment_size_max) /
606 float(total_allocation_size);
607
608 std::string log_message = fmt::format("VKTexturePool uses {}/{} mb ({:.1f}%% of {} allocations)",
609 current_usage_data_.acquired_segment_size_max >> 20,
610 total_allocation_size >> 20,
611 ratio * 100.0f,
612 current_usage_data_.allocation_count);
613 if (image_cache_) {
614 log_message += fmt::format(" ({} cached VkImages)", current_usage_data_.image_cache_size);
615 }
616
617 CLOG_TRACE(&LOG, "%s", log_message.c_str());
618}
619
620} // namespace gpu
621} // namespace blender
#define CLOG_TRACE(clg_ref,...)
Definition CLG_log.h:192
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert(a)
#define BLI_assert_msg(a, msg)
static VKBackend & get()
static VKContext * get()
render_graph::VKResourceStateTracker resources
Definition vk_device.hh:270
VmaAllocator mem_allocator_get() const
Definition vk_device.hh:348
VkDevice vk_handle() const
Definition vk_device.hh:338
const VKExtensions & extensions_get() const
Definition vk_device.hh:398
VolkDeviceTable functions
Definition vk_device.hh:280
static VKDiscardPool & discard_pool_get()
void reset_unused_cycles_count(const VKImageInfo &info)
VKResourceWithHandle< VkImage > get_or_create(const VKImageInfo &info)
Vector< VKImageView > take_image_views(const VKImageInfo &info)
void store_image_views(const VKImageInfo &info, Vector< VKImageView > image_views)
void reset(bool force_reset=false)
void discard_all_of(VmaAllocation allocation)
Texture * acquire_texture_impl(int3 extent, int mip_len, GPUTextureType type, TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const char *name=nullptr) override
void release_texture(Texture *texture) override
void reset(bool force_free=false) override
void offset_users_count(Texture *texture, int offset) override
TextureFormat device_format_get() const
VkImage vk_image_handle() const
VKTexture(const char *name)
Definition vk_texture.hh:81
ResourceHandle add_aliased_image(VkImage vk_image, bool use_subresource_tracking, VmaAllocation allocation=VK_NULL_HANDLE, const char *name=nullptr)
Register an image resource that can have aliased memory.
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
#define LOG(level)
Definition log.h:97
Segment< FEdge *, Vec3r > segment
constexpr auto tie(const VkImageCreateInfo &info)
void object_label(GLenum type, GLuint object, const char *name)
Definition gl_debug.cc:331
static VKResourceWithHandle< VkImage > create_and_bind_vk_image(const VKImageInfo &info, const std::string &name_str)
VkImageUsageFlags to_vk_image_usage(const eGPUTextureUsage usage, const GPUTextureFormatFlag format_flag, bool use_image_host_copy)
Definition vk_common.cc:893
VkImageType to_vk_image_type(const GPUTextureType type)
Definition vk_common.cc:496
VkFormat to_vk_format(const TextureFormat format)
Definition vk_common.cc:157
VkImageCreateFlags to_vk_image_create(const GPUTextureType texture_type, const GPUTextureFormatFlag format_flag, eGPUTextureUsage usage)
Definition vk_common.cc:864
BLI_INLINE MTLTexture * unwrap(Texture *tex)
uint64_t ResourceHandle
Definition vk_common.hh:68
VkImageAspectFlags to_vk_image_aspect_flag_bits(const TextureFormat format)
Definition vk_common.cc:16
BLI_INLINE Texture * wrap(MTLTexture *texture)
VkMemoryRequirements get_image_memory_requirements(const VkImageCreateInfo &image_info)
GPUTextureFormatFlag to_format_flag(TextureFormat format)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
@ GPU_SAMPLER_FILTERING_LINEAR
MINLINE int max_ii(int a, int b)
@ GPU_DRIVER_OPENSOURCE
Global G
Definition blender.cc:57
unsigned int uint32_t
Definition BKE_text.h:81
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
VecBase< int32_t, 3 > int3
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b)
static CLG_LogRef LOG
Definition logging.cpp:12
MINLINE int min_ii(int a, int b)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
#define floorf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
constexpr uint64_t operator()(const VkImageCreateInfo &value) const
VkImageCreateInfo create_info
bool operator==(const VKImageInfo &) const