1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
|
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2020 LunarG, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
** to deal in the Software without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Software, and to permit persons to whom the
** Software is furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
** DEALINGS IN THE SOFTWARE.
*/
#include "decode/custom_vulkan_struct_decoders.h"
#include "decode/decode_allocator.h"
#include "decode/value_decoder.h"
#include "generated/generated_vulkan_struct_decoders.h"
#include "util/defines.h"
#include "util/logging.h"
#include <cassert>
GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)
size_t DecodePNextStruct(const uint8_t* buffer, size_t buffer_size, PNextNode** pNext);
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkClearColorValue* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkClearColorValue* value = wrapper->decoded_value;
wrapper->uint32.SetExternalMemory(value->uint32, 4);
bytes_read += wrapper->uint32.DecodeUInt32((buffer + bytes_read), (buffer_size - bytes_read));
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkClearValue* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkClearValue* value = wrapper->decoded_value;
wrapper->color = DecodeAllocator::Allocate<Decoded_VkClearColorValue>();
wrapper->color->decoded_value = &(value->color);
bytes_read += DecodeStruct((buffer + bytes_read), (buffer_size - bytes_read), wrapper->color);
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkPipelineExecutableStatisticValueKHR* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkPipelineExecutableStatisticValueKHR* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeUInt64Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->u64));
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkDeviceOrHostAddressKHR* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkDeviceOrHostAddressKHR* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeVkDeviceSizeValue(
(buffer + bytes_read), (buffer_size - bytes_read), &(value->deviceAddress));
wrapper->hostAddress = value->deviceAddress;
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkDeviceOrHostAddressConstKHR* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkDeviceOrHostAddressConstKHR* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeVkDeviceSizeValue(
(buffer + bytes_read), (buffer_size - bytes_read), &(value->deviceAddress));
wrapper->hostAddress = value->deviceAddress;
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkAccelerationStructureGeometryDataKHR* wrapper)
{
// TODO
GFXRECON_LOG_ERROR("VkAccelerationStructureGeometryDataKHR is not supported");
return 0;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkAccelerationStructureMotionInstanceNV* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkAccelerationStructureMotionInstanceNV* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeEnumValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->type));
bytes_read += ValueDecoder::DecodeFlagsValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->flags));
switch (value->type)
{
case VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_STATIC_NV:
wrapper->staticInstance = DecodeAllocator::Allocate<Decoded_VkAccelerationStructureInstanceKHR>();
wrapper->staticInstance->decoded_value = &value->data.staticInstance;
bytes_read += DecodeStruct((buffer + bytes_read), (buffer_size - bytes_read), wrapper->staticInstance);
break;
case VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_MATRIX_MOTION_NV:
wrapper->matrixMotionInstance =
DecodeAllocator::Allocate<Decoded_VkAccelerationStructureMatrixMotionInstanceNV>();
wrapper->matrixMotionInstance->decoded_value = &value->data.matrixMotionInstance;
bytes_read +=
DecodeStruct((buffer + bytes_read), (buffer_size - bytes_read), wrapper->matrixMotionInstance);
break;
case VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_SRT_MOTION_NV:
wrapper->srtMotionInstance =
DecodeAllocator::Allocate<Decoded_VkAccelerationStructureSRTMotionInstanceNV>();
wrapper->srtMotionInstance->decoded_value = &value->data.srtMotionInstance;
bytes_read += DecodeStruct((buffer + bytes_read), (buffer_size - bytes_read), wrapper->srtMotionInstance);
break;
default:
break;
}
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkDescriptorImageInfo* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkDescriptorImageInfo* value = wrapper->decoded_value;
bytes_read +=
ValueDecoder::DecodeHandleIdValue((buffer + bytes_read), (buffer_size - bytes_read), &(wrapper->sampler));
value->sampler = VK_NULL_HANDLE;
bytes_read +=
ValueDecoder::DecodeHandleIdValue((buffer + bytes_read), (buffer_size - bytes_read), &(wrapper->imageView));
value->imageView = VK_NULL_HANDLE;
bytes_read +=
ValueDecoder::DecodeEnumValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->imageLayout));
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkWriteDescriptorSet* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkWriteDescriptorSet* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeEnumValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->sType));
bytes_read += DecodePNextStruct((buffer + bytes_read), (buffer_size - bytes_read), &(wrapper->pNext));
value->pNext = wrapper->pNext ? wrapper->pNext->GetPointer() : nullptr;
bytes_read +=
ValueDecoder::DecodeHandleIdValue((buffer + bytes_read), (buffer_size - bytes_read), &(wrapper->dstSet));
value->dstSet = VK_NULL_HANDLE;
bytes_read +=
ValueDecoder::DecodeUInt32Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->dstBinding));
bytes_read +=
ValueDecoder::DecodeUInt32Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->dstArrayElement));
bytes_read +=
ValueDecoder::DecodeUInt32Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->descriptorCount));
bytes_read +=
ValueDecoder::DecodeEnumValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->descriptorType));
wrapper->pImageInfo = DecodeAllocator::Allocate<StructPointerDecoder<Decoded_VkDescriptorImageInfo>>();
bytes_read += wrapper->pImageInfo->Decode((buffer + bytes_read), (buffer_size - bytes_read));
value->pImageInfo = wrapper->pImageInfo->GetPointer();
wrapper->pBufferInfo = DecodeAllocator::Allocate<StructPointerDecoder<Decoded_VkDescriptorBufferInfo>>();
bytes_read += wrapper->pBufferInfo->Decode((buffer + bytes_read), (buffer_size - bytes_read));
value->pBufferInfo = wrapper->pBufferInfo->GetPointer();
bytes_read += wrapper->pTexelBufferView.Decode((buffer + bytes_read), (buffer_size - bytes_read));
value->pTexelBufferView = wrapper->pTexelBufferView.GetHandlePointer();
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkPerformanceValueINTEL* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkPerformanceValueINTEL* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeEnumValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->type));
wrapper->data = DecodeAllocator::Allocate<Decoded_VkPerformanceValueDataINTEL>();
wrapper->data->decoded_value = &(value->data);
if (value->type == VK_PERFORMANCE_VALUE_TYPE_STRING_INTEL)
{
bytes_read += wrapper->data->valueString.Decode((buffer + bytes_read), (buffer_size - bytes_read));
value->data.valueString = wrapper->data->valueString.GetPointer();
}
else
{
bytes_read +=
ValueDecoder::DecodeUInt64Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->data.value64));
}
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_VkAccelerationStructureGeometryKHR* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
VkAccelerationStructureGeometryKHR* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeEnumValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->sType));
bytes_read += DecodePNextStruct((buffer + bytes_read), (buffer_size - bytes_read), &(wrapper->pNext));
value->pNext = wrapper->pNext ? wrapper->pNext->GetPointer() : nullptr;
bytes_read +=
ValueDecoder::DecodeEnumValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->geometryType));
wrapper->geometry = DecodeAllocator::Allocate<Decoded_VkAccelerationStructureGeometryDataKHR>();
switch (value->geometryType)
{
case VK_GEOMETRY_TYPE_TRIANGLES_KHR:
wrapper->geometry->triangles =
DecodeAllocator::Allocate<Decoded_VkAccelerationStructureGeometryTrianglesDataKHR>();
wrapper->geometry->triangles->decoded_value = &(value->geometry.triangles);
bytes_read += DecodeStruct((buffer + bytes_read), (buffer_size - bytes_read), wrapper->geometry->triangles);
break;
case VK_GEOMETRY_TYPE_AABBS_KHR:
wrapper->geometry->aabbs = DecodeAllocator::Allocate<Decoded_VkAccelerationStructureGeometryAabbsDataKHR>();
wrapper->geometry->aabbs->decoded_value = &(value->geometry.aabbs);
bytes_read += DecodeStruct((buffer + bytes_read), (buffer_size - bytes_read), wrapper->geometry->aabbs);
break;
case VK_GEOMETRY_TYPE_INSTANCES_KHR:
wrapper->geometry->instances =
DecodeAllocator::Allocate<Decoded_VkAccelerationStructureGeometryInstancesDataKHR>();
wrapper->geometry->instances->decoded_value = &(value->geometry.instances);
bytes_read += DecodeStruct((buffer + bytes_read), (buffer_size - bytes_read), wrapper->geometry->instances);
break;
default:
break;
}
bytes_read += ValueDecoder::DecodeFlagsValue((buffer + bytes_read), (buffer_size - bytes_read), &(value->flags));
return bytes_read;
}
// The WIN32 SID structure has a variable size, so was encoded as an array of bytes instead of a struct.
static uint8_t* unpack_sid_struct(const PointerDecoder<uint8_t>& packed_value)
{
const uint8_t* bytes = packed_value.GetPointer();
// Allocate memory for variable length SID struct, to use for unpacking.
// SidAuthorityCount is the second byte of the packed array.
size_t sid_authority_size = bytes[1] * sizeof(uint32_t);
// sizeof(SID) already includes the size of one of the SidAuthority elements,
// so we can subtract 4 bytes from sid_authority_size.
size_t allocation_size = sizeof(SID) + (sid_authority_size - sizeof(uint32_t));
uint8_t* unpacked_memory = DecodeAllocator::Allocate<uint8_t>(allocation_size);
SID* sid = reinterpret_cast<SID*>(unpacked_memory);
sid->Revision = bytes[0];
sid->SubAuthorityCount = bytes[1];
memcpy(sid->IdentifierAuthority.Value, &bytes[2], 6);
memcpy(sid->SubAuthority, &bytes[8], sid_authority_size);
return unpacked_memory;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_ACL* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
ACL* value = wrapper->decoded_value;
bytes_read +=
ValueDecoder::DecodeUInt8Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->AclRevision));
bytes_read += ValueDecoder::DecodeUInt8Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->Sbz1));
bytes_read += ValueDecoder::DecodeUInt16Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->AclSize));
bytes_read +=
ValueDecoder::DecodeUInt16Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->AceCount));
bytes_read += ValueDecoder::DecodeUInt16Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->Sbz2));
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_SECURITY_DESCRIPTOR* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
SECURITY_DESCRIPTOR* value = wrapper->decoded_value;
bytes_read += ValueDecoder::DecodeUInt8Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->Revision));
bytes_read += ValueDecoder::DecodeUInt8Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->Sbz1));
bytes_read += ValueDecoder::DecodeUInt16Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->Control));
// The SID structure has a variable size, so has been packed into an array of bytes.
bytes_read += wrapper->PackedOwner.DecodeUInt8((buffer + bytes_read), (buffer_size - bytes_read));
wrapper->Owner = unpack_sid_struct(wrapper->PackedOwner);
value->Owner = wrapper->Owner;
bytes_read += wrapper->PackedGroup.DecodeUInt8((buffer + bytes_read), (buffer_size - bytes_read));
wrapper->Group = unpack_sid_struct(wrapper->PackedOwner);
value->Group = wrapper->Group;
wrapper->Sacl = DecodeAllocator::Allocate<StructPointerDecoder<Decoded_ACL>>();
bytes_read += wrapper->Sacl->Decode((buffer + bytes_read), (buffer_size - bytes_read));
value->Sacl = wrapper->Sacl->GetPointer();
wrapper->Dacl = DecodeAllocator::Allocate<StructPointerDecoder<Decoded_ACL>>();
bytes_read += wrapper->Dacl->Decode((buffer + bytes_read), (buffer_size - bytes_read));
value->Dacl = wrapper->Dacl->GetPointer();
return bytes_read;
}
size_t DecodeStruct(const uint8_t* buffer, size_t buffer_size, Decoded_SECURITY_ATTRIBUTES* wrapper)
{
assert((wrapper != nullptr) && (wrapper->decoded_value != nullptr));
size_t bytes_read = 0;
SECURITY_ATTRIBUTES* value = wrapper->decoded_value;
uint32_t nLength = 0;
bytes_read += ValueDecoder::DecodeUInt32Value((buffer + bytes_read), (buffer_size - bytes_read), &nLength);
value->nLength = nLength;
wrapper->lpSecurityDescriptor = DecodeAllocator::Allocate<StructPointerDecoder<Decoded_SECURITY_DESCRIPTOR>>();
bytes_read += wrapper->lpSecurityDescriptor->Decode((buffer + bytes_read), (buffer_size - bytes_read));
value->lpSecurityDescriptor = wrapper->lpSecurityDescriptor->GetPointer();
bytes_read +=
ValueDecoder::DecodeInt32Value((buffer + bytes_read), (buffer_size - bytes_read), &(value->bInheritHandle));
return bytes_read;
}
GFXRECON_END_NAMESPACE(decode)
GFXRECON_END_NAMESPACE(gfxrecon)
|