Skip to content

Commit 08141e2

Browse files
stuartcarnieWhalesState
authored andcommitted
Metal: Ensure position invariance is captured from SPIRV-Cross
Closes godotengine#99029
1 parent 96e1626 commit 08141e2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/metal/rendering_device_driver_metal.mm

+15-3
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ static const API_AVAILABLE(macos(11.0), ios(14.0)) MTLSamplerBorderColor SAMPLER
10321032

10331033
#pragma mark - Shader
10341034

1035-
const uint32_t SHADER_BINARY_VERSION = 2;
1035+
const uint32_t SHADER_BINARY_VERSION = 3;
10361036

10371037
// region Serialization
10381038

@@ -1336,23 +1336,32 @@ void deserialize(BufReader &p_reader) {
13361336

13371337
struct ShaderStageData {
13381338
RD::ShaderStage stage = RD::ShaderStage::SHADER_STAGE_MAX;
1339+
uint32_t is_position_invariant = UINT32_MAX;
1340+
uint32_t supports_fast_math = UINT32_MAX;
13391341
CharString entry_point_name;
13401342
CharString source;
13411343

13421344
size_t serialize_size() const {
13431345
int comp_size = Compression::get_max_compressed_buffer_size(source.length(), Compression::MODE_ZSTD);
13441346
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;
13461351
}
13471352

13481353
void serialize(BufWriter &p_writer) const {
13491354
p_writer.write((uint32_t)stage);
1355+
p_writer.write(is_position_invariant);
1356+
p_writer.write(supports_fast_math);
13501357
p_writer.write(entry_point_name);
13511358
p_writer.write_compressed(source);
13521359
}
13531360

13541361
void deserialize(BufReader &p_reader) {
13551362
p_reader.read((uint32_t &)stage);
1363+
p_reader.read(is_position_invariant);
1364+
p_reader.read(supports_fast_math);
13561365
p_reader.read(entry_point_name);
13571366
p_reader.read_compressed(source);
13581367
}
@@ -2294,6 +2303,8 @@ void deserialize(BufReader &p_reader) {
22942303

22952304
ShaderStageData stage_data;
22962305
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);
22972308
stage_data.entry_point_name = entry_point.name.c_str();
22982309
stage_data.source = source.c_str();
22992310
bin_data.stages.push_back(stage_data);
@@ -2366,7 +2377,8 @@ void deserialize(BufReader &p_reader) {
23662377
ShaderCacheEntry *cd = memnew(ShaderCacheEntry(*this, key));
23672378
cd->name = binary_data.shader_name;
23682379
cd->stage = shader_data.stage;
2369-
2380+
options.preserveInvariance = shader_data.is_position_invariant;
2381+
options.fastMathEnabled = YES;
23702382
MDLibrary *library = [MDLibrary newLibraryWithCacheEntry:cd
23712383
device:device
23722384
source:source

0 commit comments

Comments
 (0)