Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traverse geometry pNext for safe structs #248

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/vulkan/vk_safe_struct_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ safe_VkAccelerationStructureGeometryKHR::safe_VkAccelerationStructureGeometryKHR
: sType(in_struct->sType), geometryType(in_struct->geometryType), geometry(in_struct->geometry), flags(in_struct->flags) {
if (copy_pnext) {
pNext = SafePnextCopy(in_struct->pNext, copy_state);
if (geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
geometry.instances.pNext = SafePnextCopy(in_struct->geometry.instances.pNext, copy_state);
} else if (geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
geometry.triangles.pNext = SafePnextCopy(in_struct->geometry.triangles.pNext, copy_state);
} else if (geometryType == VK_GEOMETRY_TYPE_AABBS_KHR) {
geometry.aabbs.pNext = SafePnextCopy(in_struct->geometry.aabbs.pNext, copy_state);
}
}
if (is_host && geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
if (geometry.instances.arrayOfPointers) {
Expand Down Expand Up @@ -93,6 +100,13 @@ safe_VkAccelerationStructureGeometryKHR::safe_VkAccelerationStructureGeometryKHR
flags = copy_src.flags;

pNext = SafePnextCopy(copy_src.pNext);
if (geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
geometry.instances.pNext = SafePnextCopy(copy_src.geometry.instances.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
geometry.triangles.pNext = SafePnextCopy(copy_src.geometry.triangles.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_AABBS_KHR) {
geometry.aabbs.pNext = SafePnextCopy(copy_src.geometry.aabbs.pNext);
}
auto src_iter = GetAccelStructGeomHostAllocMap().find(&copy_src);
if (src_iter != GetAccelStructGeomHostAllocMap().end()) {
auto& src_alloc = src_iter->second;
Expand Down Expand Up @@ -133,13 +147,27 @@ safe_VkAccelerationStructureGeometryKHR& safe_VkAccelerationStructureGeometryKHR
delete iter->second;
}
FreePnextChain(pNext);
if (geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
FreePnextChain(geometry.instances.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
FreePnextChain(geometry.triangles.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_AABBS_KHR) {
FreePnextChain(geometry.aabbs.pNext);
}

sType = copy_src.sType;
geometryType = copy_src.geometryType;
geometry = copy_src.geometry;
flags = copy_src.flags;

pNext = SafePnextCopy(copy_src.pNext);
if (geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
geometry.instances.pNext = SafePnextCopy(copy_src.geometry.instances.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
geometry.triangles.pNext = SafePnextCopy(copy_src.geometry.triangles.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_AABBS_KHR) {
geometry.aabbs.pNext = SafePnextCopy(copy_src.geometry.aabbs.pNext);
}
auto src_iter = GetAccelStructGeomHostAllocMap().find(&copy_src);
if (src_iter != GetAccelStructGeomHostAllocMap().end()) {
auto& src_alloc = src_iter->second;
Expand Down Expand Up @@ -179,6 +207,13 @@ safe_VkAccelerationStructureGeometryKHR::~safe_VkAccelerationStructureGeometryKH
delete iter->second;
}
FreePnextChain(pNext);
if (geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
FreePnextChain(geometry.instances.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
FreePnextChain(geometry.triangles.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_AABBS_KHR) {
FreePnextChain(geometry.aabbs.pNext);
}
}

void safe_VkAccelerationStructureGeometryKHR::initialize(const VkAccelerationStructureGeometryKHR* in_struct, const bool is_host,
Expand All @@ -189,6 +224,13 @@ void safe_VkAccelerationStructureGeometryKHR::initialize(const VkAccelerationStr
delete iter->second;
}
FreePnextChain(pNext);
if (geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
FreePnextChain(geometry.instances.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
FreePnextChain(geometry.triangles.pNext);
} else if (geometryType == VK_GEOMETRY_TYPE_AABBS_KHR) {
FreePnextChain(geometry.aabbs.pNext);
}
sType = in_struct->sType;
geometryType = in_struct->geometryType;
geometry = in_struct->geometry;
Expand Down Expand Up @@ -237,6 +279,13 @@ void safe_VkAccelerationStructureGeometryKHR::initialize(const safe_VkAccelerati
flags = copy_src->flags;

pNext = SafePnextCopy(copy_src->pNext);
if (geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
geometry.instances.pNext = SafePnextCopy(copy_src->geometry.instances.pNext, copy_state);
} else if (geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
geometry.triangles.pNext = SafePnextCopy(copy_src->geometry.triangles.pNext, copy_state);
} else if (geometryType == VK_GEOMETRY_TYPE_AABBS_KHR) {
geometry.aabbs.pNext = SafePnextCopy(copy_src->geometry.aabbs.pNext, copy_state);
}
auto src_iter = GetAccelStructGeomHostAllocMap().find(copy_src);
if (src_iter != GetAccelStructGeomHostAllocMap().end()) {
auto& src_alloc = src_iter->second;
Expand Down