@@ -32,6 +32,7 @@ namespace NEO {
3232BufferObject::BufferObject (Drm *drm, int handle, size_t size) : drm(drm), refCount(1 ), handle(handle), size(size), isReused(false ) {
3333 this ->tiling_mode = I915_TILING_NONE;
3434 this ->lockedAddress = nullptr ;
35+ bindInfo.fill (false );
3536}
3637
3738uint32_t BufferObject::getRefCount () const {
@@ -128,18 +129,24 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo
128129 return err;
129130}
130131
131- void BufferObject::bind (uint32_t drmContextId) {
132- auto ret = this ->drm ->bindBufferObject (drmContextId, this );
133- auto err = this ->drm ->getErrno ();
134- printDebugString (DebugManager.flags .PrintDebugMessages .get (), stderr, " bind buffer object returned with %d. errno=%d(%s)\n " , ret, err, strerror (err));
135- UNRECOVERABLE_IF (ret != 0 );
132+ void BufferObject::bind (uint32_t vmHandleId) {
133+ if (!this ->bindInfo [vmHandleId]) {
134+ auto ret = this ->drm ->bindBufferObject (vmHandleId, this );
135+ auto err = this ->drm ->getErrno ();
136+ printDebugString (DebugManager.flags .PrintDebugMessages .get (), stderr, " bind buffer object returned with %d. errno=%d(%s)\n " , ret, err, strerror (err));
137+ UNRECOVERABLE_IF (ret != 0 );
138+ this ->bindInfo [vmHandleId] = true ;
139+ }
136140}
137141
138- void BufferObject::unbind (uint32_t drmContextId) {
139- auto ret = this ->drm ->unbindBufferObject (drmContextId, this );
140- auto err = this ->drm ->getErrno ();
141- printDebugString (DebugManager.flags .PrintDebugMessages .get (), stderr, " unbind buffer object returned with %d. errno=%d(%s)\n " , ret, err, strerror (err));
142- UNRECOVERABLE_IF (ret != 0 );
142+ void BufferObject::unbind (uint32_t vmHandleId) {
143+ if (this ->bindInfo [vmHandleId]) {
144+ auto ret = this ->drm ->unbindBufferObject (vmHandleId, this );
145+ auto err = this ->drm ->getErrno ();
146+ printDebugString (DebugManager.flags .PrintDebugMessages .get (), stderr, " unbind buffer object returned with %d. errno=%d(%s)\n " , ret, err, strerror (err));
147+ UNRECOVERABLE_IF (ret != 0 );
148+ this ->bindInfo [vmHandleId] = false ;
149+ }
143150}
144151
145152void BufferObject::printExecutionBuffer (drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage) {
0 commit comments