Skip to content

Commit 06a7d8c

Browse files
Decouple Buffer Object and Exec Objects Storage.
Change-Id: Id47c071372959d43ccf3034917f2a5c39b707b38 Signed-off-by: Mrozek, Michal <[email protected]>
1 parent f24b428 commit 06a7d8c

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

runtime/os_interface/linux/drm_buffer_object.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace OCLRT {
3232
BufferObject::BufferObject(Drm *drm, int handle, bool isAllocated) : drm(drm), refCount(1), handle(handle), isReused(false), isAllocated(isAllocated) {
3333
this->tiling_mode = I915_TILING_NONE;
3434
this->stride = 0;
35-
execObjectsStorage = nullptr;
3635
this->size = 0;
3736
this->lockedAddress = nullptr;
3837
}
@@ -108,18 +107,18 @@ void BufferObject::fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_
108107
execObject.rsvd2 = 0;
109108
}
110109

111-
void BufferObject::processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency) {
110+
void BufferObject::processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency, drm_i915_gem_exec_object2 *execObjectsStorage) {
112111
for (size_t i = 0; i < residency.size(); i++) {
113112
residency[i]->fillExecObject(execObjectsStorage[idx], drmContextId);
114113
idx++;
115114
}
116115
}
117116

118-
int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, ResidencyVector &residency) {
117+
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) {
119118
drm_i915_gem_execbuffer2 execbuf = {};
120119

121120
int idx = 0;
122-
processRelocs(idx, drmContextId, residency);
121+
processRelocs(idx, drmContextId, residency, execObjectsStorage);
123122
this->fillExecObject(execObjectsStorage[idx], drmContextId);
124123
idx++;
125124

runtime/os_interface/linux/drm_buffer_object.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BufferObject {
4242

4343
MOCKABLE_VIRTUAL int pin(BufferObject *const boToPin[], size_t numberOfBos, uint32_t drmContextId);
4444

45-
int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, ResidencyVector &residency);
45+
int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, ResidencyVector &residency, drm_i915_gem_exec_object2 *execObjectsStorage);
4646

4747
int wait(int64_t timeoutNs);
4848
bool close();
@@ -61,9 +61,6 @@ class BufferObject {
6161
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
6262
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
6363
uint64_t peekUnmapSize() const { return unmapSize; }
64-
void setExecObjectsStorage(drm_i915_gem_exec_object2 *storage) {
65-
execObjectsStorage = storage;
66-
}
6764
StorageAllocatorType peekAllocationType() const { return storageAllocatorType; }
6865
void setAllocationType(StorageAllocatorType allocatorType) { this->storageAllocatorType = allocatorType; }
6966
bool peekIsReusableAllocation() { return this->isReused; }
@@ -75,8 +72,6 @@ class BufferObject {
7572

7673
std::atomic<uint32_t> refCount;
7774

78-
drm_i915_gem_exec_object2 *execObjectsStorage;
79-
8075
int handle; // i915 gem object handle
8176
bool isReused;
8277

@@ -85,7 +80,7 @@ class BufferObject {
8580
uint32_t stride;
8681

8782
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_t drmContextId);
88-
void processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency);
83+
void processRelocs(int &idx, uint32_t drmContextId, ResidencyVector &residency, drm_i915_gem_exec_object2 *execObjectsStorage);
8984

9085
uint64_t gpuAddress = 0llu;
9186

runtime/os_interface/linux/drm_command_stream.inl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ FlushStamp DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer,
6363
this->execObjectsStorage.resize(requiredSize);
6464
}
6565

66-
bb->setExecObjectsStorage(this->execObjectsStorage.data());
67-
6866
bb->exec(static_cast<uint32_t>(alignUp(batchBuffer.usedSize - batchBuffer.startOffset, 8)),
6967
alignedStart, engineFlag | I915_EXEC_NO_RELOC,
7068
batchBuffer.requiresCoherency,
7169
static_cast<OsContextLinux *>(osContext)->getDrmContextId(),
72-
this->residency);
70+
this->residency,
71+
this->execObjectsStorage.data());
7372

7473
this->residency.clear();
7574

unit_tests/os_interface/linux/drm_buffer_object_tests.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class DrmBufferObjectFixture {
4848
ASSERT_NE(nullptr, this->mock);
4949
bo = new TestedBufferObject(this->mock);
5050
ASSERT_NE(nullptr, bo);
51-
bo->setExecObjectsStorage(execObjectsStorage);
5251
}
5352

5453
void TearDown() {
@@ -69,7 +68,8 @@ TEST_F(DrmBufferObjectTest, exec) {
6968
mock->ioctl_res = 0;
7069

7170
BufferObject::ResidencyVector residency;
72-
auto ret = bo->exec(0, 0, 0, false, 1, residency);
71+
drm_i915_gem_exec_object2 execObjectsStorage = {};
72+
auto ret = bo->exec(0, 0, 0, false, 1, residency, &execObjectsStorage);
7373
EXPECT_EQ(mock->ioctl_res, ret);
7474
EXPECT_EQ(0u, mock->execBuffer.flags);
7575
}
@@ -78,7 +78,8 @@ TEST_F(DrmBufferObjectTest, exec_ioctlFailed) {
7878
mock->ioctl_expected.total = 1;
7979
mock->ioctl_res = -1;
8080
BufferObject::ResidencyVector residency;
81-
EXPECT_THROW(bo->exec(0, 0, 0, false, 1, residency), std::exception);
81+
drm_i915_gem_exec_object2 execObjectsStorage = {};
82+
EXPECT_THROW(bo->exec(0, 0, 0, false, 1, residency, &execObjectsStorage), std::exception);
8283
}
8384

8485
TEST_F(DrmBufferObjectTest, setTiling_success) {
@@ -145,8 +146,6 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
145146
ASSERT_NE(nullptr, mock.get());
146147
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
147148
ASSERT_NE(nullptr, bo.get());
148-
drm_i915_gem_exec_object2 execObjectsStorage[3];
149-
bo->setExecObjectsStorage(execObjectsStorage);
150149

151150
// fail DRM_IOCTL_I915_GEM_EXECBUFFER2 in pin
152151
mock->ioctl_res = -1;
@@ -168,8 +167,6 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
168167
ASSERT_NE(nullptr, mock.get());
169168
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
170169
ASSERT_NE(nullptr, bo.get());
171-
drm_i915_gem_exec_object2 execObjectsStorage[4];
172-
bo->setExecObjectsStorage(execObjectsStorage);
173170
mock->ioctl_res = 0;
174171

175172
std::unique_ptr<TestedBufferObject> boToPin(new TestedBufferObject(mock.get()));

0 commit comments

Comments
 (0)