You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Add shader baker to project exporter.
Metal Support contributed by Migeran (https://migeran.com) and Stuart Carnie. Co-authored-by: Stuart Carnie <stuart.carnie@gmail.com> Co-authored-by: Gergely Kis <gergely.kis@migeran.com>
This commit is contained in:
@@ -33,8 +33,39 @@
|
||||
#include "core/object/object.h"
|
||||
#include "core/variant/type_info.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define STEPIFY(m_number, m_alignment) ((((m_number) + ((m_alignment) - 1)) / (m_alignment)) * (m_alignment))
|
||||
|
||||
// This may one day be used in Godot for interoperability between C arrays, Vector and LocalVector.
|
||||
// (See https://github.com/godotengine/godot-proposals/issues/5144.)
|
||||
template <typename T>
|
||||
class VectorView {
|
||||
const T *_ptr = nullptr;
|
||||
const uint32_t _size = 0;
|
||||
|
||||
public:
|
||||
const T &operator[](uint32_t p_index) {
|
||||
DEV_ASSERT(p_index < _size);
|
||||
return _ptr[p_index];
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ const T *ptr() const { return _ptr; }
|
||||
_ALWAYS_INLINE_ uint32_t size() const { return _size; }
|
||||
|
||||
VectorView() = default;
|
||||
VectorView(const T &p_ptr) :
|
||||
// With this one you can pass a single element very conveniently!
|
||||
_ptr(&p_ptr),
|
||||
_size(1) {}
|
||||
VectorView(const T *p_ptr, uint32_t p_size) :
|
||||
_ptr(p_ptr), _size(p_size) {}
|
||||
VectorView(const Vector<T> &p_lv) :
|
||||
_ptr(p_lv.ptr()), _size(p_lv.size()) {}
|
||||
VectorView(const LocalVector<T> &p_lv) :
|
||||
_ptr(p_lv.ptr()), _size(p_lv.size()) {}
|
||||
};
|
||||
|
||||
class RenderingDeviceCommons : public Object {
|
||||
////////////////////////////////////////////
|
||||
// PUBLIC STUFF
|
||||
@@ -549,6 +580,30 @@ public:
|
||||
SHADER_STAGE_COMPUTE_BIT = (1 << SHADER_STAGE_COMPUTE),
|
||||
};
|
||||
|
||||
enum ShaderLanguage {
|
||||
SHADER_LANGUAGE_GLSL,
|
||||
SHADER_LANGUAGE_HLSL,
|
||||
};
|
||||
|
||||
enum ShaderLanguageVersion {
|
||||
SHADER_LANGUAGE_VULKAN_VERSION_1_0 = (1 << 22),
|
||||
SHADER_LANGUAGE_VULKAN_VERSION_1_1 = (1 << 22) | (1 << 12),
|
||||
SHADER_LANGUAGE_VULKAN_VERSION_1_2 = (1 << 22) | (2 << 12),
|
||||
SHADER_LANGUAGE_VULKAN_VERSION_1_3 = (1 << 22) | (3 << 12),
|
||||
SHADER_LANGUAGE_VULKAN_VERSION_1_4 = (1 << 22) | (4 << 12),
|
||||
SHADER_LANGUAGE_OPENGL_VERSION_4_5_0 = 450,
|
||||
};
|
||||
|
||||
enum ShaderSpirvVersion {
|
||||
SHADER_SPIRV_VERSION_1_0 = (1 << 16),
|
||||
SHADER_SPIRV_VERSION_1_1 = (1 << 16) | (1 << 8),
|
||||
SHADER_SPIRV_VERSION_1_2 = (1 << 16) | (2 << 8),
|
||||
SHADER_SPIRV_VERSION_1_3 = (1 << 16) | (3 << 8),
|
||||
SHADER_SPIRV_VERSION_1_4 = (1 << 16) | (4 << 8),
|
||||
SHADER_SPIRV_VERSION_1_5 = (1 << 16) | (5 << 8),
|
||||
SHADER_SPIRV_VERSION_1_6 = (1 << 16) | (6 << 8),
|
||||
};
|
||||
|
||||
struct ShaderStageSPIRVData {
|
||||
ShaderStage shader_stage = SHADER_STAGE_MAX;
|
||||
Vector<uint8_t> spirv;
|
||||
@@ -951,13 +1006,13 @@ protected:
|
||||
|
||||
static uint32_t get_format_vertex_size(DataFormat p_format);
|
||||
|
||||
public:
|
||||
/****************/
|
||||
/**** SHADER ****/
|
||||
/****************/
|
||||
|
||||
static const char *SHADER_STAGE_NAMES[SHADER_STAGE_MAX];
|
||||
|
||||
public:
|
||||
struct ShaderUniform {
|
||||
UniformType type = UniformType::UNIFORM_TYPE_MAX;
|
||||
bool writable = false;
|
||||
@@ -995,21 +1050,20 @@ public:
|
||||
bool operator<(const ShaderSpecializationConstant &p_other) const { return constant_id < p_other.constant_id; }
|
||||
};
|
||||
|
||||
struct ShaderDescription {
|
||||
struct ShaderReflection {
|
||||
uint64_t vertex_input_mask = 0;
|
||||
uint32_t fragment_output_mask = 0;
|
||||
bool is_compute = false;
|
||||
bool has_multiview = false;
|
||||
uint32_t compute_local_size[3] = {};
|
||||
uint32_t push_constant_size = 0;
|
||||
|
||||
Vector<Vector<ShaderUniform>> uniform_sets;
|
||||
Vector<ShaderSpecializationConstant> specialization_constants;
|
||||
Vector<ShaderStage> stages;
|
||||
};
|
||||
|
||||
protected:
|
||||
struct ShaderReflection : public ShaderDescription {
|
||||
BitField<ShaderStage> stages = {};
|
||||
Vector<ShaderStage> stages_vector;
|
||||
BitField<ShaderStage> stages_bits = {};
|
||||
BitField<ShaderStage> push_constant_stages = {};
|
||||
};
|
||||
|
||||
static Error reflect_spirv(VectorView<ShaderStageSPIRVData> p_spirv, ShaderReflection &r_reflection);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user