| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "servers/rendering/rendering_device.h" |
| 34 |
|
| 35 |
#define RD_SETGET(m_type, m_member) \ |
| 36 |
void set_##m_member(m_type p_##m_member) { \ |
| 37 |
base.m_member = p_##m_member; \ |
| 38 |
} \ |
| 39 |
m_type get_##m_member() const { \ |
| 40 |
return base.m_member; \ |
| 41 |
} |
| 42 |
|
| 43 |
#define RD_BIND(m_variant_type, m_class, m_member) \ |
| 44 |
ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_member); \ |
| 45 |
ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_member)), &m_class::get_##m_member); \ |
| 46 |
ADD_PROPERTY(PropertyInfo(m_variant_type, #m_member), "set_" _MKSTR(m_member), "get_" _MKSTR(m_member)) |
| 47 |
|
| 48 |
#define RD_SETGET_SUB(m_type, m_sub, m_member) \ |
| 49 |
void set_##m_sub##_##m_member(m_type p_##m_member) { \ |
| 50 |
base.m_sub.m_member = p_##m_member; \ |
| 51 |
} \ |
| 52 |
m_type get_##m_sub##_##m_member() const { \ |
| 53 |
return base.m_sub.m_member; \ |
| 54 |
} |
| 55 |
|
| 56 |
#define RD_BIND_SUB(m_variant_type, m_class, m_sub, m_member) \ |
| 57 |
ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_sub##_##m_member); \ |
| 58 |
ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_sub) "_" _MKSTR(m_member)), &m_class::get_##m_sub##_##m_member); \ |
| 59 |
ADD_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)) |
| 60 |
|
| 61 |
class RDTextureFormat : public RefCounted { |
| 62 |
GDCLASS(RDTextureFormat, RefCounted) |
| 63 |
|
| 64 |
friend class RenderingDevice; |
| 65 |
friend class RenderSceneBuffersRD; |
| 66 |
|
| 67 |
RD::TextureFormat base; |
| 68 |
|
| 69 |
public: |
| 70 |
RD_SETGET(RD::DataFormat, format) |
| 71 |
RD_SETGET(uint32_t, width) |
| 72 |
RD_SETGET(uint32_t, height) |
| 73 |
RD_SETGET(uint32_t, depth) |
| 74 |
RD_SETGET(uint32_t, array_layers) |
| 75 |
RD_SETGET(uint32_t, mipmaps) |
| 76 |
RD_SETGET(RD::TextureType, texture_type) |
| 77 |
RD_SETGET(RD::TextureSamples, samples) |
| 78 |
RD_SETGET(BitField<RenderingDevice::TextureUsageBits>, usage_bits) |
| 79 |
RD_SETGET(bool, is_resolve_buffer) |
| 80 |
RD_SETGET(bool, is_discardable) |
| 81 |
|
| 82 |
void add_shareable_format(RD::DataFormat p_format) { base.shareable_formats.push_back(p_format); } |
| 83 |
void remove_shareable_format(RD::DataFormat p_format) { base.shareable_formats.erase(p_format); } |
| 84 |
|
| 85 |
protected: |
| 86 |
static void _bind_methods() { |
| 87 |
RD_BIND(Variant::INT, RDTextureFormat, format); |
| 88 |
RD_BIND(Variant::INT, RDTextureFormat, width); |
| 89 |
RD_BIND(Variant::INT, RDTextureFormat, height); |
| 90 |
RD_BIND(Variant::INT, RDTextureFormat, depth); |
| 91 |
RD_BIND(Variant::INT, RDTextureFormat, array_layers); |
| 92 |
RD_BIND(Variant::INT, RDTextureFormat, mipmaps); |
| 93 |
RD_BIND(Variant::INT, RDTextureFormat, texture_type); |
| 94 |
RD_BIND(Variant::INT, RDTextureFormat, samples); |
| 95 |
RD_BIND(Variant::INT, RDTextureFormat, usage_bits); |
| 96 |
RD_BIND(Variant::BOOL, RDTextureFormat, is_resolve_buffer); |
| 97 |
RD_BIND(Variant::BOOL, RDTextureFormat, is_discardable); |
| 98 |
|
| 99 |
ClassDB::bind_method(D_METHOD("add_shareable_format", "format"), &RDTextureFormat::add_shareable_format); |
| 100 |
ClassDB::bind_method(D_METHOD("remove_shareable_format", "format"), &RDTextureFormat::remove_shareable_format); |
| 101 |
} |
| 102 |
}; |
| 103 |
|
| 104 |
class RDTextureView : public RefCounted { |
| 105 |
GDCLASS(RDTextureView, RefCounted) |
| 106 |
|
| 107 |
friend class RenderingDevice; |
| 108 |
friend class RenderSceneBuffersRD; |
| 109 |
|
| 110 |
RD::TextureView base; |
| 111 |
|
| 112 |
public: |
| 113 |
RD_SETGET(RD::DataFormat, format_override) |
| 114 |
RD_SETGET(RD::TextureSwizzle, swizzle_r) |
| 115 |
RD_SETGET(RD::TextureSwizzle, swizzle_g) |
| 116 |
RD_SETGET(RD::TextureSwizzle, swizzle_b) |
| 117 |
RD_SETGET(RD::TextureSwizzle, swizzle_a) |
| 118 |
protected: |
| 119 |
static void _bind_methods() { |
| 120 |
RD_BIND(Variant::INT, RDTextureView, format_override); |
| 121 |
RD_BIND(Variant::INT, RDTextureView, swizzle_r); |
| 122 |
RD_BIND(Variant::INT, RDTextureView, swizzle_g); |
| 123 |
RD_BIND(Variant::INT, RDTextureView, swizzle_b); |
| 124 |
RD_BIND(Variant::INT, RDTextureView, swizzle_a); |
| 125 |
} |
| 126 |
}; |
| 127 |
|
| 128 |
class RDAttachmentFormat : public RefCounted { |
| 129 |
GDCLASS(RDAttachmentFormat, RefCounted) |
| 130 |
friend class RenderingDevice; |
| 131 |
|
| 132 |
RD::AttachmentFormat base; |
| 133 |
|
| 134 |
public: |
| 135 |
RD_SETGET(RD::DataFormat, format) |
| 136 |
RD_SETGET(RD::TextureSamples, samples) |
| 137 |
RD_SETGET(uint32_t, usage_flags) |
| 138 |
protected: |
| 139 |
static void _bind_methods() { |
| 140 |
RD_BIND(Variant::INT, RDAttachmentFormat, format); |
| 141 |
RD_BIND(Variant::INT, RDAttachmentFormat, samples); |
| 142 |
RD_BIND(Variant::INT, RDAttachmentFormat, usage_flags); |
| 143 |
} |
| 144 |
}; |
| 145 |
|
| 146 |
class RDFramebufferPass : public RefCounted { |
| 147 |
GDCLASS(RDFramebufferPass, RefCounted) |
| 148 |
friend class RenderingDevice; |
| 149 |
friend class FramebufferCacheRD; |
| 150 |
|
| 151 |
RD::FramebufferPass base; |
| 152 |
|
| 153 |
public: |
| 154 |
RD_SETGET(PackedInt32Array, color_attachments) |
| 155 |
RD_SETGET(PackedInt32Array, input_attachments) |
| 156 |
RD_SETGET(PackedInt32Array, resolve_attachments) |
| 157 |
RD_SETGET(PackedInt32Array, preserve_attachments) |
| 158 |
RD_SETGET(int32_t, depth_attachment) |
| 159 |
protected: |
| 160 |
enum { |
| 161 |
ATTACHMENT_UNUSED = -1 |
| 162 |
}; |
| 163 |
|
| 164 |
static void _bind_methods() { |
| 165 |
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, color_attachments); |
| 166 |
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, input_attachments); |
| 167 |
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, resolve_attachments); |
| 168 |
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, preserve_attachments); |
| 169 |
RD_BIND(Variant::INT, RDFramebufferPass, depth_attachment); |
| 170 |
|
| 171 |
BIND_CONSTANT(ATTACHMENT_UNUSED); |
| 172 |
} |
| 173 |
}; |
| 174 |
|
| 175 |
class RDSamplerState : public RefCounted { |
| 176 |
GDCLASS(RDSamplerState, RefCounted) |
| 177 |
friend class RenderingDevice; |
| 178 |
|
| 179 |
RD::SamplerState base; |
| 180 |
|
| 181 |
public: |
| 182 |
RD_SETGET(RD::SamplerFilter, mag_filter) |
| 183 |
RD_SETGET(RD::SamplerFilter, min_filter) |
| 184 |
RD_SETGET(RD::SamplerFilter, mip_filter) |
| 185 |
RD_SETGET(RD::SamplerRepeatMode, repeat_u) |
| 186 |
RD_SETGET(RD::SamplerRepeatMode, repeat_v) |
| 187 |
RD_SETGET(RD::SamplerRepeatMode, repeat_w) |
| 188 |
RD_SETGET(float, lod_bias) |
| 189 |
RD_SETGET(bool, use_anisotropy) |
| 190 |
RD_SETGET(float, anisotropy_max) |
| 191 |
RD_SETGET(bool, enable_compare) |
| 192 |
RD_SETGET(RD::CompareOperator, compare_op) |
| 193 |
RD_SETGET(float, min_lod) |
| 194 |
RD_SETGET(float, max_lod) |
| 195 |
RD_SETGET(RD::SamplerBorderColor, border_color) |
| 196 |
RD_SETGET(bool, unnormalized_uvw) |
| 197 |
|
| 198 |
protected: |
| 199 |
static void _bind_methods() { |
| 200 |
RD_BIND(Variant::INT, RDSamplerState, mag_filter); |
| 201 |
RD_BIND(Variant::INT, RDSamplerState, min_filter); |
| 202 |
RD_BIND(Variant::INT, RDSamplerState, mip_filter); |
| 203 |
RD_BIND(Variant::INT, RDSamplerState, repeat_u); |
| 204 |
RD_BIND(Variant::INT, RDSamplerState, repeat_v); |
| 205 |
RD_BIND(Variant::INT, RDSamplerState, repeat_w); |
| 206 |
RD_BIND(Variant::FLOAT, RDSamplerState, lod_bias); |
| 207 |
RD_BIND(Variant::BOOL, RDSamplerState, use_anisotropy); |
| 208 |
RD_BIND(Variant::FLOAT, RDSamplerState, anisotropy_max); |
| 209 |
RD_BIND(Variant::BOOL, RDSamplerState, enable_compare); |
| 210 |
RD_BIND(Variant::INT, RDSamplerState, compare_op); |
| 211 |
RD_BIND(Variant::FLOAT, RDSamplerState, min_lod); |
| 212 |
RD_BIND(Variant::FLOAT, RDSamplerState, max_lod); |
| 213 |
RD_BIND(Variant::INT, RDSamplerState, border_color); |
| 214 |
RD_BIND(Variant::BOOL, RDSamplerState, unnormalized_uvw); |
| 215 |
} |
| 216 |
}; |
| 217 |
|
| 218 |
class RDVertexAttribute : public RefCounted { |
| 219 |
GDCLASS(RDVertexAttribute, RefCounted) |
| 220 |
friend class RenderingDevice; |
| 221 |
RD::VertexAttribute base; |
| 222 |
|
| 223 |
public: |
| 224 |
RD_SETGET(uint32_t, binding) |
| 225 |
RD_SETGET(uint32_t, location) |
| 226 |
RD_SETGET(uint32_t, offset) |
| 227 |
RD_SETGET(RD::DataFormat, format) |
| 228 |
RD_SETGET(uint32_t, stride) |
| 229 |
RD_SETGET(RD::VertexFrequency, frequency) |
| 230 |
|
| 231 |
protected: |
| 232 |
static void _bind_methods() { |
| 233 |
RD_BIND(Variant::INT, RDVertexAttribute, binding); |
| 234 |
RD_BIND(Variant::INT, RDVertexAttribute, location); |
| 235 |
RD_BIND(Variant::INT, RDVertexAttribute, offset); |
| 236 |
RD_BIND(Variant::INT, RDVertexAttribute, format); |
| 237 |
RD_BIND(Variant::INT, RDVertexAttribute, stride); |
| 238 |
RD_BIND(Variant::INT, RDVertexAttribute, frequency); |
| 239 |
} |
| 240 |
}; |
| 241 |
class RDShaderSource : public RefCounted { |
| 242 |
GDCLASS(RDShaderSource, RefCounted) |
| 243 |
String source[RD::SHADER_STAGE_MAX]; |
| 244 |
RD::ShaderLanguage language = RD::SHADER_LANGUAGE_GLSL; |
| 245 |
|
| 246 |
public: |
| 247 |
void set_stage_source(RD::ShaderStage p_stage, const String &p_source) { |
| 248 |
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX); |
| 249 |
source[p_stage] = p_source; |
| 250 |
} |
| 251 |
|
| 252 |
String get_stage_source(RD::ShaderStage p_stage) const { |
| 253 |
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String()); |
| 254 |
return source[p_stage]; |
| 255 |
} |
| 256 |
|
| 257 |
void set_language(RD::ShaderLanguage p_language) { |
| 258 |
language = p_language; |
| 259 |
} |
| 260 |
|
| 261 |
RD::ShaderLanguage get_language() const { |
| 262 |
return language; |
| 263 |
} |
| 264 |
|
| 265 |
protected: |
| 266 |
static void _bind_methods() { |
| 267 |
ClassDB::bind_method(D_METHOD("set_stage_source", "stage", "source"), &RDShaderSource::set_stage_source); |
| 268 |
ClassDB::bind_method(D_METHOD("get_stage_source", "stage"), &RDShaderSource::get_stage_source); |
| 269 |
|
| 270 |
ClassDB::bind_method(D_METHOD("set_language", "language"), &RDShaderSource::set_language); |
| 271 |
ClassDB::bind_method(D_METHOD("get_language"), &RDShaderSource::get_language); |
| 272 |
|
| 273 |
ADD_GROUP("Source", "source_"); |
| 274 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_vertex"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_VERTEX); |
| 275 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_fragment"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_FRAGMENT); |
| 276 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_control"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_CONTROL); |
| 277 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_evaluation"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_EVALUATION); |
| 278 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_compute"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_COMPUTE); |
| 279 |
ADD_GROUP("Syntax", "source_"); |
| 280 |
ADD_PROPERTY(PropertyInfo(Variant::INT, "language", PROPERTY_HINT_RANGE, "GLSL,HLSL"), "set_language", "get_language"); |
| 281 |
} |
| 282 |
}; |
| 283 |
|
| 284 |
class RDShaderSPIRV : public Resource { |
| 285 |
GDCLASS(RDShaderSPIRV, Resource) |
| 286 |
|
| 287 |
Vector<uint8_t> bytecode[RD::SHADER_STAGE_MAX]; |
| 288 |
String compile_error[RD::SHADER_STAGE_MAX]; |
| 289 |
|
| 290 |
public: |
| 291 |
void set_stage_bytecode(RD::ShaderStage p_stage, const Vector<uint8_t> &p_bytecode) { |
| 292 |
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX); |
| 293 |
bytecode[p_stage] = p_bytecode; |
| 294 |
} |
| 295 |
|
| 296 |
Vector<uint8_t> get_stage_bytecode(RD::ShaderStage p_stage) const { |
| 297 |
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, Vector<uint8_t>()); |
| 298 |
return bytecode[p_stage]; |
| 299 |
} |
| 300 |
|
| 301 |
Vector<RD::ShaderStageSPIRVData> get_stages() const { |
| 302 |
Vector<RD::ShaderStageSPIRVData> stages; |
| 303 |
for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) { |
| 304 |
if (bytecode[i].size()) { |
| 305 |
RD::ShaderStageSPIRVData stage; |
| 306 |
stage.shader_stage = RD::ShaderStage(i); |
| 307 |
stage.spirv = bytecode[i]; |
| 308 |
stages.push_back(stage); |
| 309 |
} |
| 310 |
} |
| 311 |
return stages; |
| 312 |
} |
| 313 |
|
| 314 |
void set_stage_compile_error(RD::ShaderStage p_stage, const String &p_compile_error) { |
| 315 |
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX); |
| 316 |
compile_error[p_stage] = p_compile_error; |
| 317 |
} |
| 318 |
|
| 319 |
String get_stage_compile_error(RD::ShaderStage p_stage) const { |
| 320 |
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String()); |
| 321 |
return compile_error[p_stage]; |
| 322 |
} |
| 323 |
|
| 324 |
protected: |
| 325 |
static void _bind_methods() { |
| 326 |
ClassDB::bind_method(D_METHOD("set_stage_bytecode", "stage", "bytecode"), &RDShaderSPIRV::set_stage_bytecode); |
| 327 |
ClassDB::bind_method(D_METHOD("get_stage_bytecode", "stage"), &RDShaderSPIRV::get_stage_bytecode); |
| 328 |
|
| 329 |
ClassDB::bind_method(D_METHOD("set_stage_compile_error", "stage", "compile_error"), &RDShaderSPIRV::set_stage_compile_error); |
| 330 |
ClassDB::bind_method(D_METHOD("get_stage_compile_error", "stage"), &RDShaderSPIRV::get_stage_compile_error); |
| 331 |
|
| 332 |
ADD_GROUP("Bytecode", "bytecode_"); |
| 333 |
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_vertex"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_VERTEX); |
| 334 |
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_fragment"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_FRAGMENT); |
| 335 |
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_control"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_CONTROL); |
| 336 |
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_evaluation"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_EVALUATION); |
| 337 |
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_compute"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_COMPUTE); |
| 338 |
ADD_GROUP("Compile Error", "compile_error_"); |
| 339 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_vertex"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_VERTEX); |
| 340 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_fragment"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_FRAGMENT); |
| 341 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_control"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_CONTROL); |
| 342 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_evaluation"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_EVALUATION); |
| 343 |
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_compute"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_COMPUTE); |
| 344 |
} |
| 345 |
}; |
| 346 |
|
| 347 |
class RDShaderFile : public Resource { |
| 348 |
GDCLASS(RDShaderFile, Resource) |
| 349 |
|
| 350 |
HashMap<StringName, Ref<RDShaderSPIRV>> versions; |
| 351 |
String base_error; |
| 352 |
|
| 353 |
public: |
| 354 |
void set_bytecode(const Ref<RDShaderSPIRV> &p_bytecode, const StringName &p_version = StringName()) { |
| 355 |
ERR_FAIL_COND(p_bytecode.is_null()); |
| 356 |
versions[p_version] = p_bytecode; |
| 357 |
emit_changed(); |
| 358 |
} |
| 359 |
|
| 360 |
Ref<RDShaderSPIRV> get_spirv(const StringName &p_version = StringName()) const { |
| 361 |
ERR_FAIL_COND_V(!versions.has(p_version), Ref<RDShaderSPIRV>()); |
| 362 |
return versions[p_version]; |
| 363 |
} |
| 364 |
|
| 365 |
Vector<RD::ShaderStageSPIRVData> get_spirv_stages(const StringName &p_version = StringName()) const { |
| 366 |
ERR_FAIL_COND_V(!versions.has(p_version), Vector<RD::ShaderStageSPIRVData>()); |
| 367 |
return versions[p_version]->get_stages(); |
| 368 |
} |
| 369 |
|
| 370 |
TypedArray<StringName> get_version_list() const { |
| 371 |
Vector<StringName> vnames; |
| 372 |
for (const KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) { |
| 373 |
vnames.push_back(E.key); |
| 374 |
} |
| 375 |
vnames.sort_custom<StringName::AlphCompare>(); |
| 376 |
TypedArray<StringName> ret; |
| 377 |
ret.resize(vnames.size()); |
| 378 |
for (int i = 0; i < vnames.size(); i++) { |
| 379 |
ret[i] = vnames[i]; |
| 380 |
} |
| 381 |
return ret; |
| 382 |
} |
| 383 |
|
| 384 |
void set_base_error(const String &p_error) { |
| 385 |
base_error = p_error; |
| 386 |
emit_changed(); |
| 387 |
} |
| 388 |
|
| 389 |
String get_base_error() const { |
| 390 |
return base_error; |
| 391 |
} |
| 392 |
|
| 393 |
void print_errors(const String &p_file) { |
| 394 |
if (!base_error.is_empty()) { |
| 395 |
ERR_PRINT("Error parsing shader '" + p_file + "':\n\n" + base_error); |
| 396 |
} else { |
| 397 |
for (KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) { |
| 398 |
for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) { |
| 399 |
String error = E.value->get_stage_compile_error(RD::ShaderStage(i)); |
| 400 |
if (!error.is_empty()) { |
| 401 |
static const char *stage_str[RD::SHADER_STAGE_MAX] = { |
| 402 |
"vertex", |
| 403 |
"fragment", |
| 404 |
"tesselation_control", |
| 405 |
"tesselation_evaluation", |
| 406 |
"compute" |
| 407 |
}; |
| 408 |
|
| 409 |
print_error("Error parsing shader '" + p_file + "', version '" + String(E.key) + "', stage '" + stage_str[i] + "':\n\n" + error); |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
typedef String (*OpenIncludeFunction)(const String &, void *userdata); |
| 417 |
Error parse_versions_from_text(const String &p_text, const String p_defines = String(), OpenIncludeFunction p_include_func = nullptr, void *p_include_func_userdata = nullptr); |
| 418 |
|
| 419 |
protected: |
| 420 |
Dictionary _get_versions() const { |
| 421 |
TypedArray<StringName> vnames = get_version_list(); |
| 422 |
Dictionary ret; |
| 423 |
for (int i = 0; i < vnames.size(); i++) { |
| 424 |
ret[vnames[i]] = versions[vnames[i]]; |
| 425 |
} |
| 426 |
return ret; |
| 427 |
} |
| 428 |
void _set_versions(const Dictionary &p_versions) { |
| 429 |
versions.clear(); |
| 430 |
for (const KeyValue<Variant, Variant> &kv : p_versions) { |
| 431 |
StringName vname = kv.key; |
| 432 |
Ref<RDShaderSPIRV> bc = kv.value; |
| 433 |
ERR_CONTINUE(bc.is_null()); |
| 434 |
versions[vname] = bc; |
| 435 |
} |
| 436 |
|
| 437 |
emit_changed(); |
| 438 |
} |
| 439 |
|
| 440 |
static void _bind_methods() { |
| 441 |
ClassDB::bind_method(D_METHOD("set_bytecode", "bytecode", "version"), &RDShaderFile::set_bytecode, DEFVAL(StringName())); |
| 442 |
ClassDB::bind_method(D_METHOD("get_spirv", "version"), &RDShaderFile::get_spirv, DEFVAL(StringName())); |
| 443 |
ClassDB::bind_method(D_METHOD("get_version_list"), &RDShaderFile::get_version_list); |
| 444 |
|
| 445 |
ClassDB::bind_method(D_METHOD("set_base_error", "error"), &RDShaderFile::set_base_error); |
| 446 |
ClassDB::bind_method(D_METHOD("get_base_error"), &RDShaderFile::get_base_error); |
| 447 |
|
| 448 |
ClassDB::bind_method(D_METHOD("_set_versions", "versions"), &RDShaderFile::_set_versions); |
| 449 |
ClassDB::bind_method(D_METHOD("_get_versions"), &RDShaderFile::_get_versions); |
| 450 |
|
| 451 |
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_versions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_versions", "_get_versions"); |
| 452 |
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_error"), "set_base_error", "get_base_error"); |
| 453 |
} |
| 454 |
}; |
| 455 |
|
| 456 |
class RDUniform : public RefCounted { |
| 457 |
GDCLASS(RDUniform, RefCounted) |
| 458 |
friend class RenderingDevice; |
| 459 |
friend class UniformSetCacheRD; |
| 460 |
RD::Uniform base; |
| 461 |
|
| 462 |
public: |
| 463 |
RD_SETGET(RD::UniformType, uniform_type) |
| 464 |
RD_SETGET(int32_t, binding) |
| 465 |
|
| 466 |
void add_id(const RID &p_id) { base.append_id(p_id); } |
| 467 |
void clear_ids() { base.clear_ids(); } |
| 468 |
TypedArray<RID> get_ids() const { |
| 469 |
TypedArray<RID> ids; |
| 470 |
for (uint32_t i = 0; i < base.get_id_count(); i++) { |
| 471 |
ids.push_back(base.get_id(i)); |
| 472 |
} |
| 473 |
return ids; |
| 474 |
} |
| 475 |
|
| 476 |
protected: |
| 477 |
void _set_ids(const TypedArray<RID> &p_ids) { |
| 478 |
base.clear_ids(); |
| 479 |
for (int i = 0; i < p_ids.size(); i++) { |
| 480 |
RID id = p_ids[i]; |
| 481 |
ERR_FAIL_COND(id.is_null()); |
| 482 |
base.append_id(id); |
| 483 |
} |
| 484 |
} |
| 485 |
static void _bind_methods() { |
| 486 |
RD_BIND(Variant::INT, RDUniform, uniform_type); |
| 487 |
RD_BIND(Variant::INT, RDUniform, binding); |
| 488 |
ClassDB::bind_method(D_METHOD("add_id", "id"), &RDUniform::add_id); |
| 489 |
ClassDB::bind_method(D_METHOD("clear_ids"), &RDUniform::clear_ids); |
| 490 |
ClassDB::bind_method(D_METHOD("_set_ids", "ids"), &RDUniform::_set_ids); |
| 491 |
ClassDB::bind_method(D_METHOD("get_ids"), &RDUniform::get_ids); |
| 492 |
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_ids", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_ids", "get_ids"); |
| 493 |
} |
| 494 |
}; |
| 495 |
|
| 496 |
class RDPipelineSpecializationConstant : public RefCounted { |
| 497 |
GDCLASS(RDPipelineSpecializationConstant, RefCounted) |
| 498 |
friend class RenderingDevice; |
| 499 |
|
| 500 |
Variant value = false; |
| 501 |
uint32_t constant_id = 0; |
| 502 |
|
| 503 |
public: |
| 504 |
void set_value(const Variant &p_value) { |
| 505 |
ERR_FAIL_COND(p_value.get_type() != Variant::BOOL && p_value.get_type() != Variant::INT && p_value.get_type() != Variant::FLOAT); |
| 506 |
value = p_value; |
| 507 |
} |
| 508 |
Variant get_value() const { return value; } |
| 509 |
|
| 510 |
void set_constant_id(uint32_t p_id) { |
| 511 |
constant_id = p_id; |
| 512 |
} |
| 513 |
uint32_t get_constant_id() const { |
| 514 |
return constant_id; |
| 515 |
} |
| 516 |
|
| 517 |
protected: |
| 518 |
static void _bind_methods() { |
| 519 |
ClassDB::bind_method(D_METHOD("set_value", "value"), &RDPipelineSpecializationConstant::set_value); |
| 520 |
ClassDB::bind_method(D_METHOD("get_value"), &RDPipelineSpecializationConstant::get_value); |
| 521 |
|
| 522 |
ClassDB::bind_method(D_METHOD("set_constant_id", "constant_id"), &RDPipelineSpecializationConstant::set_constant_id); |
| 523 |
ClassDB::bind_method(D_METHOD("get_constant_id"), &RDPipelineSpecializationConstant::get_constant_id); |
| 524 |
|
| 525 |
ADD_PROPERTY(PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_value", "get_value"); |
| 526 |
ADD_PROPERTY(PropertyInfo(Variant::INT, "constant_id", PROPERTY_HINT_RANGE, "0,65535,0"), "set_constant_id", "get_constant_id"); |
| 527 |
} |
| 528 |
}; |
| 529 |
|
| 530 |
class RDPipelineRasterizationState : public RefCounted { |
| 531 |
GDCLASS(RDPipelineRasterizationState, RefCounted) |
| 532 |
friend class RenderingDevice; |
| 533 |
|
| 534 |
RD::PipelineRasterizationState base; |
| 535 |
|
| 536 |
public: |
| 537 |
RD_SETGET(bool, enable_depth_clamp) |
| 538 |
RD_SETGET(bool, discard_primitives) |
| 539 |
RD_SETGET(bool, wireframe) |
| 540 |
RD_SETGET(RD::PolygonCullMode, cull_mode) |
| 541 |
RD_SETGET(RD::PolygonFrontFace, front_face) |
| 542 |
RD_SETGET(bool, depth_bias_enabled) |
| 543 |
RD_SETGET(float, depth_bias_constant_factor) |
| 544 |
RD_SETGET(float, depth_bias_clamp) |
| 545 |
RD_SETGET(float, depth_bias_slope_factor) |
| 546 |
RD_SETGET(float, line_width) |
| 547 |
RD_SETGET(uint32_t, patch_control_points) |
| 548 |
|
| 549 |
protected: |
| 550 |
static void _bind_methods() { |
| 551 |
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, enable_depth_clamp); |
| 552 |
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, discard_primitives); |
| 553 |
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, wireframe); |
| 554 |
RD_BIND(Variant::INT, RDPipelineRasterizationState, cull_mode); |
| 555 |
RD_BIND(Variant::INT, RDPipelineRasterizationState, front_face); |
| 556 |
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, depth_bias_enabled); |
| 557 |
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_constant_factor); |
| 558 |
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_clamp); |
| 559 |
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_slope_factor); |
| 560 |
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, line_width); |
| 561 |
RD_BIND(Variant::INT, RDPipelineRasterizationState, patch_control_points); |
| 562 |
} |
| 563 |
}; |
| 564 |
|
| 565 |
class RDPipelineMultisampleState : public RefCounted { |
| 566 |
GDCLASS(RDPipelineMultisampleState, RefCounted) |
| 567 |
friend class RenderingDevice; |
| 568 |
|
| 569 |
RD::PipelineMultisampleState base; |
| 570 |
TypedArray<int64_t> sample_masks; |
| 571 |
|
| 572 |
public: |
| 573 |
RD_SETGET(RD::TextureSamples, sample_count) |
| 574 |
RD_SETGET(bool, enable_sample_shading) |
| 575 |
RD_SETGET(float, min_sample_shading) |
| 576 |
RD_SETGET(bool, enable_alpha_to_coverage) |
| 577 |
RD_SETGET(bool, enable_alpha_to_one) |
| 578 |
|
| 579 |
void set_sample_masks(const TypedArray<int64_t> &p_masks) { sample_masks = p_masks; } |
| 580 |
TypedArray<int64_t> get_sample_masks() const { return sample_masks; } |
| 581 |
|
| 582 |
protected: |
| 583 |
static void _bind_methods() { |
| 584 |
RD_BIND(Variant::INT, RDPipelineMultisampleState, sample_count); |
| 585 |
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_sample_shading); |
| 586 |
RD_BIND(Variant::FLOAT, RDPipelineMultisampleState, min_sample_shading); |
| 587 |
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_coverage); |
| 588 |
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_one); |
| 589 |
|
| 590 |
ClassDB::bind_method(D_METHOD("set_sample_masks", "masks"), &RDPipelineMultisampleState::set_sample_masks); |
| 591 |
ClassDB::bind_method(D_METHOD("get_sample_masks"), &RDPipelineMultisampleState::get_sample_masks); |
| 592 |
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sample_masks", PROPERTY_HINT_ARRAY_TYPE, "int"), "set_sample_masks", "get_sample_masks"); |
| 593 |
} |
| 594 |
}; |
| 595 |
|
| 596 |
class RDPipelineDepthStencilState : public RefCounted { |
| 597 |
GDCLASS(RDPipelineDepthStencilState, RefCounted) |
| 598 |
friend class RenderingDevice; |
| 599 |
|
| 600 |
RD::PipelineDepthStencilState base; |
| 601 |
|
| 602 |
public: |
| 603 |
RD_SETGET(bool, enable_depth_test) |
| 604 |
RD_SETGET(bool, enable_depth_write) |
| 605 |
RD_SETGET(RD::CompareOperator, depth_compare_operator) |
| 606 |
RD_SETGET(bool, enable_depth_range) |
| 607 |
RD_SETGET(float, depth_range_min) |
| 608 |
RD_SETGET(float, depth_range_max) |
| 609 |
RD_SETGET(bool, enable_stencil) |
| 610 |
|
| 611 |
RD_SETGET_SUB(RD::StencilOperation, front_op, fail) |
| 612 |
RD_SETGET_SUB(RD::StencilOperation, front_op, pass) |
| 613 |
RD_SETGET_SUB(RD::StencilOperation, front_op, depth_fail) |
| 614 |
RD_SETGET_SUB(RD::CompareOperator, front_op, compare) |
| 615 |
RD_SETGET_SUB(uint32_t, front_op, compare_mask) |
| 616 |
RD_SETGET_SUB(uint32_t, front_op, write_mask) |
| 617 |
RD_SETGET_SUB(uint32_t, front_op, reference) |
| 618 |
|
| 619 |
RD_SETGET_SUB(RD::StencilOperation, back_op, fail) |
| 620 |
RD_SETGET_SUB(RD::StencilOperation, back_op, pass) |
| 621 |
RD_SETGET_SUB(RD::StencilOperation, back_op, depth_fail) |
| 622 |
RD_SETGET_SUB(RD::CompareOperator, back_op, compare) |
| 623 |
RD_SETGET_SUB(uint32_t, back_op, compare_mask) |
| 624 |
RD_SETGET_SUB(uint32_t, back_op, write_mask) |
| 625 |
RD_SETGET_SUB(uint32_t, back_op, reference) |
| 626 |
|
| 627 |
protected: |
| 628 |
static void _bind_methods() { |
| 629 |
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_test); |
| 630 |
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_write); |
| 631 |
RD_BIND(Variant::INT, RDPipelineDepthStencilState, depth_compare_operator); |
| 632 |
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_range); |
| 633 |
RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_min); |
| 634 |
RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_max); |
| 635 |
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_stencil); |
| 636 |
|
| 637 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, fail); |
| 638 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, pass); |
| 639 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, depth_fail); |
| 640 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare); |
| 641 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare_mask); |
| 642 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, write_mask); |
| 643 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, reference); |
| 644 |
|
| 645 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, fail); |
| 646 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, pass); |
| 647 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, depth_fail); |
| 648 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare); |
| 649 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare_mask); |
| 650 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, write_mask); |
| 651 |
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, reference); |
| 652 |
} |
| 653 |
}; |
| 654 |
|
| 655 |
class RDPipelineColorBlendStateAttachment : public RefCounted { |
| 656 |
GDCLASS(RDPipelineColorBlendStateAttachment, RefCounted) |
| 657 |
friend class RenderingDevice; |
| 658 |
RD::PipelineColorBlendState::Attachment base; |
| 659 |
|
| 660 |
public: |
| 661 |
RD_SETGET(bool, enable_blend) |
| 662 |
RD_SETGET(RD::BlendFactor, src_color_blend_factor) |
| 663 |
RD_SETGET(RD::BlendFactor, dst_color_blend_factor) |
| 664 |
RD_SETGET(RD::BlendOperation, color_blend_op) |
| 665 |
RD_SETGET(RD::BlendFactor, src_alpha_blend_factor) |
| 666 |
RD_SETGET(RD::BlendFactor, dst_alpha_blend_factor) |
| 667 |
RD_SETGET(RD::BlendOperation, alpha_blend_op) |
| 668 |
RD_SETGET(bool, write_r) |
| 669 |
RD_SETGET(bool, write_g) |
| 670 |
RD_SETGET(bool, write_b) |
| 671 |
RD_SETGET(bool, write_a) |
| 672 |
|
| 673 |
void set_as_mix() { |
| 674 |
base = RD::PipelineColorBlendState::Attachment(); |
| 675 |
base.enable_blend = true; |
| 676 |
base.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA; |
| 677 |
base.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; |
| 678 |
base.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA; |
| 679 |
base.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; |
| 680 |
} |
| 681 |
|
| 682 |
protected: |
| 683 |
static void _bind_methods() { |
| 684 |
ClassDB::bind_method(D_METHOD("set_as_mix"), &RDPipelineColorBlendStateAttachment::set_as_mix); |
| 685 |
|
| 686 |
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, enable_blend); |
| 687 |
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_color_blend_factor); |
| 688 |
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_color_blend_factor); |
| 689 |
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, color_blend_op); |
| 690 |
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_alpha_blend_factor); |
| 691 |
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_alpha_blend_factor); |
| 692 |
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, alpha_blend_op); |
| 693 |
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_r); |
| 694 |
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_g); |
| 695 |
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_b); |
| 696 |
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_a); |
| 697 |
} |
| 698 |
}; |
| 699 |
|
| 700 |
class RDPipelineColorBlendState : public RefCounted { |
| 701 |
GDCLASS(RDPipelineColorBlendState, RefCounted) |
| 702 |
friend class RenderingDevice; |
| 703 |
RD::PipelineColorBlendState base; |
| 704 |
|
| 705 |
TypedArray<RDPipelineColorBlendStateAttachment> attachments; |
| 706 |
|
| 707 |
public: |
| 708 |
RD_SETGET(bool, enable_logic_op) |
| 709 |
RD_SETGET(RD::LogicOperation, logic_op) |
| 710 |
RD_SETGET(Color, blend_constant) |
| 711 |
|
| 712 |
void set_attachments(const TypedArray<RDPipelineColorBlendStateAttachment> &p_attachments) { |
| 713 |
attachments = p_attachments; |
| 714 |
} |
| 715 |
|
| 716 |
TypedArray<RDPipelineColorBlendStateAttachment> get_attachments() const { |
| 717 |
return attachments; |
| 718 |
} |
| 719 |
|
| 720 |
protected: |
| 721 |
static void _bind_methods() { |
| 722 |
RD_BIND(Variant::BOOL, RDPipelineColorBlendState, enable_logic_op); |
| 723 |
RD_BIND(Variant::INT, RDPipelineColorBlendState, logic_op); |
| 724 |
RD_BIND(Variant::COLOR, RDPipelineColorBlendState, blend_constant); |
| 725 |
|
| 726 |
ClassDB::bind_method(D_METHOD("set_attachments", "attachments"), &RDPipelineColorBlendState::set_attachments); |
| 727 |
ClassDB::bind_method(D_METHOD("get_attachments"), &RDPipelineColorBlendState::get_attachments); |
| 728 |
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "attachments", PROPERTY_HINT_ARRAY_TYPE, "RDPipelineColorBlendStateAttachment"), "set_attachments", "get_attachments"); |
| 729 |
} |
| 730 |
}; |