2023-09-20 10:47:42 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2020-09-12 04:52:18 +00:00
|
|
|
#pragma once
|
2023-08-13 06:28:28 +00:00
|
|
|
|
2023-08-13 03:42:02 +00:00
|
|
|
#include "gpu_device.h"
|
2023-08-13 06:28:28 +00:00
|
|
|
|
2020-09-12 04:52:18 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class ShaderGen
|
|
|
|
{
|
|
|
|
public:
|
2023-09-20 10:47:42 +00:00
|
|
|
ShaderGen(RenderAPI render_api, bool supports_dual_source_blend, bool supports_framebuffer_fetch);
|
2020-09-12 04:52:18 +00:00
|
|
|
~ShaderGen();
|
|
|
|
|
|
|
|
static bool UseGLSLBindingLayout();
|
|
|
|
|
|
|
|
std::string GenerateScreenQuadVertexShader();
|
2020-12-30 06:26:20 +00:00
|
|
|
std::string GenerateUVQuadVertexShader();
|
2020-09-12 04:52:18 +00:00
|
|
|
std::string GenerateFillFragmentShader();
|
|
|
|
std::string GenerateCopyFragmentShader();
|
2023-08-13 03:42:02 +00:00
|
|
|
|
|
|
|
std::string GenerateImGuiVertexShader();
|
|
|
|
std::string GenerateImGuiFragmentShader();
|
2020-09-12 04:52:18 +00:00
|
|
|
|
|
|
|
protected:
|
2022-08-26 11:59:45 +00:00
|
|
|
ALWAYS_INLINE bool IsVulkan() const { return (m_render_api == RenderAPI::Vulkan); }
|
2023-08-13 03:42:02 +00:00
|
|
|
ALWAYS_INLINE bool IsMetal() const { return (m_render_api == RenderAPI::Metal); }
|
2020-09-12 04:52:18 +00:00
|
|
|
|
2020-10-31 05:20:06 +00:00
|
|
|
const char* GetInterpolationQualifier(bool interface_block, bool centroid_interpolation, bool sample_interpolation,
|
|
|
|
bool is_out) const;
|
|
|
|
|
2023-09-17 02:28:11 +00:00
|
|
|
#ifdef ENABLE_OPENGL
|
2020-09-12 04:52:18 +00:00
|
|
|
void SetGLSLVersionString();
|
2022-07-30 15:06:40 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-12 04:52:18 +00:00
|
|
|
void DefineMacro(std::stringstream& ss, const char* name, bool enabled);
|
2023-09-20 10:47:42 +00:00
|
|
|
void DefineMacro(std::stringstream& ss, const char* name, s32 value);
|
2020-09-12 04:52:18 +00:00
|
|
|
void WriteHeader(std::stringstream& ss);
|
2020-09-12 15:19:57 +00:00
|
|
|
void WriteUniformBufferDeclaration(std::stringstream& ss, bool push_constant_on_vulkan);
|
2020-09-12 04:52:18 +00:00
|
|
|
void DeclareUniformBuffer(std::stringstream& ss, const std::initializer_list<const char*>& members,
|
|
|
|
bool push_constant_on_vulkan);
|
2023-12-18 15:40:45 +00:00
|
|
|
void DeclareTexture(std::stringstream& ss, const char* name, u32 index, bool multisampled = false,
|
|
|
|
bool is_int = false, bool is_unsigned = false);
|
2020-09-12 04:52:18 +00:00
|
|
|
void DeclareTextureBuffer(std::stringstream& ss, const char* name, u32 index, bool is_int, bool is_unsigned);
|
|
|
|
void DeclareVertexEntryPoint(std::stringstream& ss, const std::initializer_list<const char*>& attributes,
|
|
|
|
u32 num_color_outputs, u32 num_texcoord_outputs,
|
|
|
|
const std::initializer_list<std::pair<const char*, const char*>>& additional_outputs,
|
2020-10-30 14:38:06 +00:00
|
|
|
bool declare_vertex_id = false, const char* output_block_suffix = "", bool msaa = false,
|
2022-10-03 10:03:30 +00:00
|
|
|
bool ssaa = false, bool noperspective_color = false);
|
2020-09-12 04:52:18 +00:00
|
|
|
void DeclareFragmentEntryPoint(std::stringstream& ss, u32 num_color_inputs, u32 num_texcoord_inputs,
|
|
|
|
const std::initializer_list<std::pair<const char*, const char*>>& additional_inputs,
|
2020-10-30 14:38:06 +00:00
|
|
|
bool declare_fragcoord = false, u32 num_color_outputs = 1, bool depth_output = false,
|
2022-10-03 10:03:30 +00:00
|
|
|
bool msaa = false, bool ssaa = false, bool declare_sample_id = false,
|
2023-09-20 10:47:42 +00:00
|
|
|
bool noperspective_color = false, bool framebuffer_fetch = false);
|
2020-09-12 04:52:18 +00:00
|
|
|
|
2022-08-26 11:59:45 +00:00
|
|
|
RenderAPI m_render_api;
|
2020-09-12 04:52:18 +00:00
|
|
|
bool m_glsl;
|
2023-08-13 03:42:02 +00:00
|
|
|
bool m_spirv;
|
2020-09-12 04:52:18 +00:00
|
|
|
bool m_supports_dual_source_blend;
|
2023-09-20 10:47:42 +00:00
|
|
|
bool m_supports_framebuffer_fetch;
|
2020-09-12 04:52:18 +00:00
|
|
|
bool m_use_glsl_interface_blocks;
|
|
|
|
bool m_use_glsl_binding_layout;
|
2023-08-13 03:42:02 +00:00
|
|
|
bool m_has_uniform_buffer = false;
|
2020-09-12 04:52:18 +00:00
|
|
|
|
|
|
|
std::string m_glsl_version_string;
|
|
|
|
};
|