Path: blob/master/servers/rendering/rendering_device_binds.h
21022 views
/**************************************************************************/1/* rendering_device_binds.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "servers/rendering/rendering_device.h"3334#define RD_SETGET(m_type, m_member) \35void set_##m_member(m_type p_##m_member) { \36base.m_member = p_##m_member; \37} \38m_type get_##m_member() const { \39return base.m_member; \40}4142#define RD_BIND(m_variant_type, m_class, m_member) \43ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_member); \44ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_member)), &m_class::get_##m_member); \45ADD_PROPERTY(PropertyInfo(m_variant_type, #m_member), "set_" _MKSTR(m_member), "get_" _MKSTR(m_member))4647#define RD_SETGET_SUB(m_type, m_sub, m_member) \48void set_##m_sub##_##m_member(m_type p_##m_member) { \49base.m_sub.m_member = p_##m_member; \50} \51m_type get_##m_sub##_##m_member() const { \52return base.m_sub.m_member; \53}5455#define RD_BIND_SUB(m_variant_type, m_class, m_sub, m_member) \56ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_sub##_##m_member); \57ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_sub) "_" _MKSTR(m_member)), &m_class::get_##m_sub##_##m_member); \58ADD_PROPERTY(PropertyInfo(m_variant_type, _MKSTR(m_sub) "_" _MKSTR(m_member)), "set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "get_" _MKSTR(m_sub) "_" _MKSTR(m_member))5960class RDTextureFormat : public RefCounted {61GDCLASS(RDTextureFormat, RefCounted)6263friend class RenderingDevice;64friend class RenderSceneBuffersRD;6566RD::TextureFormat base;6768public:69RD_SETGET(RD::DataFormat, format)70RD_SETGET(uint32_t, width)71RD_SETGET(uint32_t, height)72RD_SETGET(uint32_t, depth)73RD_SETGET(uint32_t, array_layers)74RD_SETGET(uint32_t, mipmaps)75RD_SETGET(RD::TextureType, texture_type)76RD_SETGET(RD::TextureSamples, samples)77RD_SETGET(BitField<RenderingDevice::TextureUsageBits>, usage_bits)78RD_SETGET(bool, is_resolve_buffer)79RD_SETGET(bool, is_discardable)8081void add_shareable_format(RD::DataFormat p_format) { base.shareable_formats.push_back(p_format); }82void remove_shareable_format(RD::DataFormat p_format) { base.shareable_formats.erase(p_format); }8384protected:85static void _bind_methods() {86RD_BIND(Variant::INT, RDTextureFormat, format);87RD_BIND(Variant::INT, RDTextureFormat, width);88RD_BIND(Variant::INT, RDTextureFormat, height);89RD_BIND(Variant::INT, RDTextureFormat, depth);90RD_BIND(Variant::INT, RDTextureFormat, array_layers);91RD_BIND(Variant::INT, RDTextureFormat, mipmaps);92RD_BIND(Variant::INT, RDTextureFormat, texture_type);93RD_BIND(Variant::INT, RDTextureFormat, samples);94RD_BIND(Variant::INT, RDTextureFormat, usage_bits);95RD_BIND(Variant::BOOL, RDTextureFormat, is_resolve_buffer);96RD_BIND(Variant::BOOL, RDTextureFormat, is_discardable);9798ClassDB::bind_method(D_METHOD("add_shareable_format", "format"), &RDTextureFormat::add_shareable_format);99ClassDB::bind_method(D_METHOD("remove_shareable_format", "format"), &RDTextureFormat::remove_shareable_format);100}101};102103class RDTextureView : public RefCounted {104GDCLASS(RDTextureView, RefCounted)105106friend class RenderingDevice;107friend class RenderSceneBuffersRD;108109RD::TextureView base;110111public:112RD_SETGET(RD::DataFormat, format_override)113RD_SETGET(RD::TextureSwizzle, swizzle_r)114RD_SETGET(RD::TextureSwizzle, swizzle_g)115RD_SETGET(RD::TextureSwizzle, swizzle_b)116RD_SETGET(RD::TextureSwizzle, swizzle_a)117protected:118static void _bind_methods() {119RD_BIND(Variant::INT, RDTextureView, format_override);120RD_BIND(Variant::INT, RDTextureView, swizzle_r);121RD_BIND(Variant::INT, RDTextureView, swizzle_g);122RD_BIND(Variant::INT, RDTextureView, swizzle_b);123RD_BIND(Variant::INT, RDTextureView, swizzle_a);124}125};126127class RDAttachmentFormat : public RefCounted {128GDCLASS(RDAttachmentFormat, RefCounted)129friend class RenderingDevice;130131RD::AttachmentFormat base;132133public:134RD_SETGET(RD::DataFormat, format)135RD_SETGET(RD::TextureSamples, samples)136RD_SETGET(uint32_t, usage_flags)137protected:138static void _bind_methods() {139RD_BIND(Variant::INT, RDAttachmentFormat, format);140RD_BIND(Variant::INT, RDAttachmentFormat, samples);141RD_BIND(Variant::INT, RDAttachmentFormat, usage_flags);142}143};144145class RDFramebufferPass : public RefCounted {146GDCLASS(RDFramebufferPass, RefCounted)147friend class RenderingDevice;148friend class FramebufferCacheRD;149150RD::FramebufferPass base;151152public:153RD_SETGET(PackedInt32Array, color_attachments)154RD_SETGET(PackedInt32Array, input_attachments)155RD_SETGET(PackedInt32Array, resolve_attachments)156RD_SETGET(PackedInt32Array, preserve_attachments)157RD_SETGET(int32_t, depth_attachment)158protected:159enum {160ATTACHMENT_UNUSED = -1161};162163static void _bind_methods() {164RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, color_attachments);165RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, input_attachments);166RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, resolve_attachments);167RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, preserve_attachments);168RD_BIND(Variant::INT, RDFramebufferPass, depth_attachment);169170BIND_CONSTANT(ATTACHMENT_UNUSED);171}172};173174class RDSamplerState : public RefCounted {175GDCLASS(RDSamplerState, RefCounted)176friend class RenderingDevice;177178RD::SamplerState base;179180public:181RD_SETGET(RD::SamplerFilter, mag_filter)182RD_SETGET(RD::SamplerFilter, min_filter)183RD_SETGET(RD::SamplerFilter, mip_filter)184RD_SETGET(RD::SamplerRepeatMode, repeat_u)185RD_SETGET(RD::SamplerRepeatMode, repeat_v)186RD_SETGET(RD::SamplerRepeatMode, repeat_w)187RD_SETGET(float, lod_bias)188RD_SETGET(bool, use_anisotropy)189RD_SETGET(float, anisotropy_max)190RD_SETGET(bool, enable_compare)191RD_SETGET(RD::CompareOperator, compare_op)192RD_SETGET(float, min_lod)193RD_SETGET(float, max_lod)194RD_SETGET(RD::SamplerBorderColor, border_color)195RD_SETGET(bool, unnormalized_uvw)196197protected:198static void _bind_methods() {199RD_BIND(Variant::INT, RDSamplerState, mag_filter);200RD_BIND(Variant::INT, RDSamplerState, min_filter);201RD_BIND(Variant::INT, RDSamplerState, mip_filter);202RD_BIND(Variant::INT, RDSamplerState, repeat_u);203RD_BIND(Variant::INT, RDSamplerState, repeat_v);204RD_BIND(Variant::INT, RDSamplerState, repeat_w);205RD_BIND(Variant::FLOAT, RDSamplerState, lod_bias);206RD_BIND(Variant::BOOL, RDSamplerState, use_anisotropy);207RD_BIND(Variant::FLOAT, RDSamplerState, anisotropy_max);208RD_BIND(Variant::BOOL, RDSamplerState, enable_compare);209RD_BIND(Variant::INT, RDSamplerState, compare_op);210RD_BIND(Variant::FLOAT, RDSamplerState, min_lod);211RD_BIND(Variant::FLOAT, RDSamplerState, max_lod);212RD_BIND(Variant::INT, RDSamplerState, border_color);213RD_BIND(Variant::BOOL, RDSamplerState, unnormalized_uvw);214}215};216217class RDVertexAttribute : public RefCounted {218GDCLASS(RDVertexAttribute, RefCounted)219friend class RenderingDevice;220RD::VertexAttribute base;221222public:223RD_SETGET(uint32_t, binding)224RD_SETGET(uint32_t, location)225RD_SETGET(uint32_t, offset)226RD_SETGET(RD::DataFormat, format)227RD_SETGET(uint32_t, stride)228RD_SETGET(RD::VertexFrequency, frequency)229230protected:231static void _bind_methods() {232RD_BIND(Variant::INT, RDVertexAttribute, binding);233RD_BIND(Variant::INT, RDVertexAttribute, location);234RD_BIND(Variant::INT, RDVertexAttribute, offset);235RD_BIND(Variant::INT, RDVertexAttribute, format);236RD_BIND(Variant::INT, RDVertexAttribute, stride);237RD_BIND(Variant::INT, RDVertexAttribute, frequency);238}239};240class RDShaderSource : public RefCounted {241GDCLASS(RDShaderSource, RefCounted)242String source[RD::SHADER_STAGE_MAX];243RD::ShaderLanguage language = RD::SHADER_LANGUAGE_GLSL;244245public:246void set_stage_source(RD::ShaderStage p_stage, const String &p_source) {247ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);248source[p_stage] = p_source;249}250251String get_stage_source(RD::ShaderStage p_stage) const {252ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());253return source[p_stage];254}255256void set_language(RD::ShaderLanguage p_language) {257language = p_language;258}259260RD::ShaderLanguage get_language() const {261return language;262}263264protected:265static void _bind_methods() {266ClassDB::bind_method(D_METHOD("set_stage_source", "stage", "source"), &RDShaderSource::set_stage_source);267ClassDB::bind_method(D_METHOD("get_stage_source", "stage"), &RDShaderSource::get_stage_source);268269ClassDB::bind_method(D_METHOD("set_language", "language"), &RDShaderSource::set_language);270ClassDB::bind_method(D_METHOD("get_language"), &RDShaderSource::get_language);271272ADD_GROUP("Source", "source_");273ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_vertex"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_VERTEX);274ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_fragment"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_FRAGMENT);275ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_control"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_CONTROL);276ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_evaluation"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_EVALUATION);277ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_compute"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_COMPUTE);278ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_raygen"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_RAYGEN);279ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_any_hit"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_ANY_HIT);280ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_closest_hit"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_CLOSEST_HIT);281ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_miss"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_MISS);282ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_intersection"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_INTERSECTION);283ADD_GROUP("Syntax", "source_");284ADD_PROPERTY(PropertyInfo(Variant::INT, "language", PROPERTY_HINT_RANGE, "GLSL,HLSL"), "set_language", "get_language");285}286};287288class RDShaderSPIRV : public Resource {289GDCLASS(RDShaderSPIRV, Resource)290291Vector<uint8_t> bytecode[RD::SHADER_STAGE_MAX];292String compile_error[RD::SHADER_STAGE_MAX];293294public:295void set_stage_bytecode(RD::ShaderStage p_stage, const Vector<uint8_t> &p_bytecode) {296ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);297bytecode[p_stage] = p_bytecode;298}299300Vector<uint8_t> get_stage_bytecode(RD::ShaderStage p_stage) const {301ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, Vector<uint8_t>());302return bytecode[p_stage];303}304305Vector<RD::ShaderStageSPIRVData> get_stages() const {306Vector<RD::ShaderStageSPIRVData> stages;307for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {308if (bytecode[i].size()) {309RD::ShaderStageSPIRVData stage;310stage.shader_stage = RD::ShaderStage(i);311stage.spirv = bytecode[i];312stages.push_back(stage);313}314}315return stages;316}317318void set_stage_compile_error(RD::ShaderStage p_stage, const String &p_compile_error) {319ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);320compile_error[p_stage] = p_compile_error;321}322323String get_stage_compile_error(RD::ShaderStage p_stage) const {324ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());325return compile_error[p_stage];326}327328protected:329static void _bind_methods() {330ClassDB::bind_method(D_METHOD("set_stage_bytecode", "stage", "bytecode"), &RDShaderSPIRV::set_stage_bytecode);331ClassDB::bind_method(D_METHOD("get_stage_bytecode", "stage"), &RDShaderSPIRV::get_stage_bytecode);332333ClassDB::bind_method(D_METHOD("set_stage_compile_error", "stage", "compile_error"), &RDShaderSPIRV::set_stage_compile_error);334ClassDB::bind_method(D_METHOD("get_stage_compile_error", "stage"), &RDShaderSPIRV::get_stage_compile_error);335336ADD_GROUP("Bytecode", "bytecode_");337ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_vertex"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_VERTEX);338ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_fragment"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_FRAGMENT);339ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_control"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_CONTROL);340ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_evaluation"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_EVALUATION);341ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_compute"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_COMPUTE);342ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_raygen"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_RAYGEN);343ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_any_hit"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_ANY_HIT);344ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_closest_hit"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_CLOSEST_HIT);345ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_miss"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_MISS);346ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_intersection"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_INTERSECTION);347ADD_GROUP("Compile Error", "compile_error_");348ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_vertex"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_VERTEX);349ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_fragment"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_FRAGMENT);350ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_control"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_CONTROL);351ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_evaluation"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_EVALUATION);352ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_compute"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_COMPUTE);353ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_raygen"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_RAYGEN);354ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_any_hit"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_ANY_HIT);355ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_closest_hit"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_CLOSEST_HIT);356ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_miss"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_MISS);357ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_intersection"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_INTERSECTION);358}359};360361class RDShaderFile : public Resource {362GDCLASS(RDShaderFile, Resource)363364HashMap<StringName, Ref<RDShaderSPIRV>> versions;365String base_error;366367public:368void set_bytecode(const Ref<RDShaderSPIRV> &p_bytecode, const StringName &p_version = StringName()) {369ERR_FAIL_COND(p_bytecode.is_null());370versions[p_version] = p_bytecode;371emit_changed();372}373374Ref<RDShaderSPIRV> get_spirv(const StringName &p_version = StringName()) const {375ERR_FAIL_COND_V(!versions.has(p_version), Ref<RDShaderSPIRV>());376return versions[p_version];377}378379Vector<RD::ShaderStageSPIRVData> get_spirv_stages(const StringName &p_version = StringName()) const {380ERR_FAIL_COND_V(!versions.has(p_version), Vector<RD::ShaderStageSPIRVData>());381return versions[p_version]->get_stages();382}383384TypedArray<StringName> get_version_list() const {385Vector<StringName> vnames;386for (const KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) {387vnames.push_back(E.key);388}389vnames.sort_custom<StringName::AlphCompare>();390TypedArray<StringName> ret;391ret.resize(vnames.size());392for (int i = 0; i < vnames.size(); i++) {393ret[i] = vnames[i];394}395return ret;396}397398void set_base_error(const String &p_error) {399base_error = p_error;400emit_changed();401}402403String get_base_error() const {404return base_error;405}406407void print_errors(const String &p_file) {408if (!base_error.is_empty()) {409ERR_PRINT("Error parsing shader '" + p_file + "':\n\n" + base_error);410} else {411for (KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) {412for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {413String error = E.value->get_stage_compile_error(RD::ShaderStage(i));414if (!error.is_empty()) {415static const char *stage_str[RD::SHADER_STAGE_MAX] = {416"vertex",417"fragment",418"tesselation_control",419"tesselation_evaluation",420"compute"421};422423print_error("Error parsing shader '" + p_file + "', version '" + String(E.key) + "', stage '" + stage_str[i] + "':\n\n" + error);424}425}426}427}428}429430typedef String (*OpenIncludeFunction)(const String &, void *userdata);431Error parse_versions_from_text(const String &p_text, const String p_defines = String(), OpenIncludeFunction p_include_func = nullptr, void *p_include_func_userdata = nullptr);432433protected:434Dictionary _get_versions() const {435TypedArray<StringName> vnames = get_version_list();436Dictionary ret;437for (int i = 0; i < vnames.size(); i++) {438ret[vnames[i]] = versions[vnames[i]];439}440return ret;441}442void _set_versions(const Dictionary &p_versions) {443versions.clear();444for (const KeyValue<Variant, Variant> &kv : p_versions) {445StringName vname = kv.key;446Ref<RDShaderSPIRV> bc = kv.value;447ERR_CONTINUE(bc.is_null());448versions[vname] = bc;449}450451emit_changed();452}453454static void _bind_methods() {455ClassDB::bind_method(D_METHOD("set_bytecode", "bytecode", "version"), &RDShaderFile::set_bytecode, DEFVAL(StringName()));456ClassDB::bind_method(D_METHOD("get_spirv", "version"), &RDShaderFile::get_spirv, DEFVAL(StringName()));457ClassDB::bind_method(D_METHOD("get_version_list"), &RDShaderFile::get_version_list);458459ClassDB::bind_method(D_METHOD("set_base_error", "error"), &RDShaderFile::set_base_error);460ClassDB::bind_method(D_METHOD("get_base_error"), &RDShaderFile::get_base_error);461462ClassDB::bind_method(D_METHOD("_set_versions", "versions"), &RDShaderFile::_set_versions);463ClassDB::bind_method(D_METHOD("_get_versions"), &RDShaderFile::_get_versions);464465ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_versions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_versions", "_get_versions");466ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_error"), "set_base_error", "get_base_error");467}468};469470class RDUniform : public RefCounted {471GDCLASS(RDUniform, RefCounted)472friend class RenderingDevice;473friend class UniformSetCacheRD;474RD::Uniform base;475476public:477RD_SETGET(RD::UniformType, uniform_type)478RD_SETGET(int32_t, binding)479480void add_id(const RID &p_id) { base.append_id(p_id); }481void clear_ids() { base.clear_ids(); }482TypedArray<RID> get_ids() const {483TypedArray<RID> ids;484for (uint32_t i = 0; i < base.get_id_count(); i++) {485ids.push_back(base.get_id(i));486}487return ids;488}489490protected:491void _set_ids(const TypedArray<RID> &p_ids) {492base.clear_ids();493for (int i = 0; i < p_ids.size(); i++) {494RID id = p_ids[i];495ERR_FAIL_COND(id.is_null());496base.append_id(id);497}498}499static void _bind_methods() {500RD_BIND(Variant::INT, RDUniform, uniform_type);501RD_BIND(Variant::INT, RDUniform, binding);502ClassDB::bind_method(D_METHOD("add_id", "id"), &RDUniform::add_id);503ClassDB::bind_method(D_METHOD("clear_ids"), &RDUniform::clear_ids);504ClassDB::bind_method(D_METHOD("_set_ids", "ids"), &RDUniform::_set_ids);505ClassDB::bind_method(D_METHOD("get_ids"), &RDUniform::get_ids);506ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_ids", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_ids", "get_ids");507}508};509510class RDPipelineSpecializationConstant : public RefCounted {511GDCLASS(RDPipelineSpecializationConstant, RefCounted)512friend class RenderingDevice;513514Variant value = false;515uint32_t constant_id = 0;516517public:518void set_value(const Variant &p_value) {519ERR_FAIL_COND(p_value.get_type() != Variant::BOOL && p_value.get_type() != Variant::INT && p_value.get_type() != Variant::FLOAT);520value = p_value;521}522Variant get_value() const { return value; }523524void set_constant_id(uint32_t p_id) {525constant_id = p_id;526}527uint32_t get_constant_id() const {528return constant_id;529}530531protected:532static void _bind_methods() {533ClassDB::bind_method(D_METHOD("set_value", "value"), &RDPipelineSpecializationConstant::set_value);534ClassDB::bind_method(D_METHOD("get_value"), &RDPipelineSpecializationConstant::get_value);535536ClassDB::bind_method(D_METHOD("set_constant_id", "constant_id"), &RDPipelineSpecializationConstant::set_constant_id);537ClassDB::bind_method(D_METHOD("get_constant_id"), &RDPipelineSpecializationConstant::get_constant_id);538539ADD_PROPERTY(PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_value", "get_value");540ADD_PROPERTY(PropertyInfo(Variant::INT, "constant_id", PROPERTY_HINT_RANGE, "0,65535,0"), "set_constant_id", "get_constant_id");541}542};543544class RDPipelineRasterizationState : public RefCounted {545GDCLASS(RDPipelineRasterizationState, RefCounted)546friend class RenderingDevice;547548RD::PipelineRasterizationState base;549550public:551RD_SETGET(bool, enable_depth_clamp)552RD_SETGET(bool, discard_primitives)553RD_SETGET(bool, wireframe)554RD_SETGET(RD::PolygonCullMode, cull_mode)555RD_SETGET(RD::PolygonFrontFace, front_face)556RD_SETGET(bool, depth_bias_enabled)557RD_SETGET(float, depth_bias_constant_factor)558RD_SETGET(float, depth_bias_clamp)559RD_SETGET(float, depth_bias_slope_factor)560RD_SETGET(float, line_width)561RD_SETGET(uint32_t, patch_control_points)562563protected:564static void _bind_methods() {565RD_BIND(Variant::BOOL, RDPipelineRasterizationState, enable_depth_clamp);566RD_BIND(Variant::BOOL, RDPipelineRasterizationState, discard_primitives);567RD_BIND(Variant::BOOL, RDPipelineRasterizationState, wireframe);568RD_BIND(Variant::INT, RDPipelineRasterizationState, cull_mode);569RD_BIND(Variant::INT, RDPipelineRasterizationState, front_face);570RD_BIND(Variant::BOOL, RDPipelineRasterizationState, depth_bias_enabled);571RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_constant_factor);572RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_clamp);573RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_slope_factor);574RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, line_width);575RD_BIND(Variant::INT, RDPipelineRasterizationState, patch_control_points);576}577};578579class RDPipelineMultisampleState : public RefCounted {580GDCLASS(RDPipelineMultisampleState, RefCounted)581friend class RenderingDevice;582583RD::PipelineMultisampleState base;584TypedArray<int64_t> sample_masks;585586public:587RD_SETGET(RD::TextureSamples, sample_count)588RD_SETGET(bool, enable_sample_shading)589RD_SETGET(float, min_sample_shading)590RD_SETGET(bool, enable_alpha_to_coverage)591RD_SETGET(bool, enable_alpha_to_one)592593void set_sample_masks(const TypedArray<int64_t> &p_masks) { sample_masks = p_masks; }594TypedArray<int64_t> get_sample_masks() const { return sample_masks; }595596protected:597static void _bind_methods() {598RD_BIND(Variant::INT, RDPipelineMultisampleState, sample_count);599RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_sample_shading);600RD_BIND(Variant::FLOAT, RDPipelineMultisampleState, min_sample_shading);601RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_coverage);602RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_one);603604ClassDB::bind_method(D_METHOD("set_sample_masks", "masks"), &RDPipelineMultisampleState::set_sample_masks);605ClassDB::bind_method(D_METHOD("get_sample_masks"), &RDPipelineMultisampleState::get_sample_masks);606ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sample_masks", PROPERTY_HINT_ARRAY_TYPE, "int"), "set_sample_masks", "get_sample_masks");607}608};609610class RDPipelineDepthStencilState : public RefCounted {611GDCLASS(RDPipelineDepthStencilState, RefCounted)612friend class RenderingDevice;613614RD::PipelineDepthStencilState base;615616public:617RD_SETGET(bool, enable_depth_test)618RD_SETGET(bool, enable_depth_write)619RD_SETGET(RD::CompareOperator, depth_compare_operator)620RD_SETGET(bool, enable_depth_range)621RD_SETGET(float, depth_range_min)622RD_SETGET(float, depth_range_max)623RD_SETGET(bool, enable_stencil)624625RD_SETGET_SUB(RD::StencilOperation, front_op, fail)626RD_SETGET_SUB(RD::StencilOperation, front_op, pass)627RD_SETGET_SUB(RD::StencilOperation, front_op, depth_fail)628RD_SETGET_SUB(RD::CompareOperator, front_op, compare)629RD_SETGET_SUB(uint32_t, front_op, compare_mask)630RD_SETGET_SUB(uint32_t, front_op, write_mask)631RD_SETGET_SUB(uint32_t, front_op, reference)632633RD_SETGET_SUB(RD::StencilOperation, back_op, fail)634RD_SETGET_SUB(RD::StencilOperation, back_op, pass)635RD_SETGET_SUB(RD::StencilOperation, back_op, depth_fail)636RD_SETGET_SUB(RD::CompareOperator, back_op, compare)637RD_SETGET_SUB(uint32_t, back_op, compare_mask)638RD_SETGET_SUB(uint32_t, back_op, write_mask)639RD_SETGET_SUB(uint32_t, back_op, reference)640641protected:642static void _bind_methods() {643RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_test);644RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_write);645RD_BIND(Variant::INT, RDPipelineDepthStencilState, depth_compare_operator);646RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_range);647RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_min);648RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_max);649RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_stencil);650651RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, fail);652RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, pass);653RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, depth_fail);654RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare);655RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare_mask);656RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, write_mask);657RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, reference);658659RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, fail);660RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, pass);661RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, depth_fail);662RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare);663RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare_mask);664RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, write_mask);665RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, reference);666}667};668669class RDPipelineColorBlendStateAttachment : public RefCounted {670GDCLASS(RDPipelineColorBlendStateAttachment, RefCounted)671friend class RenderingDevice;672RD::PipelineColorBlendState::Attachment base;673674public:675RD_SETGET(bool, enable_blend)676RD_SETGET(RD::BlendFactor, src_color_blend_factor)677RD_SETGET(RD::BlendFactor, dst_color_blend_factor)678RD_SETGET(RD::BlendOperation, color_blend_op)679RD_SETGET(RD::BlendFactor, src_alpha_blend_factor)680RD_SETGET(RD::BlendFactor, dst_alpha_blend_factor)681RD_SETGET(RD::BlendOperation, alpha_blend_op)682RD_SETGET(bool, write_r)683RD_SETGET(bool, write_g)684RD_SETGET(bool, write_b)685RD_SETGET(bool, write_a)686687void set_as_mix() {688base = RD::PipelineColorBlendState::Attachment();689base.enable_blend = true;690base.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;691base.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;692base.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;693base.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;694}695696protected:697static void _bind_methods() {698ClassDB::bind_method(D_METHOD("set_as_mix"), &RDPipelineColorBlendStateAttachment::set_as_mix);699700RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, enable_blend);701RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_color_blend_factor);702RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_color_blend_factor);703RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, color_blend_op);704RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_alpha_blend_factor);705RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_alpha_blend_factor);706RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, alpha_blend_op);707RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_r);708RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_g);709RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_b);710RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_a);711}712};713714class RDPipelineColorBlendState : public RefCounted {715GDCLASS(RDPipelineColorBlendState, RefCounted)716friend class RenderingDevice;717RD::PipelineColorBlendState base;718719TypedArray<RDPipelineColorBlendStateAttachment> attachments;720721public:722RD_SETGET(bool, enable_logic_op)723RD_SETGET(RD::LogicOperation, logic_op)724RD_SETGET(Color, blend_constant)725726void set_attachments(const TypedArray<RDPipelineColorBlendStateAttachment> &p_attachments) {727attachments = p_attachments;728}729730TypedArray<RDPipelineColorBlendStateAttachment> get_attachments() const {731return attachments;732}733734protected:735static void _bind_methods() {736RD_BIND(Variant::BOOL, RDPipelineColorBlendState, enable_logic_op);737RD_BIND(Variant::INT, RDPipelineColorBlendState, logic_op);738RD_BIND(Variant::COLOR, RDPipelineColorBlendState, blend_constant);739740ClassDB::bind_method(D_METHOD("set_attachments", "attachments"), &RDPipelineColorBlendState::set_attachments);741ClassDB::bind_method(D_METHOD("get_attachments"), &RDPipelineColorBlendState::get_attachments);742ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "attachments", PROPERTY_HINT_ARRAY_TYPE, "RDPipelineColorBlendStateAttachment"), "set_attachments", "get_attachments");743}744};745746747