5#include "GraphicsDeviceVK.h"
12 VkShaderModule prepareShader(VkDevice device,
const void * data,
const size_t size)
14 VkShaderModuleCreateInfo moduleCreateInfo;
15 VkShaderModule module;
18 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
19 moduleCreateInfo.pNext =
nullptr;
21 moduleCreateInfo.codeSize = size;
22 moduleCreateInfo.pCode =
reinterpret_cast<const uint32_t *
>(data);
23 moduleCreateInfo.flags = 0;
25 err = vkCreateShaderModule(device, &moduleCreateInfo,
nullptr, &module);
33void Cogs::EffectsVK::initialize(GraphicsDeviceVK * graphicsDevice)
35 this->graphicsDevice = graphicsDevice;
37 EffectsCommon::initialize(graphicsDevice->getBuffers());
58bool Cogs::EffectsVK::initializeEffectLayout(
EffectVK & effect)
60 const VkDescriptorType slotTypes[] = {
61 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
62 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
63 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
64 VK_DESCRIPTOR_TYPE_SAMPLER
67 const VkShaderStageFlagBits shaderTypes[] = {
68 VK_SHADER_STAGE_VERTEX_BIT,
69 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
70 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
71 VK_SHADER_STAGE_GEOMETRY_BIT,
72 VK_SHADER_STAGE_FRAGMENT_BIT,
75 Shader * shaders[] = {
79 &effect.geometryShader,
83 for (
size_t j = 0; j < ShaderType::NumShaderTypes; ++j) {
84 std::vector<VkDescriptorSetLayoutBinding> layoutBindings;
87 for (
size_t i = 0; i < SlotType::NumSlotTypes - 1; ++i) {
88 auto slots = effect.signature.slots[i].values[j];
91 for (
size_t k = 0; k < slots; ++k) {
92 const VkDescriptorSetLayoutBinding layoutBinding = {
96 static_cast<VkShaderStageFlags
>(shaderTypes[j]),
100 layoutBindings.push_back(layoutBinding);
105 if (!layoutBindings.size())
continue;
107 const VkDescriptorSetLayoutCreateInfo descriptorLayoutInfo = {
108 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
111 static_cast<uint32_t
>(layoutBindings.size()),
112 layoutBindings.data(),
115 VkDescriptorSetLayout descriptorSetLayout;
117 auto result = vkCreateDescriptorSetLayout(graphicsDevice->device, &descriptorLayoutInfo,
nullptr, &descriptorSetLayout);
119 if (result != VK_SUCCESS) {
120 LOG_ERROR(logger,
"Error creating descriptor set layout.");
124 effect.descriptorSetLayouts.push_back(descriptorSetLayout);
127 const VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = {
128 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
131 static_cast<uint32_t
>(effect.descriptorSetLayouts.size()),
132 effect.descriptorSetLayouts.data(),
137 auto result = vkCreatePipelineLayout(graphicsDevice->device, &pipelineLayoutCreateInfo,
nullptr, &effect.pipelineLayout);
139 if (result != VK_SUCCESS) {
140 LOG_ERROR(logger,
"Error creating pipeline layout.");
148 const ProcessedContent & vsSource,
149 const ProcessedContent & hsSource,
150 const ProcessedContent & dsSource,
151 const ProcessedContent & gsSource,
152 const ProcessedContent & psSource,
153 const StringView & vsEntryPoint,
154 const StringView & hsEntryPoint,
155 const StringView & dsEntryPoint,
156 const StringView & gsEntryPoint,
157 const StringView & psEntryPoint,
158 const EffectDescription & desc)
EffectHandle loadComputeEffect(const StringView &fileName, EffectFlags::EEffectFlags effectFlags=EffectFlags::None) override
Load the compute shader with the given file name and create an effect.
void releaseEffect(EffectHandle effectHandle) override
Release the effect with the given handle, freeing all resources generated during program loading.
void releaseResources() override
Release all allocated effect resources.
Log implementation class.
Provides a weakly referenced view over the contents of a string.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
std::vector< PreprocessorDefinition > PreprocessorDefinitions
A set of preprocessor definitions.
EEffectFlags
Effect source flags.
static const Handle_t NoHandle
Represents a handle to nothing.