@@ -1032,7 +1032,7 @@ static const API_AVAILABLE(macos(11.0), ios(14.0)) MTLSamplerBorderColor SAMPLER
1032
1032
1033
1033
#pragma mark - Shader
1034
1034
1035
- const uint32_t SHADER_BINARY_VERSION = 2 ;
1035
+ const uint32_t SHADER_BINARY_VERSION = 3 ;
1036
1036
1037
1037
// region Serialization
1038
1038
@@ -1336,23 +1336,32 @@ void deserialize(BufReader &p_reader) {
1336
1336
1337
1337
struct ShaderStageData {
1338
1338
RD::ShaderStage stage = RD::ShaderStage::SHADER_STAGE_MAX;
1339
+ uint32_t is_position_invariant = UINT32_MAX;
1340
+ uint32_t supports_fast_math = UINT32_MAX;
1339
1341
CharString entry_point_name;
1340
1342
CharString source;
1341
1343
1342
1344
size_t serialize_size () const {
1343
1345
int comp_size = Compression::get_max_compressed_buffer_size (source.length (), Compression::MODE_ZSTD);
1344
1346
return sizeof (uint32_t ) // Stage.
1345
- + sizeof (uint32_t ) /* entry_point_name.utf8().length */ + entry_point_name.length () + sizeof (uint32_t ) /* uncompressed size */ + sizeof (uint32_t ) /* compressed size */ + comp_size;
1347
+ + sizeof (uint32_t ) // is_position_invariant
1348
+ + sizeof (uint32_t ) // supports_fast_math
1349
+ + sizeof (uint32_t ) /* entry_point_name.utf8().length */
1350
+ + entry_point_name.length () + sizeof (uint32_t ) /* uncompressed size */ + sizeof (uint32_t ) /* compressed size */ + comp_size;
1346
1351
}
1347
1352
1348
1353
void serialize (BufWriter &p_writer) const {
1349
1354
p_writer.write ((uint32_t )stage);
1355
+ p_writer.write (is_position_invariant);
1356
+ p_writer.write (supports_fast_math);
1350
1357
p_writer.write (entry_point_name);
1351
1358
p_writer.write_compressed (source);
1352
1359
}
1353
1360
1354
1361
void deserialize (BufReader &p_reader) {
1355
1362
p_reader.read ((uint32_t &)stage);
1363
+ p_reader.read (is_position_invariant);
1364
+ p_reader.read (supports_fast_math);
1356
1365
p_reader.read (entry_point_name);
1357
1366
p_reader.read_compressed (source);
1358
1367
}
@@ -2294,6 +2303,8 @@ void deserialize(BufReader &p_reader) {
2294
2303
2295
2304
ShaderStageData stage_data;
2296
2305
stage_data.stage = v.shader_stage ;
2306
+ stage_data.is_position_invariant = compiler.is_position_invariant ();
2307
+ stage_data.supports_fast_math = !entry_point.flags .get (spv::ExecutionModeSignedZeroInfNanPreserve);
2297
2308
stage_data.entry_point_name = entry_point.name .c_str ();
2298
2309
stage_data.source = source.c_str ();
2299
2310
bin_data.stages .push_back (stage_data);
@@ -2366,7 +2377,8 @@ void deserialize(BufReader &p_reader) {
2366
2377
ShaderCacheEntry *cd = memnew (ShaderCacheEntry (*this , key));
2367
2378
cd->name = binary_data.shader_name ;
2368
2379
cd->stage = shader_data.stage ;
2369
-
2380
+ options.preserveInvariance = shader_data.is_position_invariant ;
2381
+ options.fastMathEnabled = YES ;
2370
2382
MDLibrary *library = [MDLibrary newLibraryWithCacheEntry: cd
2371
2383
device: device
2372
2384
source: source
0 commit comments