Vulkan: Push constants #104880

Merged
Jeroen Bakker merged 73 commits from Jeroen-Bakker/blender:vulkan-push-constants into main 2023-03-06 12:29:06 +01:00
6 changed files with 32 additions and 12 deletions
Showing only changes of commit 8b6db40ccc - Show all commits

View File

@ -7,6 +7,7 @@
#include "vk_command_buffer.hh"
#include "vk_context.hh"
#include "vk_memory.hh"
#include "BLI_assert.h"
@ -15,7 +16,8 @@ namespace blender::gpu {
VKCommandBuffer::~VKCommandBuffer()
{
if (vk_device_ != VK_NULL_HANDLE) {
vkDestroyFence(vk_device_, vk_fence_, nullptr);
VK_ALLOCATION_CALLBACKS;
vkDestroyFence(vk_device_, vk_fence_, vk_allocation_callbacks);
vk_fence_ = VK_NULL_HANDLE;
}
}
@ -29,10 +31,11 @@ void VKCommandBuffer::init(const VkDevice vk_device,
vk_command_buffer_ = vk_command_buffer;
if (vk_fence_ == VK_NULL_HANDLE) {
VK_ALLOCATION_CALLBACKS;
VkFenceCreateInfo fenceInfo{};
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
vkCreateFence(vk_device_, &fenceInfo, nullptr, &vk_fence_);
vkCreateFence(vk_device_, &fenceInfo, vk_allocation_callbacks, &vk_fence_);
}
}

View File

@ -8,6 +8,7 @@
#include "vk_context.hh"
#include "vk_backend.hh"
#include "vk_memory.hh"
#include "vk_state_manager.hh"
#include "GHOST_C-api.h"
@ -16,6 +17,7 @@ namespace blender::gpu {
VKContext::VKContext(void *ghost_window, void *ghost_context)
{
VK_ALLOCATION_CALLBACKS;
ghost_window_ = ghost_window;
if (ghost_window) {
ghost_context = GHOST_GetDrawingContext((GHOST_WindowHandle)ghost_window);
@ -38,6 +40,7 @@ VKContext::VKContext(void *ghost_window, void *ghost_context)
info.physicalDevice = vk_physical_device_;
info.device = vk_device_;
info.instance = vk_instance_;
info.pAllocationCallbacks = vk_allocation_callbacks;
vmaCreateAllocator(&info, &mem_allocator_);
descriptor_pools_.init(vk_device_);

View File

@ -6,6 +6,7 @@
*/
#include "vk_descriptor_pools.hh"
#include "vk_memory.hh"
namespace blender::gpu {
VKDescriptorPools::VKDescriptorPools()
@ -14,9 +15,10 @@ VKDescriptorPools::VKDescriptorPools()
VKDescriptorPools::~VKDescriptorPools()
{
VK_ALLOCATION_CALLBACKS
for (const VkDescriptorPool vk_descriptor_pool : pools_) {
BLI_assert(vk_device_ != VK_NULL_HANDLE);
vkDestroyDescriptorPool(vk_device_, vk_descriptor_pool, nullptr);
vkDestroyDescriptorPool(vk_device_, vk_descriptor_pool, vk_allocation_callbacks);
}
vk_device_ = VK_NULL_HANDLE;
}
@ -35,6 +37,7 @@ void VKDescriptorPools::reset()
void VKDescriptorPools::add_new_pool()
{
VK_ALLOCATION_CALLBACKS
Vector<VkDescriptorPoolSize> pool_sizes = {
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, POOL_SIZE_UNIFORM_BUFFER},
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, POOL_SIZE_STORAGE_BUFFER},
@ -46,7 +49,8 @@ void VKDescriptorPools::add_new_pool()
pool_info.poolSizeCount = pool_sizes.size();
pool_info.pPoolSizes = pool_sizes.data();
VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
VkResult result = vkCreateDescriptorPool(vk_device_, &pool_info, nullptr, &descriptor_pool);
VkResult result = vkCreateDescriptorPool(
vk_device_, &pool_info, vk_allocation_callbacks, &descriptor_pool);
UNUSED_VARS(result);
pools_.append(descriptor_pool);
}

View File

@ -37,7 +37,9 @@ void *vk_memory_reallocation(void *user_data,
void vk_memory_free(void * /*user_data*/, void *memory)
{
MEM_freeN(memory);
if (memory != nullptr) {
MEM_freeN(memory);
}
}
#endif

View File

@ -7,6 +7,7 @@
#include "vk_pipeline.hh"
#include "vk_context.hh"
#include "vk_memory.hh"
namespace blender::gpu {
@ -18,9 +19,10 @@ VKPipeline::VKPipeline(VkPipeline vk_pipeline, VKDescriptorSet &&vk_descriptor_s
VKPipeline::~VKPipeline()
{
VK_ALLOCATION_CALLBACKS
VkDevice vk_device = VKContext::get()->device_get();
if (vk_pipeline_ != VK_NULL_HANDLE) {
vkDestroyPipeline(vk_device, vk_pipeline_, nullptr);
vkDestroyPipeline(vk_device, vk_pipeline_, vk_allocation_callbacks);
}
}
@ -29,6 +31,7 @@ VKPipeline VKPipeline::create_compute_pipeline(VKContext &context,
VkDescriptorSetLayout &descriptor_set_layout,
VkPipelineLayout &pipeline_layout)
{
VK_ALLOCATION_CALLBACKS
VkDevice vk_device = context.device_get();
VkComputePipelineCreateInfo pipeline_info = {};
pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
@ -42,7 +45,8 @@ VKPipeline VKPipeline::create_compute_pipeline(VKContext &context,
pipeline_info.stage.pName = "main";
VkPipeline pipeline;
if (vkCreateComputePipelines(vk_device, nullptr, 1, &pipeline_info, nullptr, &pipeline) !=
if (vkCreateComputePipelines(
vk_device, nullptr, 1, &pipeline_info, vk_allocation_callbacks, &pipeline) !=
VK_SUCCESS) {
return VKPipeline();
}

View File

@ -605,11 +605,11 @@ VKShader::~VKShader()
compute_module_ = VK_NULL_HANDLE;
}
if (pipeline_layout_ != VK_NULL_HANDLE) {
vkDestroyPipelineLayout(device, pipeline_layout_, nullptr);
vkDestroyPipelineLayout(device, pipeline_layout_, vk_allocation_callbacks);
pipeline_layout_ = VK_NULL_HANDLE;
}
if (layout_ != VK_NULL_HANDLE) {
vkDestroyDescriptorSetLayout(device, layout_, nullptr);
vkDestroyDescriptorSetLayout(device, layout_, vk_allocation_callbacks);
layout_ = VK_NULL_HANDLE;
}
}
@ -723,14 +723,15 @@ bool VKShader::finalize_graphics_pipeline(VkDevice /*vk_device */)
bool VKShader::finalize_pipeline_layout(VkDevice vk_device,
const shader::ShaderCreateInfo & /*info*/)
{
VK_ALLOCATION_CALLBACKS
VkPipelineLayoutCreateInfo pipeline_info = {};
pipeline_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipeline_info.flags = 0;
pipeline_info.setLayoutCount = 1;
pipeline_info.pSetLayouts = &layout_;
if (vkCreatePipelineLayout(vk_device, &pipeline_info, nullptr, &pipeline_layout_) !=
VK_SUCCESS) {
if (vkCreatePipelineLayout(
vk_device, &pipeline_info, vk_allocation_callbacks, &pipeline_layout_) != VK_SUCCESS) {
return false;
};
@ -797,6 +798,8 @@ bool VKShader::finalize_descriptor_set_layouts(VkDevice vk_device,
return true;
}
VK_ALLOCATION_CALLBACKS
/* Currently we create a single descriptor set. The goal would be to create one descriptor set
* for Frequency::PASS/BATCH. This isn't possible as areas expect that the binding location is
* static and predictable (eevee-next) or the binding location can be mapped to a single number
@ -808,7 +811,8 @@ bool VKShader::finalize_descriptor_set_layouts(VkDevice vk_device,
Vector<VkDescriptorSetLayoutBinding> bindings;
VkDescriptorSetLayoutCreateInfo layout_info = create_descriptor_set_layout(all_resources,
bindings);
if (vkCreateDescriptorSetLayout(vk_device, &layout_info, nullptr, &layout_) != VK_SUCCESS) {
if (vkCreateDescriptorSetLayout(vk_device, &layout_info, vk_allocation_callbacks, &layout_) !=
VK_SUCCESS) {
return false;
};