@@ -19,11 +19,15 @@ static void trace()
1919 vulkan_setup_t vulkan = test_init (TEST_NAME_1, reqs);
2020
2121 VkBuffer buf;
22+ VkBuffer buf2;
2223 VkBufferCreateInfo bufferCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, nullptr };
2324 bufferCreateInfo.size = BUFFER_SIZE;
2425 bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_KHR;
2526 bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
2627 VkResult result = trace_vkCreateBuffer (vulkan.device , &bufferCreateInfo, nullptr , &buf);
28+ check (result);
29+ result = trace_vkCreateBuffer (vulkan.device , &bufferCreateInfo, nullptr , &buf2);
30+ check (result);
2731
2832 VkMemoryRequirements req;
2933 trace_vkGetBufferMemoryRequirements (vulkan.device , buf, &req);
@@ -35,13 +39,15 @@ static void trace()
3539 VkMemoryAllocateInfo pAllocateMemInfo = {};
3640 pAllocateMemInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3741 pAllocateMemInfo.memoryTypeIndex = memoryTypeIndex;
38- pAllocateMemInfo.allocationSize = req. size ;
42+ pAllocateMemInfo.allocationSize = aligned_size * 2 ;
3943 VkDeviceMemory memory = 0 ;
4044 result = trace_vkAllocateMemory (vulkan.device , &pAllocateMemInfo, nullptr , &memory);
4145 check (result);
4246 assert (memory != 0 );
4347
48+ test_marker (vulkan, " Bind buffers" );
4449 trace_vkBindBufferMemory (vulkan.device , buf, memory, 0 );
50+ trace_vkBindBufferMemory (vulkan.device , buf2, memory, aligned_size);
4551
4652 VkBufferDeviceAddressInfo bdainfo = { VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO, nullptr };
4753 bdainfo.buffer = buf;
@@ -57,6 +63,7 @@ static void trace()
5763 ar.pMarkingTypes = markingTypes.data ();
5864 ar.pSubTypes = subTypes.data ();
5965
66+ test_marker (vulkan, " Device address at first byte - " + std::to_string (address));
6067 char * ptr = nullptr ;
6168 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
6269 check (result);
@@ -71,27 +78,82 @@ static void trace()
7178 testFlushMemory (vulkan, memory, 0 , pAllocateMemInfo.allocationSize , true , &ar);
7279 trace_vkUnmapMemory (vulkan.device , memory);
7380
74- // 8-byte-aligned address
81+ test_marker (vulkan, " Device address at bytes 32 and 128 " ); // 8-byte-aligned address
7582 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
7683 check (result);
7784 uint64_t * u64ptr = (uint64_t *)ptr;
85+ u64ptr[4 ] = address; // second address, on 8 byte aligned boundary
7886 u64ptr[16 ] = address; // second address, on 8 byte aligned boundary
79- ar.count = 1 ; // we only changed one value
80- offsets[0 ] = 16 * sizeof (uint64_t ); // and it is here
87+ ar.count = 2 ; // we only changed one value
88+ offsets[0 ] = 4 * sizeof (uint64_t ); // and it is here
89+ offsets[1 ] = 16 * sizeof (uint64_t ); // and it is here too
8190 testFlushMemory (vulkan, memory, 0 , pAllocateMemInfo.allocationSize , true , &ar);
8291 trace_vkUnmapMemory (vulkan.device , memory);
8392
84- // 4-byte-aligned address that is _not_ 8 byte aligned
93+ test_marker (vulkan, " Partial flush" );
94+ result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
95+ check (result);
96+ u64ptr = (uint64_t *)ptr;
97+ const VkDeviceSize flush_offset = 64 * sizeof (uint64_t );
98+ const VkDeviceSize flush_size = 32 * sizeof (uint64_t );
99+ const VkDeviceSize marked_offset = flush_offset + (4 * sizeof (uint64_t ));
100+ u64ptr[marked_offset / sizeof (uint64_t )] = address;
101+ ar.count = 1 ;
102+ offsets[0 ] = marked_offset - flush_offset;
103+ testFlushMemory (vulkan, memory, flush_offset, flush_size, true , &ar);
104+ trace_vkUnmapMemory (vulkan.device , memory);
105+
106+ test_marker (vulkan, " Flush with mapped offset" );
107+ result = trace_vkMapMemory (vulkan.device , memory, 192 , VK_WHOLE_SIZE, 0 , (void **)&ptr);
108+ check (result);
109+ u64ptr = (uint64_t *)ptr;
110+ *u64ptr = address;
111+ ar.count = 1 ;
112+ offsets[0 ] = 0 ;
113+ testFlushMemory (vulkan, memory, 192 , 64 , true , &ar);
114+ trace_vkUnmapMemory (vulkan.device , memory);
115+
116+ test_marker (vulkan, " Flush with mapped offset and limited window" );
117+ result = trace_vkMapMemory (vulkan.device , memory, 200 , 64 , 0 , (void **)&ptr);
118+ check (result);
119+ u64ptr = (uint64_t *)ptr;
120+ u64ptr[1 ] = address;
121+ ar.count = 1 ;
122+ offsets[0 ] = 8 ;
123+ testFlushMemory (vulkan, memory, 200 , VK_WHOLE_SIZE, true , &ar);
124+ trace_vkUnmapMemory (vulkan.device , memory);
125+
126+ test_marker (vulkan, " Flush with out of bounds offset" );
127+ result = trace_vkMapMemory (vulkan.device , memory, 8 , 64 , 0 , (void **)&ptr);
128+ check (result);
129+ ar.count = 1 ;
130+ offsets[0 ] = UINT32_MAX;
131+ testFlushMemory (vulkan, memory, 8 , VK_WHOLE_SIZE, true , &ar);
132+ trace_vkUnmapMemory (vulkan.device , memory);
133+
134+ test_marker (vulkan, " Device address on a 4 byte alignment" );
85135 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
86136 check (result);
87137 u64ptr = (uint64_t *)(ptr + 4 );
88138 u64ptr[64 ] = address; // add one more address at non-8-byte-aligned boundary
89139 ar.count = 1 ; // we still only changed one value
90- offsets[0 ] = 64 * sizeof (uint32_t ) ; // and it is here
140+ offsets[0 ] = 64 * sizeof (uint64_t ) + 4 ; // and it is here
91141 testFlushMemory (vulkan, memory, 0 , pAllocateMemInfo.allocationSize , true , &ar);
92142 trace_vkUnmapMemory (vulkan.device , memory);
93143
94- // no address changes -- send empty address list
144+ test_marker (vulkan, " Device address in a second buffer and flush covering both" );
145+ result = trace_vkMapMemory (vulkan.device , memory, 0 , VK_WHOLE_SIZE, 0 , (void **)&ptr);
146+ check (result);
147+ u64ptr = (uint64_t *)(ptr + aligned_size);
148+ u64ptr[0 ] = address;
149+ u64ptr[1 ] = address;
150+ ar.count = 2 ;
151+ offsets[0 ] = aligned_size;
152+ offsets[1 ] = aligned_size + 8 ;
153+ testFlushMemory (vulkan, memory, 0 , VK_WHOLE_SIZE, true , &ar);
154+ trace_vkUnmapMemory (vulkan.device , memory);
155+
156+ test_marker (vulkan, " No address changes, empty address list sent" );
95157 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
96158 check (result);
97159 u64ptr = (uint64_t *)ptr;
@@ -100,30 +162,30 @@ static void trace()
100162 testFlushMemory (vulkan, memory, 0 , pAllocateMemInfo.allocationSize , true , &ar);
101163 trace_vkUnmapMemory (vulkan.device , memory);
102164
103- // no address changes -- no address list
165+ test_marker (vulkan, " No address changes, no address list sent " );
104166 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
105167 check (result);
106168 u64ptr = (uint64_t *)ptr;
107169 u64ptr[20 ] = 0 ;
108170 testFlushMemory (vulkan, memory, 0 , pAllocateMemInfo.allocationSize , true , nullptr );
109171 trace_vkUnmapMemory (vulkan.device , memory);
110172
111- // no address changes -- no info bit , just flush
173+ test_marker (vulkan, " No address changes, just flush" );
112174 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
113175 check (result);
114176 u64ptr = (uint64_t *)ptr;
115177 u64ptr[21 ] = 0 ;
116178 testFlushMemory (vulkan, memory, 0 , pAllocateMemInfo.allocationSize , false , nullptr );
117179 trace_vkUnmapMemory (vulkan.device , memory);
118180
119- // no address changes -- no flush even
181+ test_marker (vulkan, " No address changes, no flush" );
120182 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
121183 check (result);
122184 u64ptr = (uint64_t *)ptr;
123185 u64ptr[22 ] = 0 ;
124186 trace_vkUnmapMemory (vulkan.device , memory);
125187
126- // remove all addresses -- notice their removal if we scan for them
188+ test_marker (vulkan, " Reset buffer back to dead pattern and flush " );
127189 result = trace_vkMapMemory (vulkan.device , memory, 0 , pAllocateMemInfo.allocationSize , 0 , (void **)&ptr);
128190 check (result);
129191 u32ptr = (uint32_t *)ptr;
0 commit comments