mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
more comfortable way to initialize shader
This commit is contained in:
parent
2717f02f0f
commit
d3f5d87d61
3 changed files with 17 additions and 23 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "device.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <string>
|
||||
|
|
@ -30,7 +31,7 @@ namespace Vulkan::Core {
|
|||
/// @throws ls::vulkan_error if object creation fails.
|
||||
///
|
||||
ShaderModule(const Device& device, const std::string& path,
|
||||
std::vector<VkDescriptorType> descriptorTypes);
|
||||
const std::vector<std::pair<size_t, VkDescriptorType>>& descriptorTypes);
|
||||
|
||||
/// Get the Vulkan handle.
|
||||
[[nodiscard]] auto handle() const { return *this->shaderModule; }
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
using namespace Vulkan::Core;
|
||||
|
||||
ShaderModule::ShaderModule(const Device& device, const std::string& path,
|
||||
std::vector<VkDescriptorType> descriptorTypes) {
|
||||
const std::vector<std::pair<size_t, VkDescriptorType>>& descriptorTypes) {
|
||||
if (!device)
|
||||
throw std::invalid_argument("Invalid Vulkan device");
|
||||
|
||||
|
|
@ -46,14 +46,16 @@ ShaderModule::ShaderModule(const Device& device, const std::string& path,
|
|||
);
|
||||
|
||||
// create descriptor set layout
|
||||
std::vector<VkDescriptorSetLayoutBinding> layoutBindings(descriptorTypes.size());
|
||||
for (size_t i = 0; i < descriptorTypes.size(); ++i)
|
||||
layoutBindings.at(i) = {
|
||||
.binding = static_cast<uint32_t>(i),
|
||||
.descriptorType = descriptorTypes.at(i),
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT
|
||||
};
|
||||
std::vector<VkDescriptorSetLayoutBinding> layoutBindings;
|
||||
size_t bindIdx = 0;
|
||||
for (const auto &[count, type] : descriptorTypes)
|
||||
for (size_t i = 0; i < count; i++, bindIdx++)
|
||||
layoutBindings.emplace_back(VkDescriptorSetLayoutBinding {
|
||||
.binding = static_cast<uint32_t>(bindIdx),
|
||||
.descriptorType = type,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT
|
||||
});
|
||||
|
||||
const VkDescriptorSetLayoutCreateInfo layoutDesc{
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||
|
|
|
|||
17
src/main.cpp
17
src/main.cpp
|
|
@ -11,19 +11,10 @@ int main() {
|
|||
const Vulkan::Device device(instance);
|
||||
|
||||
const Vulkan::Core::ShaderModule computeShader(device, "shaders/downsample.spv",
|
||||
{
|
||||
VK_DESCRIPTOR_TYPE_SAMPLER,
|
||||
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
|
||||
}
|
||||
);
|
||||
{ { 1, VK_DESCRIPTOR_TYPE_SAMPLER},
|
||||
{ 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE},
|
||||
{ 7, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE},
|
||||
{ 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER} });
|
||||
const Vulkan::Core::Pipeline computePipeline(device, computeShader);
|
||||
|
||||
std::cerr << "Application finished" << '\n';
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue