1 #ifndef _VKSSERIALIZERVKSC_HPP
2 #define _VKSSERIALIZERVKSC_HPP
3
4 /*-------------------------------------------------------------------------
5 * Vulkan CTS Framework
6 * --------------------
7 *
8 * Copyright (c) 2021 The Khronos Group Inc.
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 *-------------------------------------------------------------------------*/
23
24 #include "vksSerializer.hpp"
25 #include "vksJson.hpp"
26
27 #include "vkPrograms.hpp"
28
29 namespace vksc_server
30 {
31
32 template <typename ENUM>
SerializeEnum(Serializer<ToWrite> & serializer,ENUM & v)33 inline void SerializeEnum (Serializer<ToWrite>& serializer, ENUM& v)
34 {
35 static_assert(std::is_enum<ENUM>::value, "enums only");
36 s32 raw = v;
37 serializer.Serialize(raw);
38 }
39
40 template <typename ENUM>
SerializeEnum(Serializer<ToRead> & serializer,ENUM & v)41 inline void SerializeEnum (Serializer<ToRead>& serializer, ENUM& v)
42 {
43 static_assert(std::is_enum<ENUM>::value, "enums only");
44 s32 raw;
45 serializer.Serialize(raw);
46 v = static_cast<ENUM>(raw);
47 }
48
49 template <typename TYPE>
SerializeItem(Serializer<TYPE> & serializer,vk::SpirvVersion & v)50 inline void SerializeItem (Serializer<TYPE>& serializer, vk::SpirvVersion& v)
51 {
52 SerializeEnum(serializer, v);
53 }
54
55 template <typename TYPE>
SerializeItem(Serializer<TYPE> & serializer,vk::SpirVAsmBuildOptions & v)56 inline void SerializeItem (Serializer<TYPE>& serializer, vk::SpirVAsmBuildOptions& v)
57 {
58 serializer.Serialize(v.vulkanVersion, v.targetVersion, v.supports_VK_KHR_spirv_1_4);
59 }
60
61 template <typename TYPE>
SerializeItem(Serializer<TYPE> & serializer,vk::SpirVAsmSource & v)62 inline void SerializeItem (Serializer<TYPE>& serializer, vk::SpirVAsmSource& v)
63 {
64 serializer.Serialize(v.buildOptions, v.source);
65 }
66
67 template <typename TYPE>
SerializeItem(Serializer<TYPE> & serializer,vk::SpirVProgramInfo & v)68 inline void SerializeItem (Serializer<TYPE>& serializer, vk::SpirVProgramInfo& v)
69 {
70 serializer.Serialize(v.source, v.infoLog, v.compileTimeUs, v.compileOk);
71 }
72
73 template <typename TYPE>
SerializeItem(Serializer<TYPE> & serializer,vk::ShaderBuildOptions & v)74 inline void SerializeItem (Serializer<TYPE>& serializer, vk::ShaderBuildOptions& v)
75 {
76 serializer.Serialize(v.vulkanVersion, v.targetVersion, v.flags, v.supports_VK_KHR_spirv_1_4);
77 }
78
79 template <typename TYPE>
SerializeItem(Serializer<TYPE> & serializer,vk::GlslSource & v)80 inline void SerializeItem (Serializer<TYPE>& serializer, vk::GlslSource& v)
81 {
82 for (msize i{}; i < glu::SHADERTYPE_LAST; ++i)
83 {
84 serializer.Serialize(v.sources[i]);
85 }
86 serializer.Serialize(v.buildOptions);
87 }
88
89 template <typename TYPE>
SerializeItem(Serializer<TYPE> & serializer,vk::HlslSource & v)90 inline void SerializeItem (Serializer<TYPE>& serializer, vk::HlslSource& v)
91 {
92 for (msize i{}; i < glu::SHADERTYPE_LAST; ++i)
93 {
94 serializer.Serialize(v.sources[i]);
95 }
96 serializer.Serialize(v.buildOptions);
97 }
98
99 template <vk::HandleType VKTYPE>
SerializeItem(Serializer<ToRead> & serializer,vk::Handle<VKTYPE> & v)100 inline void SerializeItem (Serializer<ToRead>& serializer, vk::Handle<VKTYPE>& v)
101 {
102 u64 handle;
103 serializer.Serialize(handle);
104 v = handle;
105 }
106
107 template <vk::HandleType VKTYPE>
SerializeItem(Serializer<ToWrite> & serializer,const vk::Handle<VKTYPE> & v)108 inline void SerializeItem (Serializer<ToWrite>& serializer, const vk::Handle<VKTYPE>& v)
109 {
110 serializer.Serialize(v.getInternal());
111 }
112
SerializeItem(Serializer<ToRead> & serializer,vk::VkDeviceObjectReservationCreateInfo & v)113 inline void SerializeItem (Serializer<ToRead>& serializer, vk::VkDeviceObjectReservationCreateInfo& v)
114 {
115 string input;
116 serializer.Serialize(input);
117 json::Context ctx;
118 json::readJSON_VkDeviceObjectReservationCreateInfo(ctx, input, v);
119 }
120
SerializeItem(Serializer<ToWrite> & serializer,vk::VkDeviceObjectReservationCreateInfo & v)121 inline void SerializeItem (Serializer<ToWrite>& serializer, vk::VkDeviceObjectReservationCreateInfo& v)
122 {
123 string output = json::writeJSON_VkDeviceObjectReservationCreateInfo(v);
124 serializer.Serialize(output);
125 }
126
SerializeItem(Serializer<ToRead> & serializer,vk::VkPipelineOfflineCreateInfo & v)127 inline void SerializeItem(Serializer<ToRead>& serializer, vk::VkPipelineOfflineCreateInfo& v)
128 {
129 string input;
130 serializer.Serialize(input);
131 json::Context ctx;
132 json::readJSON_VkPipelineOfflineCreateInfo(ctx, input, v);
133 }
134
SerializeItem(Serializer<ToWrite> & serializer,vk::VkPipelineOfflineCreateInfo & v)135 inline void SerializeItem(Serializer<ToWrite>& serializer, vk::VkPipelineOfflineCreateInfo& v)
136 {
137 string output = json::writeJSON_VkPipelineOfflineCreateInfo(v);
138 serializer.Serialize(output);
139 }
140
SerializeItem(Serializer<ToRead> & serializer,vk::VkPhysicalDeviceFeatures2 & v)141 inline void SerializeItem(Serializer<ToRead>& serializer, vk::VkPhysicalDeviceFeatures2& v)
142 {
143 string input;
144 serializer.Serialize(input);
145 json::Context ctx;
146 json::readJSON_VkPhysicalDeviceFeatures2(ctx, input, v);
147 }
148
SerializeItem(Serializer<ToWrite> & serializer,vk::VkPhysicalDeviceFeatures2 & v)149 inline void SerializeItem(Serializer<ToWrite>& serializer, vk::VkPhysicalDeviceFeatures2& v)
150 {
151 string output = json::writeJSON_VkPhysicalDeviceFeatures2(v);
152 serializer.Serialize(output);
153 }
154
155 }
156
157 #endif // _VKSSERIALIZERVKSC_HPP
158