Add query for shader language accepted by the current GFX api
This commit is contained in:
parent
80fd8a375b
commit
6db47e272f
7 changed files with 16 additions and 10 deletions
|
@ -2,7 +2,7 @@ set(CMAKE_FOLDER "GFX Backends")
|
|||
|
||||
add_library(GFX INTERFACE)
|
||||
target_include_directories(GFX INTERFACE public)
|
||||
target_link_libraries(GFX INTERFACE Utility)
|
||||
target_link_libraries(GFX INTERFACE Utility ShaderCompiler)
|
||||
|
||||
add_custom_target(GFXInterface SOURCES
|
||||
public/gfx.hpp
|
||||
|
|
|
@ -9,6 +9,7 @@ class GFXMetal : public GFX {
|
|||
public:
|
||||
bool is_supported() override;
|
||||
GFXContext required_context() override { return GFXContext::Metal; }
|
||||
ShaderLanguage accepted_shader_language() override { return ShaderLanguage::MSL; }
|
||||
const char* get_name() override;
|
||||
|
||||
bool supports_feature(const GFXFeature feature) override;
|
||||
|
|
|
@ -431,7 +431,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
{
|
||||
std::string vertex_src;
|
||||
if(info.shaders.vertex_path.empty()) {
|
||||
vertex_src = std::get<std::string>(info.shaders.vertex_src);
|
||||
vertex_src = info.shaders.vertex_src.as_string();
|
||||
} else {
|
||||
const auto vertex_path = utility::format("{}.msl", info.shaders.vertex_path);
|
||||
|
||||
|
@ -453,7 +453,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
{
|
||||
std::string fragment_src;
|
||||
if(info.shaders.fragment_path.empty()) {
|
||||
fragment_src = std::get<std::string>(info.shaders.fragment_src);
|
||||
fragment_src = info.shaders.fragment_src.as_string();
|
||||
} else {
|
||||
const auto fragment_path = utility::format("{}.msl", info.shaders.fragment_path);
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
#include "shadercompiler.hpp"
|
||||
|
||||
class GFXBuffer;
|
||||
class GFXPipeline;
|
||||
class GFXCommandBuffer;
|
||||
|
@ -145,7 +147,7 @@ struct GFXGraphicsPipelineCreateInfo {
|
|||
struct Shaders {
|
||||
std::string_view vertex_path, fragment_path;
|
||||
|
||||
std::variant<std::string, std::vector<uint32_t>> vertex_src, fragment_src;
|
||||
ShaderSource vertex_src, fragment_src;
|
||||
|
||||
GFXShaderConstants vertex_constants, fragment_constants;
|
||||
} shaders;
|
||||
|
@ -269,6 +271,7 @@ public:
|
|||
// check for runtime support
|
||||
virtual bool is_supported() { return false; }
|
||||
virtual GFXContext required_context() { return GFXContext::None; }
|
||||
virtual ShaderLanguage accepted_shader_language() {}
|
||||
virtual const char* get_name() { return nullptr; }
|
||||
|
||||
virtual bool supports_feature([[maybe_unused]] const GFXFeature feature) { return true; }
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
// generates static and skinned versions of the pipeline provided
|
||||
std::tuple<GFXPipeline*, GFXPipeline*> create_pipeline_permutations(GFXGraphicsPipelineCreateInfo& createInfo, bool positions_only = false);
|
||||
|
||||
std::variant<std::string, std::vector<uint32_t>> compile_material_fragment(Material& material, bool use_ibl = true);
|
||||
ShaderSource compile_material_fragment(Material& material, bool use_ibl = true);
|
||||
};
|
||||
|
||||
static MaterialCompiler material_compiler;
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
#include "string_utils.hpp"
|
||||
#include "shadercompiler.hpp"
|
||||
|
||||
std::variant<std::string, std::vector<uint32_t>> get_shader(std::string filename, bool skinned, bool cubemap) {
|
||||
ShaderSource get_shader(std::string filename, bool skinned, bool cubemap) {
|
||||
auto shader_file = file::open(file::internal_domain / filename);
|
||||
if(!shader_file.has_value()) {
|
||||
console::error(System::Renderer, "Failed to open shader file {}!", filename);
|
||||
return "";
|
||||
return {};
|
||||
}
|
||||
|
||||
ShaderStage stage;
|
||||
|
@ -27,7 +27,7 @@ std::variant<std::string, std::vector<uint32_t>> get_shader(std::string filename
|
|||
if(cubemap)
|
||||
options.add_definition("CUBEMAP");
|
||||
|
||||
return shader_compiler.compile(ShaderLanguage::GLSL, stage, shader_file->read_as_string(), ShaderLanguage::MSL, options)->source;
|
||||
return *shader_compiler.compile(ShaderLanguage::GLSL, stage, shader_file->read_as_string(), engine->get_gfx()->accepted_shader_language(), options);
|
||||
}
|
||||
|
||||
GFXPipeline* MaterialCompiler::create_static_pipeline(GFXGraphicsPipelineCreateInfo createInfo, bool positions_only, bool cubemap) {
|
||||
|
@ -184,7 +184,7 @@ layout(push_constant, binding = 0) uniform PushConstant {\n \
|
|||
int materialOffset;\n \
|
||||
};\n";
|
||||
|
||||
std::variant<std::string, std::vector<uint32_t>> MaterialCompiler::compile_material_fragment(Material& material, bool use_ibl) {
|
||||
ShaderSource MaterialCompiler::compile_material_fragment(Material& material, bool use_ibl) {
|
||||
walked_nodes.clear();
|
||||
|
||||
if(!render_options.enable_ibl)
|
||||
|
@ -387,5 +387,5 @@ std::variant<std::string, std::vector<uint32_t>> MaterialCompiler::compile_mater
|
|||
|
||||
src += "}\n";
|
||||
|
||||
return shader_compiler.compile(ShaderLanguage::GLSL, ShaderStage::Fragment, src, ShaderLanguage::MSL)->source;
|
||||
return *shader_compiler.compile(ShaderLanguage::GLSL, ShaderStage::Fragment, src, engine->get_gfx()->accepted_shader_language());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
|
||||
class ShaderSource {
|
||||
public:
|
||||
ShaderSource() {}
|
||||
ShaderSource(const ShaderSource& rhs) : source (rhs.source) {}
|
||||
ShaderSource(const std::string source_string) : source(source_string) {}
|
||||
ShaderSource(const std::vector<uint32_t> source_bytecode) : source(source_bytecode) {}
|
||||
|
||||
|
|
Reference in a new issue