[Bf-blender-cvs] [8b079a48889] temp-vulkan-descriptor-sets: Initial vk_shader_interface with SSBO support.
Jeroen Bakker
noreply at git.blender.org
Fri Feb 3 15:23:46 CET 2023
Commit: 8b079a48889f5f8f28d458cddbce75559fbca644
Author: Jeroen Bakker
Date: Thu Feb 2 12:58:14 2023 +0100
Branches: temp-vulkan-descriptor-sets
https://developer.blender.org/rB8b079a48889f5f8f28d458cddbce75559fbca644
Initial vk_shader_interface with SSBO support.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/vulkan/vk_shader.cc
A source/blender/gpu/vulkan/vk_shader_interface.cc
A source/blender/gpu/vulkan/vk_shader_interface.hh
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 0285e8e674c..44ec004f776 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -199,6 +199,7 @@ set(VULKAN_SRC
vulkan/vk_pixel_buffer.cc
vulkan/vk_query.cc
vulkan/vk_shader.cc
+ vulkan/vk_shader_interface.cc
vulkan/vk_shader_log.cc
vulkan/vk_storage_buffer.cc
vulkan/vk_texture.cc
@@ -216,6 +217,7 @@ set(VULKAN_SRC
vulkan/vk_pixel_buffer.hh
vulkan/vk_query.hh
vulkan/vk_shader.hh
+ vulkan/vk_shader_interface.hh
vulkan/vk_shader_log.hh
vulkan/vk_storage_buffer.hh
vulkan/vk_texture.hh
diff --git a/source/blender/gpu/vulkan/vk_shader.cc b/source/blender/gpu/vulkan/vk_shader.cc
index caaffd8f9ff..f9daf75dee4 100644
--- a/source/blender/gpu/vulkan/vk_shader.cc
+++ b/source/blender/gpu/vulkan/vk_shader.cc
@@ -8,6 +8,7 @@
#include "vk_shader.hh"
#include "vk_backend.hh"
+#include "vk_shader_interface.hh"
#include "vk_shader_log.hh"
#include "BLI_string_utils.h"
@@ -652,19 +653,27 @@ bool VKShader::finalize(const shader::ShaderCreateInfo *info)
/* TODO we might need to move the actual pipeline construction to a later stage as the graphics
* pipeline requires more data before it can be constructed.*/
const bool is_graphics_shader = vertex_module_ != VK_NULL_HANDLE;
+ bool result;
if (is_graphics_shader) {
BLI_assert((fragment_module_ != VK_NULL_HANDLE && info->tf_type_ == GPU_SHADER_TFB_NONE) ||
(fragment_module_ == VK_NULL_HANDLE && info->tf_type_ != GPU_SHADER_TFB_NONE));
BLI_assert(compute_module_ == VK_NULL_HANDLE);
- return finalize_graphics_pipeline(vk_device);
+ result = finalize_graphics_pipeline(vk_device);
}
else {
BLI_assert(vertex_module_ == VK_NULL_HANDLE);
BLI_assert(geometry_module_ == VK_NULL_HANDLE);
BLI_assert(fragment_module_ == VK_NULL_HANDLE);
BLI_assert(compute_module_ != VK_NULL_HANDLE);
- return bake_compute_pipeline(vk_device);
+ result = bake_compute_pipeline(vk_device);
}
+
+ if (result) {
+ VKShaderInterface *vk_interface = new VKShaderInterface();
+ vk_interface->init(*info);
+ interface = vk_interface;
+ }
+ return result;
}
bool VKShader::finalize_graphics_pipeline(VkDevice /*vk_device */)
diff --git a/source/blender/gpu/vulkan/vk_shader_interface.cc b/source/blender/gpu/vulkan/vk_shader_interface.cc
new file mode 100644
index 00000000000..00dbbf7820d
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_shader_interface.cc
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2023 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#include "vk_shader_interface.hh"
+
+namespace blender::gpu {
+
+void VKShaderInterface::init(const shader::ShaderCreateInfo &info)
+{
+ using namespace blender::gpu::shader;
+
+ ssbo_len_ = 0;
+
+ Vector<ShaderCreateInfo::Resource> all_resources;
+ all_resources.extend(info.pass_resources_);
+ all_resources.extend(info.batch_resources_);
+
+ for (ShaderCreateInfo::Resource &res : all_resources) {
+ switch (res.bind_type) {
+ case ShaderCreateInfo::Resource::BindType::IMAGE:
+ case ShaderCreateInfo::Resource::BindType::SAMPLER:
+ case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
+ // BLI_assert_msg(false, "not implemented yet");
+ break;
+ case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
+ ssbo_len_++;
+ break;
+ }
+ }
+
+ int32_t input_tot_len = ssbo_len_;
+ inputs_ = static_cast<ShaderInput *>(
+ MEM_calloc_arrayN(input_tot_len, sizeof(ShaderInput), __func__));
+ ShaderInput *input = inputs_;
+
+ name_buffer_ = (char *)MEM_mallocN(info.interface_names_size_, "name_buffer");
+ uint32_t name_buffer_offset = 0;
+
+ for (const ShaderCreateInfo::Resource &res : all_resources) {
+ if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
+ copy_input_name(input, res.storagebuf.name, name_buffer_, name_buffer_offset);
+ input->location = input->binding = res.slot;
+ enabled_ssbo_mask_ |= (1 << input->binding);
+ input++;
+ }
+ }
+
+ sort_inputs();
+}
+
+} // namespace blender::gpu
diff --git a/source/blender/gpu/vulkan/vk_shader_interface.hh b/source/blender/gpu/vulkan/vk_shader_interface.hh
new file mode 100644
index 00000000000..f741a0b133e
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_shader_interface.hh
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2023 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#pragma once
+
+#include "gpu_shader_create_info.hh"
+#include "gpu_shader_interface.hh"
+
+namespace blender::gpu {
+class VKShaderInterface : public ShaderInterface {
+ public:
+ VKShaderInterface() = default;
+
+ void init(const shader::ShaderCreateInfo &info);
+};
+} // namespace blender::gpu
More information about the Bf-blender-cvs
mailing list