2023-11-01 23:12:30 +01:00
|
|
|
#include "Shader.h"
|
|
|
|
|
#include "Graphics.h"
|
2024-04-12 09:27:30 +02:00
|
|
|
#include "Graphics/slang-compile.h"
|
2022-11-15 12:19:11 +01:00
|
|
|
#include "slang-com-ptr.h"
|
2024-06-09 12:20:04 +02:00
|
|
|
#include "slang.h"
|
2021-10-15 23:12:29 +02:00
|
|
|
#include "stdlib.h"
|
2024-01-16 21:11:57 +01:00
|
|
|
#include <fmt/core.h>
|
2020-05-05 01:51:13 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
2020-06-02 11:46:18 +02:00
|
|
|
using namespace Seele::Vulkan;
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
Shader::Shader(PGraphics graphics, VkShaderStageFlags stage) : graphics(graphics), stage(stage) {}
|
2020-06-02 11:46:18 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
Shader::~Shader() {
|
|
|
|
|
if (module != VK_NULL_HANDLE) {
|
2020-06-02 11:46:18 +02:00
|
|
|
vkDestroyShaderModule(graphics->getDevice(), module, nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
uint32 Seele::Vulkan::Shader::getShaderHash() const { return hash; }
|
2020-10-30 18:45:35 +01:00
|
|
|
|
2024-07-10 21:07:10 +02:00
|
|
|
void Shader::create(const ShaderCreateInfo& createInfo) {
|
2024-07-12 13:33:52 +02:00
|
|
|
auto [kernelBlob, entryName] = generateShader(createInfo);
|
|
|
|
|
entryPointName = entryName;
|
2024-06-09 12:20:04 +02:00
|
|
|
VkShaderModuleCreateInfo moduleInfo = {
|
2023-11-10 19:18:09 +01:00
|
|
|
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
|
|
|
|
.pNext = nullptr,
|
|
|
|
|
.flags = 0,
|
|
|
|
|
.codeSize = kernelBlob->getBufferSize(),
|
|
|
|
|
.pCode = (uint32_t*)kernelBlob->getBufferPointer(),
|
|
|
|
|
};
|
2023-11-09 22:15:51 +01:00
|
|
|
VK_CHECK(vkCreateShaderModule(graphics->getDevice(), &moduleInfo, nullptr, &module));
|
2020-10-30 18:45:35 +01:00
|
|
|
|
2022-11-22 22:11:37 +01:00
|
|
|
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
|
2020-06-02 11:46:18 +02:00
|
|
|
}
|