1cb93a386Sopenharmony_ci// Copyright 2021 The SwiftShader Authors. All Rights Reserved.
2cb93a386Sopenharmony_ci//
3cb93a386Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4cb93a386Sopenharmony_ci// you may not use this file except in compliance with the License.
5cb93a386Sopenharmony_ci// You may obtain a copy of the License at
6cb93a386Sopenharmony_ci//
7cb93a386Sopenharmony_ci//    http://www.apache.org/licenses/LICENSE-2.0
8cb93a386Sopenharmony_ci//
9cb93a386Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10cb93a386Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11cb93a386Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb93a386Sopenharmony_ci// See the License for the specific language governing permissions and
13cb93a386Sopenharmony_ci// limitations under the License.
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ci#ifndef sw_SpirvBinary_hpp
16cb93a386Sopenharmony_ci#define sw_SpirvBinary_hpp
17cb93a386Sopenharmony_ci
18cb93a386Sopenharmony_ci#include <atomic>
19cb93a386Sopenharmony_ci#include <cstdint>
20cb93a386Sopenharmony_ci#include <vector>
21cb93a386Sopenharmony_ci
22cb93a386Sopenharmony_cinamespace sw {
23cb93a386Sopenharmony_ci
24cb93a386Sopenharmony_ciclass SpirvBinary : public std::vector<uint32_t>
25cb93a386Sopenharmony_ci{
26cb93a386Sopenharmony_cipublic:
27cb93a386Sopenharmony_ci	SpirvBinary();
28cb93a386Sopenharmony_ci	SpirvBinary(const uint32_t *binary, uint32_t wordCount);
29cb93a386Sopenharmony_ci
30cb93a386Sopenharmony_ci	inline uint32_t getIdentifier() const { return identifier; };
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ci	// Assigns an identifier derived from the unoptimized SPIR-V binary, to avoid recompiles.
33cb93a386Sopenharmony_ci	void mapOptimizedIdentifier(const SpirvBinary &unoptimized);
34cb93a386Sopenharmony_ci
35cb93a386Sopenharmony_ciprivate:
36cb93a386Sopenharmony_ci	static std::atomic<uint32_t> serialCounter;
37cb93a386Sopenharmony_ci
38cb93a386Sopenharmony_ci	uint32_t identifier;
39cb93a386Sopenharmony_ci};
40cb93a386Sopenharmony_ci
41cb93a386Sopenharmony_ci}  // namespace sw
42cb93a386Sopenharmony_ci
43cb93a386Sopenharmony_ci#endif  // sw_SpirvBinary_hpp
44