Add alignment check to CL_DEVICE_MEM_BASE_ADDR_ALIGN for compressed buffers
Change-Id: I44fa231411a754fb24398a4a9727ca16f257220e Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
parent
e9a35fbf88
commit
cefa3e3119
|
@ -98,6 +98,11 @@ inline bool isAligned(T *ptr) {
|
|||
return ((reinterpret_cast<uintptr_t>(ptr)) % alignment) == 0;
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline bool isAligned(T1 ptr, T2 alignment) {
|
||||
return ((static_cast<size_t>(ptr)) & (static_cast<size_t>(alignment) - 1u)) == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool isAligned(T *ptr) {
|
||||
return (reinterpret_cast<uintptr_t>(ptr) & (alignof(T) - 1)) == 0;
|
||||
|
|
|
@ -61,12 +61,17 @@ bool Buffer::isSubBuffer() {
|
|||
}
|
||||
|
||||
bool Buffer::isValidSubBufferOffset(size_t offset) {
|
||||
for (size_t i = 0; i < context->getNumDevices(); ++i) {
|
||||
cl_uint address_align = 32; // 4 byte alignment
|
||||
if ((offset & (address_align / 8 - 1)) == 0) {
|
||||
return true;
|
||||
if (this->getGraphicsAllocation()->getAllocationType() == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED) {
|
||||
// From spec: "origin value is aligned to the CL_DEVICE_MEM_BASE_ADDR_ALIGN value"
|
||||
if (!isAligned(offset, this->getContext()->getDevice(0)->getDeviceInfo().memBaseAddressAlign)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
cl_uint address_align = 32; // 4 byte alignment
|
||||
if ((offset & (address_align / 8 - 1)) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,14 @@ TEST_F(SubBufferTest, GivenAlignmentThatIsHigherThen4BytesWhenCheckedForValidity
|
|||
EXPECT_TRUE(buffer->isValidSubBufferOffset(region2.origin));
|
||||
cl_buffer_region region3 = {8, 4};
|
||||
EXPECT_TRUE(buffer->isValidSubBufferOffset(region3.origin));
|
||||
|
||||
buffer->getGraphicsAllocation()->setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
|
||||
EXPECT_FALSE(buffer->isValidSubBufferOffset(region.origin));
|
||||
EXPECT_FALSE(buffer->isValidSubBufferOffset(region2.origin));
|
||||
cl_buffer_region region4 = {1025, 4};
|
||||
EXPECT_FALSE(buffer->isValidSubBufferOffset(region4.origin));
|
||||
cl_buffer_region region5 = {1024, 4};
|
||||
EXPECT_TRUE(buffer->isValidSubBufferOffset(region5.origin));
|
||||
}
|
||||
|
||||
TEST_F(SubBufferTest, givenSharingHandlerFromParentBufferWhenCreateThenShareHandler) {
|
||||
|
|
Loading…
Reference in New Issue