safe_struct: Copy every pSampleMask word

In 2017 (VVL GH1383) the generator read the latexmath length of
pSampleMask as rasterizationSamples/32, which is 0 below 32 samples, so
the copy was empty. The fix copied a single element for every length
with a division. The length now comes from altlen as
(rasterizationSamples + 31) / 32.

pSampleMask is the only such array without custom code (pCode has its
own). A 64-sample mask loses its second word, so VVL reads past the copy
when it compares two words for pLibraries-06635 and reports the error at
random.

Copy the whole array, and put the length in parentheses since it is
multiplied by the element size.
diff --git a/scripts/generators/safe_struct_generator.py b/scripts/generators/safe_struct_generator.py
index 5c3d824..3b74335 100644
--- a/scripts/generators/safe_struct_generator.py
+++ b/scripts/generators/safe_struct_generator.py
@@ -667,7 +667,7 @@
                             construct_txt += f'{member.name} = in_struct->{member.name};\n'
                         else:
                             init_func_txt += f'{member.name} = nullptr;\n'
-                            if not member.fixedSizeArray and (member.length is None or '/' in member.length):
+                            if not member.fixedSizeArray and member.length is None:
                                 construct_txt += f'''
                                     if (in_struct->{member.name}) {{
                                             {member.name} = new {m_type}(*in_struct->{member.name});
@@ -680,6 +680,9 @@
                                 decorated_length = member.length
                                 for other_member in struct.members:
                                     decorated_length = re.sub(r'\b({})\b'.format(other_member.name), r'in_struct->\1', decorated_length)
+                                if '/' in decorated_length:
+                                    # Multiplied by the element size below
+                                    decorated_length = f'({decorated_length})'
                                 try:
                                     concurrent_clause = member_construct_conditions[member.name](struct, member)
                                 except:
diff --git a/src/vulkan/vk_safe_struct_core.cpp b/src/vulkan/vk_safe_struct_core.cpp
index 2bbf69f..8359975 100644
--- a/src/vulkan/vk_safe_struct_core.cpp
+++ b/src/vulkan/vk_safe_struct_core.cpp
@@ -4488,7 +4488,9 @@
         pNext = SafePnextCopy(in_struct->pNext, copy_state);
     }
     if (in_struct->pSampleMask) {
-        pSampleMask = new VkSampleMask(*in_struct->pSampleMask);
+        pSampleMask = new VkSampleMask[((in_struct->rasterizationSamples + 31) / 32)];
+        memcpy((void*)pSampleMask, (void*)in_struct->pSampleMask,
+               sizeof(VkSampleMask) * ((in_struct->rasterizationSamples + 31) / 32));
     }
 }
 
@@ -4516,7 +4518,8 @@
     pNext = SafePnextCopy(copy_src.pNext);
 
     if (copy_src.pSampleMask) {
-        pSampleMask = new VkSampleMask(*copy_src.pSampleMask);
+        pSampleMask = new VkSampleMask[((copy_src.rasterizationSamples + 31) / 32)];
+        memcpy((void*)pSampleMask, (void*)copy_src.pSampleMask, sizeof(VkSampleMask) * ((copy_src.rasterizationSamples + 31) / 32));
     }
 }
 
@@ -4524,7 +4527,7 @@
     const safe_VkPipelineMultisampleStateCreateInfo& copy_src) {
     if (&copy_src == this) return *this;
 
-    if (pSampleMask) delete pSampleMask;
+    if (pSampleMask) delete[] pSampleMask;
     FreePnextChain(pNext);
 
     sType = copy_src.sType;
@@ -4538,20 +4541,21 @@
     pNext = SafePnextCopy(copy_src.pNext);
 
     if (copy_src.pSampleMask) {
-        pSampleMask = new VkSampleMask(*copy_src.pSampleMask);
+        pSampleMask = new VkSampleMask[((copy_src.rasterizationSamples + 31) / 32)];
+        memcpy((void*)pSampleMask, (void*)copy_src.pSampleMask, sizeof(VkSampleMask) * ((copy_src.rasterizationSamples + 31) / 32));
     }
 
     return *this;
 }
 
 safe_VkPipelineMultisampleStateCreateInfo::~safe_VkPipelineMultisampleStateCreateInfo() {
-    if (pSampleMask) delete pSampleMask;
+    if (pSampleMask) delete[] pSampleMask;
     FreePnextChain(pNext);
 }
 
 void safe_VkPipelineMultisampleStateCreateInfo::initialize(const VkPipelineMultisampleStateCreateInfo* in_struct,
                                                            [[maybe_unused]] PNextCopyState* copy_state) {
-    if (pSampleMask) delete pSampleMask;
+    if (pSampleMask) delete[] pSampleMask;
     FreePnextChain(pNext);
     sType = in_struct->sType;
     flags = in_struct->flags;
@@ -4564,7 +4568,9 @@
     pNext = SafePnextCopy(in_struct->pNext, copy_state);
 
     if (in_struct->pSampleMask) {
-        pSampleMask = new VkSampleMask(*in_struct->pSampleMask);
+        pSampleMask = new VkSampleMask[((in_struct->rasterizationSamples + 31) / 32)];
+        memcpy((void*)pSampleMask, (void*)in_struct->pSampleMask,
+               sizeof(VkSampleMask) * ((in_struct->rasterizationSamples + 31) / 32));
     }
 }
 
@@ -4581,7 +4587,9 @@
     pNext = SafePnextCopy(copy_src->pNext);
 
     if (copy_src->pSampleMask) {
-        pSampleMask = new VkSampleMask(*copy_src->pSampleMask);
+        pSampleMask = new VkSampleMask[((copy_src->rasterizationSamples + 31) / 32)];
+        memcpy((void*)pSampleMask, (void*)copy_src->pSampleMask,
+               sizeof(VkSampleMask) * ((copy_src->rasterizationSamples + 31) / 32));
     }
 }
 
diff --git a/tests/safe_struct.cpp b/tests/safe_struct.cpp
index c742826..35570f4 100644
--- a/tests/safe_struct.cpp
+++ b/tests/safe_struct.cpp
@@ -331,3 +331,22 @@
     ASSERT_NE(nullptr, copied.info.pPipelineInfo);
     EXPECT_EQ(7u, copied.info.pPipelineInfo->maxPipelineCount);
 }
+
+TEST(safe_struct, multisample_sample_mask_64) {
+    const std::array<VkSampleMask, 2> sample_mask = {0xAAAAAAAA, 0x55555555};
+    VkPipelineMultisampleStateCreateInfo ms_ci = vku::InitStructHelper();
+    ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_64_BIT;
+    ms_ci.pSampleMask = sample_mask.data();
+
+    vku::safe_VkPipelineMultisampleStateCreateInfo safe_ms_ci(&ms_ci);
+    ASSERT_NE(sample_mask.data(), safe_ms_ci.pSampleMask);
+    ASSERT_EQ(sample_mask[0], safe_ms_ci.pSampleMask[0]);
+    ASSERT_EQ(sample_mask[1], safe_ms_ci.pSampleMask[1]);
+
+    vku::safe_VkPipelineMultisampleStateCreateInfo copy_ms_ci(safe_ms_ci);
+    ASSERT_EQ(sample_mask[1], copy_ms_ci.pSampleMask[1]);
+
+    vku::safe_VkPipelineMultisampleStateCreateInfo assigned_ms_ci;
+    assigned_ms_ci = safe_ms_ci;
+    ASSERT_EQ(sample_mask[1], assigned_ms_ci.pSampleMask[1]);
+}