Refactored the shader loading.
This commit is contained in:
parent
35198bce6b
commit
61931083c6
2 changed files with 58 additions and 52 deletions
|
|
@ -410,8 +410,41 @@ void VulkanEngine::init_descriptors() {
|
||||||
void VulkanEngine::init_pipelines()
|
void VulkanEngine::init_pipelines()
|
||||||
{
|
{
|
||||||
init_background_pipelines();
|
init_background_pipelines();
|
||||||
|
init_shaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanEngine::load_shader(const char *file_name, const char *entry_point, ComputeEffect sky) {
|
||||||
|
VkShaderModule skyShader;
|
||||||
|
bool good = vkutil::load_shader_module(file_name, _device, &skyShader);
|
||||||
|
assert(good && "failed to load shader");
|
||||||
|
|
||||||
|
VkPipelineShaderStageCreateInfo stageinfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
|
.stage = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||||
|
.module = skyShader,
|
||||||
|
.pName = entry_point,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkComputePipelineCreateInfo computePipelineCreateInfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
|
||||||
|
.stage = stageinfo,
|
||||||
|
.layout = _gradientPipelineLayout,
|
||||||
|
};
|
||||||
|
|
||||||
|
sky.layout = _gradientPipelineLayout;
|
||||||
|
|
||||||
|
VK_CHECK(vkCreateComputePipelines(_device, VK_NULL_HANDLE, 1, &computePipelineCreateInfo, nullptr, &sky.pipeline));
|
||||||
|
|
||||||
|
backgroundEffects.push_back(sky);
|
||||||
|
|
||||||
|
vkDestroyShaderModule(_device, skyShader, nullptr);
|
||||||
|
|
||||||
|
_mainDeletionQueue.push_function([=,this]() {
|
||||||
|
vkDestroyPipeline(_device, sky.pipeline, nullptr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void VulkanEngine::init_background_pipelines()
|
void VulkanEngine::init_background_pipelines()
|
||||||
{
|
{
|
||||||
VkPushConstantRange pushConstant{
|
VkPushConstantRange pushConstant{
|
||||||
|
|
@ -430,59 +463,28 @@ void VulkanEngine::init_background_pipelines()
|
||||||
|
|
||||||
VK_CHECK(vkCreatePipelineLayout(_device, &computeLayout, nullptr, &_gradientPipelineLayout));
|
VK_CHECK(vkCreatePipelineLayout(_device, &computeLayout, nullptr, &_gradientPipelineLayout));
|
||||||
|
|
||||||
VkShaderModule gradientShader;
|
// final cleanup
|
||||||
bool good = vkutil::load_shader_module("gradient_color.comp.spv", _device, &gradientShader);
|
_mainDeletionQueue.push_function([=,this]() {
|
||||||
assert(good && "failed to load gradient_color.comp.spv");
|
vkDestroyPipelineLayout(_device, _gradientPipelineLayout, nullptr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
VkShaderModule skyShader;
|
|
||||||
good = vkutil::load_shader_module("sky.comp.spv", _device, &skyShader);
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo stageinfo{
|
void VulkanEngine::init_shaders() {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
/// gradient shader
|
||||||
.stage = VK_SHADER_STAGE_COMPUTE_BIT,
|
load_shader("gradient_color.comp.spv", "main", {
|
||||||
.module = gradientShader,
|
|
||||||
.pName = "main",
|
|
||||||
};
|
|
||||||
|
|
||||||
VkComputePipelineCreateInfo computePipelineCreateInfo{
|
|
||||||
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
|
|
||||||
.stage = stageinfo,
|
|
||||||
.layout = _gradientPipelineLayout,
|
|
||||||
};
|
|
||||||
|
|
||||||
ComputeEffect gradient{
|
|
||||||
.name="gradient",
|
.name="gradient",
|
||||||
.layout = _gradientPipelineLayout,
|
|
||||||
.data={
|
.data={
|
||||||
.data1 = glm::vec4(1, 0, 0, 1),
|
.data1 = glm::vec4(1, 0, 0, 1),
|
||||||
.data2 = glm::vec4(0, 0, 1, 1),
|
.data2 = glm::vec4(0, 0, 1, 1),
|
||||||
},
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
|
load_shader("sky.comp.spv", "main", {
|
||||||
VK_CHECK(vkCreateComputePipelines(_device, VK_NULL_HANDLE, 1, &computePipelineCreateInfo, nullptr, &gradient.pipeline));
|
|
||||||
|
|
||||||
// change the shader module only to create the sky
|
|
||||||
computePipelineCreateInfo.stage.module = skyShader;
|
|
||||||
|
|
||||||
ComputeEffect sky{
|
|
||||||
.name="sky",
|
.name="sky",
|
||||||
.layout = _gradientPipelineLayout,
|
.data = {
|
||||||
.data{.data1 = glm::vec4(0.1, 0.2, 0.4, 0.97)},
|
.data1 = glm::vec4(0.1, 0.2, 0.4, 0.97)
|
||||||
};
|
}
|
||||||
|
|
||||||
VK_CHECK(vkCreateComputePipelines(_device, VK_NULL_HANDLE, 1, &computePipelineCreateInfo, nullptr, &sky.pipeline));
|
|
||||||
|
|
||||||
backgroundEffects.push_back(gradient);
|
|
||||||
backgroundEffects.push_back(sky);
|
|
||||||
|
|
||||||
vkDestroyShaderModule(_device, gradientShader, nullptr);
|
|
||||||
vkDestroyShaderModule(_device, skyShader, nullptr);
|
|
||||||
|
|
||||||
_mainDeletionQueue.push_function([=,this]() {
|
|
||||||
vkDestroyPipelineLayout(_device, _gradientPipelineLayout, nullptr);
|
|
||||||
vkDestroyPipeline(_device, sky.pipeline, nullptr);
|
|
||||||
vkDestroyPipeline(_device, sky.pipeline, nullptr);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,8 @@ public:
|
||||||
// imgui shader stuff
|
// imgui shader stuff
|
||||||
std::vector<ComputeEffect> backgroundEffects;
|
std::vector<ComputeEffect> backgroundEffects;
|
||||||
int currentBackgroundEffect{0};
|
int currentBackgroundEffect{0};
|
||||||
|
|
||||||
|
// ZED's REFACTOR
|
||||||
VkGUI _gui;
|
VkGUI _gui;
|
||||||
|
|
||||||
static VulkanEngine& Get();
|
static VulkanEngine& Get();
|
||||||
|
|
@ -114,6 +116,8 @@ private:
|
||||||
void init_descriptors();
|
void init_descriptors();
|
||||||
void init_pipelines();
|
void init_pipelines();
|
||||||
void init_background_pipelines();
|
void init_background_pipelines();
|
||||||
|
void init_shaders();
|
||||||
|
void load_shader(const char *file_name, const char *entry_point, ComputeEffect data);
|
||||||
|
|
||||||
void create_swapchain(uint32_t width, uint32_t height);
|
void create_swapchain(uint32_t width, uint32_t height);
|
||||||
void destroy_swapchain();
|
void destroy_swapchain();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue