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

safe: Fix VK_EXT_sample_locations #232

Merged
Merged
Show file tree
Hide file tree
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
32 changes: 30 additions & 2 deletions include/vulkan/utility/vk_safe_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10301,13 +10301,41 @@ struct safe_VkSampleLocationsInfoEXT {
VkSampleLocationsInfoEXT* ptr() { return reinterpret_cast<VkSampleLocationsInfoEXT*>(this); }
VkSampleLocationsInfoEXT const* ptr() const { return reinterpret_cast<VkSampleLocationsInfoEXT const*>(this); }
};
struct safe_VkAttachmentSampleLocationsEXT {
uint32_t attachmentIndex;
safe_VkSampleLocationsInfoEXT sampleLocationsInfo;

safe_VkAttachmentSampleLocationsEXT(const VkAttachmentSampleLocationsEXT* in_struct, PNextCopyState* copy_state = {});
safe_VkAttachmentSampleLocationsEXT(const safe_VkAttachmentSampleLocationsEXT& copy_src);
safe_VkAttachmentSampleLocationsEXT& operator=(const safe_VkAttachmentSampleLocationsEXT& copy_src);
safe_VkAttachmentSampleLocationsEXT();
~safe_VkAttachmentSampleLocationsEXT();
void initialize(const VkAttachmentSampleLocationsEXT* in_struct, PNextCopyState* copy_state = {});
void initialize(const safe_VkAttachmentSampleLocationsEXT* copy_src, PNextCopyState* copy_state = {});
VkAttachmentSampleLocationsEXT* ptr() { return reinterpret_cast<VkAttachmentSampleLocationsEXT*>(this); }
VkAttachmentSampleLocationsEXT const* ptr() const { return reinterpret_cast<VkAttachmentSampleLocationsEXT const*>(this); }
};
struct safe_VkSubpassSampleLocationsEXT {
uint32_t subpassIndex;
safe_VkSampleLocationsInfoEXT sampleLocationsInfo;

safe_VkSubpassSampleLocationsEXT(const VkSubpassSampleLocationsEXT* in_struct, PNextCopyState* copy_state = {});
safe_VkSubpassSampleLocationsEXT(const safe_VkSubpassSampleLocationsEXT& copy_src);
safe_VkSubpassSampleLocationsEXT& operator=(const safe_VkSubpassSampleLocationsEXT& copy_src);
safe_VkSubpassSampleLocationsEXT();
~safe_VkSubpassSampleLocationsEXT();
void initialize(const VkSubpassSampleLocationsEXT* in_struct, PNextCopyState* copy_state = {});
void initialize(const safe_VkSubpassSampleLocationsEXT* copy_src, PNextCopyState* copy_state = {});
VkSubpassSampleLocationsEXT* ptr() { return reinterpret_cast<VkSubpassSampleLocationsEXT*>(this); }
VkSubpassSampleLocationsEXT const* ptr() const { return reinterpret_cast<VkSubpassSampleLocationsEXT const*>(this); }
};
struct safe_VkRenderPassSampleLocationsBeginInfoEXT {
VkStructureType sType;
const void* pNext{};
uint32_t attachmentInitialSampleLocationsCount;
const VkAttachmentSampleLocationsEXT* pAttachmentInitialSampleLocations{};
safe_VkAttachmentSampleLocationsEXT* pAttachmentInitialSampleLocations{};
uint32_t postSubpassSampleLocationsCount;
const VkSubpassSampleLocationsEXT* pPostSubpassSampleLocations{};
safe_VkSubpassSampleLocationsEXT* pPostSubpassSampleLocations{};

safe_VkRenderPassSampleLocationsBeginInfoEXT(const VkRenderPassSampleLocationsBeginInfoEXT* in_struct,
PNextCopyState* copy_state = {}, bool copy_pnext = true);
Expand Down
5 changes: 4 additions & 1 deletion scripts/generators/safe_struct_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def needSafeStruct(self, struct: Struct) -> bool:
for member in struct.members:
if member.pointer:
return True
# The VK_EXT_sample_locations design created edge case, easiest to handle here
if struct.name == 'VkAttachmentSampleLocationsEXT' or struct.name == 'VkSubpassSampleLocationsEXT':
return True
return False

def containsObjectHandle(self, member: Member) -> bool:
Expand Down Expand Up @@ -170,7 +173,7 @@ def generateHeader(self):
#include <vulkan/utility/vk_safe_struct_utils.hpp>

namespace vku {

// Mapping of unknown stype codes to structure lengths. This should be set up by the application
// before vkCreateInstance() and not modified afterwards.
std::vector<std::pair<uint32_t, uint32_t>>& GetCustomStypeInfo();
Expand Down
168 changes: 119 additions & 49 deletions src/vulkan/vk_safe_struct_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,75 @@ void safe_VkSampleLocationsInfoEXT::initialize(const safe_VkSampleLocationsInfoE
}
}

safe_VkAttachmentSampleLocationsEXT::safe_VkAttachmentSampleLocationsEXT(const VkAttachmentSampleLocationsEXT* in_struct,
[[maybe_unused]] PNextCopyState* copy_state)
: attachmentIndex(in_struct->attachmentIndex), sampleLocationsInfo(&in_struct->sampleLocationsInfo) {}

safe_VkAttachmentSampleLocationsEXT::safe_VkAttachmentSampleLocationsEXT() : attachmentIndex() {}

safe_VkAttachmentSampleLocationsEXT::safe_VkAttachmentSampleLocationsEXT(const safe_VkAttachmentSampleLocationsEXT& copy_src) {
attachmentIndex = copy_src.attachmentIndex;
sampleLocationsInfo.initialize(&copy_src.sampleLocationsInfo);
}

safe_VkAttachmentSampleLocationsEXT& safe_VkAttachmentSampleLocationsEXT::operator=(
const safe_VkAttachmentSampleLocationsEXT& copy_src) {
if (&copy_src == this) return *this;

attachmentIndex = copy_src.attachmentIndex;
sampleLocationsInfo.initialize(&copy_src.sampleLocationsInfo);

return *this;
}

safe_VkAttachmentSampleLocationsEXT::~safe_VkAttachmentSampleLocationsEXT() {}

void safe_VkAttachmentSampleLocationsEXT::initialize(const VkAttachmentSampleLocationsEXT* in_struct,
[[maybe_unused]] PNextCopyState* copy_state) {
attachmentIndex = in_struct->attachmentIndex;
sampleLocationsInfo.initialize(&in_struct->sampleLocationsInfo);
}

void safe_VkAttachmentSampleLocationsEXT::initialize(const safe_VkAttachmentSampleLocationsEXT* copy_src,
[[maybe_unused]] PNextCopyState* copy_state) {
attachmentIndex = copy_src->attachmentIndex;
sampleLocationsInfo.initialize(&copy_src->sampleLocationsInfo);
}

safe_VkSubpassSampleLocationsEXT::safe_VkSubpassSampleLocationsEXT(const VkSubpassSampleLocationsEXT* in_struct,
[[maybe_unused]] PNextCopyState* copy_state)
: subpassIndex(in_struct->subpassIndex), sampleLocationsInfo(&in_struct->sampleLocationsInfo) {}

safe_VkSubpassSampleLocationsEXT::safe_VkSubpassSampleLocationsEXT() : subpassIndex() {}

safe_VkSubpassSampleLocationsEXT::safe_VkSubpassSampleLocationsEXT(const safe_VkSubpassSampleLocationsEXT& copy_src) {
subpassIndex = copy_src.subpassIndex;
sampleLocationsInfo.initialize(&copy_src.sampleLocationsInfo);
}

safe_VkSubpassSampleLocationsEXT& safe_VkSubpassSampleLocationsEXT::operator=(const safe_VkSubpassSampleLocationsEXT& copy_src) {
if (&copy_src == this) return *this;

subpassIndex = copy_src.subpassIndex;
sampleLocationsInfo.initialize(&copy_src.sampleLocationsInfo);

return *this;
}

safe_VkSubpassSampleLocationsEXT::~safe_VkSubpassSampleLocationsEXT() {}

void safe_VkSubpassSampleLocationsEXT::initialize(const VkSubpassSampleLocationsEXT* in_struct,
[[maybe_unused]] PNextCopyState* copy_state) {
subpassIndex = in_struct->subpassIndex;
sampleLocationsInfo.initialize(&in_struct->sampleLocationsInfo);
}

void safe_VkSubpassSampleLocationsEXT::initialize(const safe_VkSubpassSampleLocationsEXT* copy_src,
[[maybe_unused]] PNextCopyState* copy_state) {
subpassIndex = copy_src->subpassIndex;
sampleLocationsInfo.initialize(&copy_src->sampleLocationsInfo);
}

safe_VkRenderPassSampleLocationsBeginInfoEXT::safe_VkRenderPassSampleLocationsBeginInfoEXT(
const VkRenderPassSampleLocationsBeginInfoEXT* in_struct, [[maybe_unused]] PNextCopyState* copy_state, bool copy_pnext)
: sType(in_struct->sType),
Expand All @@ -2698,16 +2767,17 @@ safe_VkRenderPassSampleLocationsBeginInfoEXT::safe_VkRenderPassSampleLocationsBe
if (copy_pnext) {
pNext = SafePnextCopy(in_struct->pNext, copy_state);
}
if (in_struct->pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new VkAttachmentSampleLocationsEXT[in_struct->attachmentInitialSampleLocationsCount];
memcpy((void*)pAttachmentInitialSampleLocations, (void*)in_struct->pAttachmentInitialSampleLocations,
sizeof(VkAttachmentSampleLocationsEXT) * in_struct->attachmentInitialSampleLocationsCount);
if (attachmentInitialSampleLocationsCount && in_struct->pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new safe_VkAttachmentSampleLocationsEXT[attachmentInitialSampleLocationsCount];
for (uint32_t i = 0; i < attachmentInitialSampleLocationsCount; ++i) {
pAttachmentInitialSampleLocations[i].initialize(&in_struct->pAttachmentInitialSampleLocations[i]);
}
}

if (in_struct->pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new VkSubpassSampleLocationsEXT[in_struct->postSubpassSampleLocationsCount];
memcpy((void*)pPostSubpassSampleLocations, (void*)in_struct->pPostSubpassSampleLocations,
sizeof(VkSubpassSampleLocationsEXT) * in_struct->postSubpassSampleLocationsCount);
if (postSubpassSampleLocationsCount && in_struct->pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new safe_VkSubpassSampleLocationsEXT[postSubpassSampleLocationsCount];
for (uint32_t i = 0; i < postSubpassSampleLocationsCount; ++i) {
pPostSubpassSampleLocations[i].initialize(&in_struct->pPostSubpassSampleLocations[i]);
}
}
}

Expand All @@ -2727,17 +2797,17 @@ safe_VkRenderPassSampleLocationsBeginInfoEXT::safe_VkRenderPassSampleLocationsBe
postSubpassSampleLocationsCount = copy_src.postSubpassSampleLocationsCount;
pPostSubpassSampleLocations = nullptr;
pNext = SafePnextCopy(copy_src.pNext);

if (copy_src.pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new VkAttachmentSampleLocationsEXT[copy_src.attachmentInitialSampleLocationsCount];
memcpy((void*)pAttachmentInitialSampleLocations, (void*)copy_src.pAttachmentInitialSampleLocations,
sizeof(VkAttachmentSampleLocationsEXT) * copy_src.attachmentInitialSampleLocationsCount);
if (attachmentInitialSampleLocationsCount && copy_src.pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new safe_VkAttachmentSampleLocationsEXT[attachmentInitialSampleLocationsCount];
for (uint32_t i = 0; i < attachmentInitialSampleLocationsCount; ++i) {
pAttachmentInitialSampleLocations[i].initialize(&copy_src.pAttachmentInitialSampleLocations[i]);
}
}

if (copy_src.pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new VkSubpassSampleLocationsEXT[copy_src.postSubpassSampleLocationsCount];
memcpy((void*)pPostSubpassSampleLocations, (void*)copy_src.pPostSubpassSampleLocations,
sizeof(VkSubpassSampleLocationsEXT) * copy_src.postSubpassSampleLocationsCount);
if (postSubpassSampleLocationsCount && copy_src.pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new safe_VkSubpassSampleLocationsEXT[postSubpassSampleLocationsCount];
for (uint32_t i = 0; i < postSubpassSampleLocationsCount; ++i) {
pPostSubpassSampleLocations[i].initialize(&copy_src.pPostSubpassSampleLocations[i]);
}
}
}

Expand All @@ -2755,17 +2825,17 @@ safe_VkRenderPassSampleLocationsBeginInfoEXT& safe_VkRenderPassSampleLocationsBe
postSubpassSampleLocationsCount = copy_src.postSubpassSampleLocationsCount;
pPostSubpassSampleLocations = nullptr;
pNext = SafePnextCopy(copy_src.pNext);

if (copy_src.pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new VkAttachmentSampleLocationsEXT[copy_src.attachmentInitialSampleLocationsCount];
memcpy((void*)pAttachmentInitialSampleLocations, (void*)copy_src.pAttachmentInitialSampleLocations,
sizeof(VkAttachmentSampleLocationsEXT) * copy_src.attachmentInitialSampleLocationsCount);
if (attachmentInitialSampleLocationsCount && copy_src.pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new safe_VkAttachmentSampleLocationsEXT[attachmentInitialSampleLocationsCount];
for (uint32_t i = 0; i < attachmentInitialSampleLocationsCount; ++i) {
pAttachmentInitialSampleLocations[i].initialize(&copy_src.pAttachmentInitialSampleLocations[i]);
}
}

if (copy_src.pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new VkSubpassSampleLocationsEXT[copy_src.postSubpassSampleLocationsCount];
memcpy((void*)pPostSubpassSampleLocations, (void*)copy_src.pPostSubpassSampleLocations,
sizeof(VkSubpassSampleLocationsEXT) * copy_src.postSubpassSampleLocationsCount);
if (postSubpassSampleLocationsCount && copy_src.pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new safe_VkSubpassSampleLocationsEXT[postSubpassSampleLocationsCount];
for (uint32_t i = 0; i < postSubpassSampleLocationsCount; ++i) {
pPostSubpassSampleLocations[i].initialize(&copy_src.pPostSubpassSampleLocations[i]);
}
}

return *this;
Expand All @@ -2788,17 +2858,17 @@ void safe_VkRenderPassSampleLocationsBeginInfoEXT::initialize(const VkRenderPass
postSubpassSampleLocationsCount = in_struct->postSubpassSampleLocationsCount;
pPostSubpassSampleLocations = nullptr;
pNext = SafePnextCopy(in_struct->pNext, copy_state);

if (in_struct->pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new VkAttachmentSampleLocationsEXT[in_struct->attachmentInitialSampleLocationsCount];
memcpy((void*)pAttachmentInitialSampleLocations, (void*)in_struct->pAttachmentInitialSampleLocations,
sizeof(VkAttachmentSampleLocationsEXT) * in_struct->attachmentInitialSampleLocationsCount);
if (attachmentInitialSampleLocationsCount && in_struct->pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new safe_VkAttachmentSampleLocationsEXT[attachmentInitialSampleLocationsCount];
for (uint32_t i = 0; i < attachmentInitialSampleLocationsCount; ++i) {
pAttachmentInitialSampleLocations[i].initialize(&in_struct->pAttachmentInitialSampleLocations[i]);
}
}

if (in_struct->pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new VkSubpassSampleLocationsEXT[in_struct->postSubpassSampleLocationsCount];
memcpy((void*)pPostSubpassSampleLocations, (void*)in_struct->pPostSubpassSampleLocations,
sizeof(VkSubpassSampleLocationsEXT) * in_struct->postSubpassSampleLocationsCount);
if (postSubpassSampleLocationsCount && in_struct->pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new safe_VkSubpassSampleLocationsEXT[postSubpassSampleLocationsCount];
for (uint32_t i = 0; i < postSubpassSampleLocationsCount; ++i) {
pPostSubpassSampleLocations[i].initialize(&in_struct->pPostSubpassSampleLocations[i]);
}
}
}

Expand All @@ -2810,17 +2880,17 @@ void safe_VkRenderPassSampleLocationsBeginInfoEXT::initialize(const safe_VkRende
postSubpassSampleLocationsCount = copy_src->postSubpassSampleLocationsCount;
pPostSubpassSampleLocations = nullptr;
pNext = SafePnextCopy(copy_src->pNext);

if (copy_src->pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new VkAttachmentSampleLocationsEXT[copy_src->attachmentInitialSampleLocationsCount];
memcpy((void*)pAttachmentInitialSampleLocations, (void*)copy_src->pAttachmentInitialSampleLocations,
sizeof(VkAttachmentSampleLocationsEXT) * copy_src->attachmentInitialSampleLocationsCount);
if (attachmentInitialSampleLocationsCount && copy_src->pAttachmentInitialSampleLocations) {
pAttachmentInitialSampleLocations = new safe_VkAttachmentSampleLocationsEXT[attachmentInitialSampleLocationsCount];
for (uint32_t i = 0; i < attachmentInitialSampleLocationsCount; ++i) {
pAttachmentInitialSampleLocations[i].initialize(&copy_src->pAttachmentInitialSampleLocations[i]);
}
}

if (copy_src->pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new VkSubpassSampleLocationsEXT[copy_src->postSubpassSampleLocationsCount];
memcpy((void*)pPostSubpassSampleLocations, (void*)copy_src->pPostSubpassSampleLocations,
sizeof(VkSubpassSampleLocationsEXT) * copy_src->postSubpassSampleLocationsCount);
if (postSubpassSampleLocationsCount && copy_src->pPostSubpassSampleLocations) {
pPostSubpassSampleLocations = new safe_VkSubpassSampleLocationsEXT[postSubpassSampleLocationsCount];
for (uint32_t i = 0; i < postSubpassSampleLocationsCount; ++i) {
pPostSubpassSampleLocations[i].initialize(&copy_src->pPostSubpassSampleLocations[i]);
}
}
}

Expand Down