xref: /aosp_15_r20/external/swiftshader/src/Pipeline/SpirvBinary.cpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1 // Copyright 2021 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "SpirvBinary.hpp"
16 
17 namespace sw {
18 
19 std::atomic<uint32_t> SpirvBinary::serialCounter(1);  // Start at 1, 0 is invalid shader.
20 
SpirvBinary()21 SpirvBinary::SpirvBinary()
22     : identifier(serialCounter++)
23 {}
24 
SpirvBinary(const uint32_t * binary,uint32_t wordCount)25 SpirvBinary::SpirvBinary(const uint32_t *binary, uint32_t wordCount)
26     : std::vector<uint32_t>(binary, binary + wordCount)
27     , identifier(serialCounter++)
28 {
29 }
30 
mapOptimizedIdentifier(const SpirvBinary & unoptimized)31 void SpirvBinary::mapOptimizedIdentifier(const SpirvBinary &unoptimized)
32 {
33 	// The bitwise NOT accomplishes a 1-to-1 mapping of the identifiers,
34 	// while avoiding clashes with previous or future serial IDs.
35 	identifier = ~unoptimized.identifier;
36 }
37 
38 }  // namespace sw