diff --git a/runtime/os_interface/linux/drm_buffer_object.cpp b/runtime/os_interface/linux/drm_buffer_object.cpp index 287ba82a28..9b52834e86 100644 --- a/runtime/os_interface/linux/drm_buffer_object.cpp +++ b/runtime/os_interface/linux/drm_buffer_object.cpp @@ -32,7 +32,6 @@ namespace OCLRT { BufferObject::BufferObject(Drm *drm, int handle, bool isAllocated) : drm(drm), refCount(1), handle(handle), isReused(false), isAllocated(isAllocated) { this->tiling_mode = I915_TILING_NONE; this->stride = 0; - execObjectsStorage = nullptr; this->size = 0; this->lockedAddress = nullptr; } @@ -108,18 +107,18 @@ void BufferObject::fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_ execObject.rsvd2 = 0; } -void BufferObject::processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency) { +void BufferObject::processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency, drm_i915_gem_exec_object2 *execObjectsStorage) { for (size_t i = 0; i < residency.size(); i++) { residency[i]->fillExecObject(execObjectsStorage[idx], drmContextId); idx++; } } -int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, ResidencyVector &residency) { +int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, ResidencyVector &residency, drm_i915_gem_exec_object2 *execObjectsStorage) { drm_i915_gem_execbuffer2 execbuf = {}; int idx = 0; - processRelocs(idx, drmContextId, residency); + processRelocs(idx, drmContextId, residency, execObjectsStorage); this->fillExecObject(execObjectsStorage[idx], drmContextId); idx++; diff --git a/runtime/os_interface/linux/drm_buffer_object.h b/runtime/os_interface/linux/drm_buffer_object.h index 0584aeb1f9..9a26806c71 100644 --- a/runtime/os_interface/linux/drm_buffer_object.h +++ b/runtime/os_interface/linux/drm_buffer_object.h @@ -42,7 +42,7 @@ class BufferObject { MOCKABLE_VIRTUAL int pin(BufferObject *const boToPin[], size_t numberOfBos, uint32_t drmContextId); - int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, ResidencyVector &residency); + int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, ResidencyVector &residency, drm_i915_gem_exec_object2 *execObjectsStorage); int wait(int64_t timeoutNs); bool close(); @@ -61,9 +61,6 @@ class BufferObject { void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; } void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; } uint64_t peekUnmapSize() const { return unmapSize; } - void setExecObjectsStorage(drm_i915_gem_exec_object2 *storage) { - execObjectsStorage = storage; - } StorageAllocatorType peekAllocationType() const { return storageAllocatorType; } void setAllocationType(StorageAllocatorType allocatorType) { this->storageAllocatorType = allocatorType; } bool peekIsReusableAllocation() { return this->isReused; } @@ -75,8 +72,6 @@ class BufferObject { std::atomic refCount; - drm_i915_gem_exec_object2 *execObjectsStorage; - int handle; // i915 gem object handle bool isReused; @@ -85,7 +80,7 @@ class BufferObject { uint32_t stride; MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_t drmContextId); - void processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency); + void processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency, drm_i915_gem_exec_object2 *execObjectsStorage); uint64_t gpuAddress = 0llu; diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index 01618a7b16..32fad58536 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -63,13 +63,12 @@ FlushStamp DrmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, this->execObjectsStorage.resize(requiredSize); } - bb->setExecObjectsStorage(this->execObjectsStorage.data()); - bb->exec(static_cast(alignUp(batchBuffer.usedSize - batchBuffer.startOffset, 8)), alignedStart, engineFlag | I915_EXEC_NO_RELOC, batchBuffer.requiresCoherency, static_cast(osContext)->getDrmContextId(), - this->residency); + this->residency, + this->execObjectsStorage.data()); this->residency.clear(); diff --git a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp index 0c1157eb0e..24f8853407 100644 --- a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp +++ b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp @@ -48,7 +48,6 @@ class DrmBufferObjectFixture { ASSERT_NE(nullptr, this->mock); bo = new TestedBufferObject(this->mock); ASSERT_NE(nullptr, bo); - bo->setExecObjectsStorage(execObjectsStorage); } void TearDown() { @@ -69,7 +68,8 @@ TEST_F(DrmBufferObjectTest, exec) { mock->ioctl_res = 0; BufferObject::ResidencyVector residency; - auto ret = bo->exec(0, 0, 0, false, 1, residency); + drm_i915_gem_exec_object2 execObjectsStorage = {}; + auto ret = bo->exec(0, 0, 0, false, 1, residency, &execObjectsStorage); EXPECT_EQ(mock->ioctl_res, ret); EXPECT_EQ(0u, mock->execBuffer.flags); } @@ -78,7 +78,8 @@ TEST_F(DrmBufferObjectTest, exec_ioctlFailed) { mock->ioctl_expected.total = 1; mock->ioctl_res = -1; BufferObject::ResidencyVector residency; - EXPECT_THROW(bo->exec(0, 0, 0, false, 1, residency), std::exception); + drm_i915_gem_exec_object2 execObjectsStorage = {}; + EXPECT_THROW(bo->exec(0, 0, 0, false, 1, residency, &execObjectsStorage), std::exception); } TEST_F(DrmBufferObjectTest, setTiling_success) { @@ -145,8 +146,6 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned ASSERT_NE(nullptr, mock.get()); std::unique_ptr bo(new TestedBufferObject(mock.get())); ASSERT_NE(nullptr, bo.get()); - drm_i915_gem_exec_object2 execObjectsStorage[3]; - bo->setExecObjectsStorage(execObjectsStorage); // fail DRM_IOCTL_I915_GEM_EXECBUFFER2 in pin mock->ioctl_res = -1; @@ -168,8 +167,6 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) { ASSERT_NE(nullptr, mock.get()); std::unique_ptr bo(new TestedBufferObject(mock.get())); ASSERT_NE(nullptr, bo.get()); - drm_i915_gem_exec_object2 execObjectsStorage[4]; - bo->setExecObjectsStorage(execObjectsStorage); mock->ioctl_res = 0; std::unique_ptr boToPin(new TestedBufferObject(mock.get()));