Fix incorrect computation of pointer size
authorMarcin Kańtoch <marcin.kantoch@amd.com>
Tue, 31 Aug 2021 11:08:45 +0000 (13:08 +0200)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Fri, 8 Oct 2021 15:40:49 +0000 (15:40 +0000)
CTS always fills the array of pointers with a stride of 64-bits.
So, for 32-bits applications, each two 32-bits has one valid pointer
to instance of bottom-level acceleration structure.

To correct this the pointer size should be calculated as
sizeof(VkDeviceOrHostAddressConstKHR::hostAddress) for host built
top-level acceleration structure and
sizeof(VkDeviceOrHostAddressConstKHR::deviceAddress) for device built
top-level acceleration structure.

VK-GL-CTS issue: 3084
Components: Vulkan

Affects:
dEQP-VK.ray*instances_aop*

Change-Id: I8c412a5a5d2ce3f1f687795768d6d83ad4913892

external/vulkancts/framework/vulkan/vkRayTracingUtil.cpp

index e5601bf..2288f12 100644 (file)
@@ -1826,7 +1826,8 @@ void TopLevelAccelerationStructureKHR::create (const DeviceInterface&                             vk,
 
        if (m_useArrayOfPointers)
        {
-               const VkBufferCreateInfo        bufferCreateInfo = makeBufferCreateInfo(m_bottomLevelInstances.size() * sizeof(VkDeviceOrHostAddressConstKHR), VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
+               const size_t                            pointerSize = (m_buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) ? sizeof(VkDeviceOrHostAddressConstKHR::deviceAddress) : sizeof(VkDeviceOrHostAddressConstKHR::hostAddress);
+               const VkBufferCreateInfo        bufferCreateInfo = makeBufferCreateInfo(static_cast<VkDeviceSize>(m_bottomLevelInstances.size() * pointerSize), VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
                m_instanceAddressBuffer = de::MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, bufferCreateInfo, MemoryRequirement::HostVisible | MemoryRequirement::Coherent | MemoryRequirement::DeviceAddress));
        }
 
@@ -2076,8 +2077,8 @@ void TopLevelAccelerationStructureKHR::prepareInstances (const DeviceInterface&
                                        VkDeviceOrHostAddressConstKHR   currentInstance;
                                        currentInstance.deviceAddress   = firstInstance.deviceAddress + instanceNdx * sizeof(VkAccelerationStructureInstanceKHR);
 
-                                       deMemcpy(&bufferStart[bufferOffset], &currentInstance, sizeof(VkDeviceOrHostAddressConstKHR));
-                                       bufferOffset += sizeof(VkDeviceOrHostAddressConstKHR);
+                                       deMemcpy(&bufferStart[bufferOffset], &currentInstance, sizeof(VkDeviceOrHostAddressConstKHR::deviceAddress));
+                                       bufferOffset += sizeof(VkDeviceOrHostAddressConstKHR::deviceAddress);
                                }
                                flushMappedMemoryRange(vk, device, m_instanceAddressBuffer->getAllocation().getMemory(), m_instanceAddressBuffer->getAllocation().getOffset(), VK_WHOLE_SIZE);
 
@@ -2102,8 +2103,8 @@ void TopLevelAccelerationStructureKHR::prepareInstances (const DeviceInterface&
                                        VkDeviceOrHostAddressConstKHR   currentInstance;
                                        currentInstance.hostAddress     = (deUint8*)m_instanceBuffer->getAllocation().getHostPtr() + instanceNdx * sizeof(VkAccelerationStructureInstanceKHR);
 
-                                       deMemcpy(&bufferStart[bufferOffset], &currentInstance, sizeof(VkDeviceOrHostAddressConstKHR));
-                                       bufferOffset += sizeof(VkDeviceOrHostAddressConstKHR);
+                                       deMemcpy(&bufferStart[bufferOffset], &currentInstance, sizeof(VkDeviceOrHostAddressConstKHR::hostAddress));
+                                       bufferOffset += sizeof(VkDeviceOrHostAddressConstKHR::hostAddress);
                                }
                                instancesData = makeDeviceOrHostAddressConstKHR(m_instanceAddressBuffer->getAllocation().getHostPtr());
                        }