Files
test2/source/blender/gpu/vulkan/vk_shader_module.cc
Jeroen Bakker 791f90ab8d Vulkan: Remove guardedalloc option
WITH_VULKAN_GUARDEDALLOC is a development option to use Blenders guarded
allocator when allocating internal vulkan driver resources. It does not provide any benefits
as this should be covered by vulkan validation and drivers are often ignoring this. This
change will remove the option from cmake and source code.

Pull Request: https://projects.blender.org/blender/blender/pulls/129039
2024-10-15 13:46:00 +02:00

65 lines
1.8 KiB
C++

/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#include "vk_shader_module.hh"
#include "vk_backend.hh"
#include "vk_shader.hh"
#include <iomanip>
#include <sstream>
namespace blender::gpu {
VKShaderModule::~VKShaderModule()
{
VKDevice &device = VKBackend::get().device;
VKDiscardPool &discard_pool = device.discard_pool_for_current_thread();
if (vk_shader_module != VK_NULL_HANDLE) {
discard_pool.discard_shader_module(vk_shader_module);
vk_shader_module = VK_NULL_HANDLE;
}
}
void VKShaderModule::finalize(StringRefNull name)
{
BLI_assert(vk_shader_module == VK_NULL_HANDLE);
if (compilation_result.GetCompilationStatus() != shaderc_compilation_status_success &&
spirv_binary.is_empty())
{
return;
}
VkShaderModuleCreateInfo create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
if (!spirv_binary.is_empty()) {
create_info.codeSize = spirv_binary.size() * sizeof(uint32_t);
create_info.pCode = spirv_binary.data();
}
else {
create_info.codeSize = (compilation_result.end() - compilation_result.begin()) *
sizeof(uint32_t);
create_info.pCode = compilation_result.begin();
}
const VKDevice &device = VKBackend::get().device;
vkCreateShaderModule(device.vk_handle(), &create_info, nullptr, &vk_shader_module);
debug::object_label(vk_shader_module, name.c_str());
}
void VKShaderModule::build_sources_hash()
{
DefaultHash<std::string> hasher;
BLI_assert(!combined_sources.empty());
uint64_t hash = hasher(combined_sources);
std::stringstream ss;
ss << std::setfill('0') << std::setw(sizeof(uint64_t) * 2) << std::hex << hash;
sources_hash = ss.str();
BLI_assert(!sources_hash.empty());
}
} // namespace blender::gpu