Add Vulkan GLSL shader compilation path
This commit is contained in:
@@ -8,12 +8,22 @@
|
||||
|
||||
#include "XCEngine/RHI/RHIEnums.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
inline std::string NarrowAscii(const std::wstring& value) {
|
||||
std::string result;
|
||||
result.reserve(value.size());
|
||||
for (wchar_t ch : value) {
|
||||
result.push_back(static_cast<char>(ch));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline std::wstring WidenAscii(const char* value) {
|
||||
if (value == nullptr) {
|
||||
return {};
|
||||
@@ -23,6 +33,42 @@ inline std::wstring WidenAscii(const char* value) {
|
||||
return std::wstring(ascii.begin(), ascii.end());
|
||||
}
|
||||
|
||||
inline bool TryResolveShaderTypeFromTarget(const char* target, ShaderType& type) {
|
||||
if (target == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (std::strstr(target, "vs_") != nullptr || std::strcmp(target, "vs") == 0) {
|
||||
type = ShaderType::Vertex;
|
||||
return true;
|
||||
}
|
||||
if (std::strstr(target, "ps_") != nullptr ||
|
||||
std::strstr(target, "fs_") != nullptr ||
|
||||
std::strcmp(target, "ps") == 0 ||
|
||||
std::strcmp(target, "fs") == 0) {
|
||||
type = ShaderType::Fragment;
|
||||
return true;
|
||||
}
|
||||
if (std::strstr(target, "gs_") != nullptr || std::strcmp(target, "gs") == 0) {
|
||||
type = ShaderType::Geometry;
|
||||
return true;
|
||||
}
|
||||
if (std::strstr(target, "hs_") != nullptr || std::strcmp(target, "hs") == 0) {
|
||||
type = ShaderType::TessControl;
|
||||
return true;
|
||||
}
|
||||
if (std::strstr(target, "ds_") != nullptr || std::strcmp(target, "ds") == 0) {
|
||||
type = ShaderType::TessEvaluation;
|
||||
return true;
|
||||
}
|
||||
if (std::strstr(target, "cs_") != nullptr || std::strcmp(target, "cs") == 0) {
|
||||
type = ShaderType::Compute;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline VkFormat ToVulkanFormat(Format format) {
|
||||
switch (format) {
|
||||
case Format::R8G8B8A8_UNorm:
|
||||
|
||||
23
engine/include/XCEngine/RHI/Vulkan/VulkanShaderCompiler.h
Normal file
23
engine/include/XCEngine/RHI/Vulkan/VulkanShaderCompiler.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "XCEngine/RHI/RHITypes.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
struct VulkanCompiledShader {
|
||||
std::vector<uint32_t> spirvWords;
|
||||
ShaderType type = ShaderType::Vertex;
|
||||
std::string entryPoint;
|
||||
};
|
||||
|
||||
bool CompileVulkanShader(const ShaderCompileDesc& desc,
|
||||
VulkanCompiledShader& outShader,
|
||||
std::string* errorMessage = nullptr);
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user