2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-04 15:53:51 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-07-28 13:48:41 +08:00
|
|
|
|
2020-06-09 16:00:59 +08:00
|
|
|
#include "drm/i915_drm.h"
|
2020-07-28 13:48:41 +08:00
|
|
|
#include "engine_limits.h"
|
2020-06-09 16:00:59 +08:00
|
|
|
|
2020-07-28 13:48:41 +08:00
|
|
|
#include <array>
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <atomic>
|
2019-07-17 21:38:14 +08:00
|
|
|
#include <cstddef>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <stdint.h>
|
2020-05-06 18:37:15 +08:00
|
|
|
|
|
|
|
struct drm_i915_gem_exec_object2;
|
|
|
|
struct drm_i915_gem_relocation_entry;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class DrmMemoryManager;
|
|
|
|
class Drm;
|
|
|
|
|
|
|
|
class BufferObject {
|
|
|
|
friend DrmMemoryManager;
|
|
|
|
|
|
|
|
public:
|
2020-03-19 17:41:35 +08:00
|
|
|
BufferObject(Drm *drm, int handle, size_t size);
|
2018-02-28 19:09:48 +08:00
|
|
|
MOCKABLE_VIRTUAL ~BufferObject(){};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-07-17 19:40:52 +08:00
|
|
|
struct Deleter {
|
|
|
|
void operator()(BufferObject *bo) {
|
|
|
|
bo->close();
|
|
|
|
delete bo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool setTiling(uint32_t mode, uint32_t stride);
|
|
|
|
|
2020-07-31 13:45:48 +08:00
|
|
|
MOCKABLE_VIRTUAL int pin(BufferObject *const boToPin[], size_t numberOfBos, uint32_t vmHandleId, uint32_t drmContextId);
|
2018-02-28 19:09:48 +08:00
|
|
|
|
2020-07-31 13:45:48 +08:00
|
|
|
int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t vmHandleId, uint32_t drmContextId, BufferObject *const residency[], size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-07-28 13:48:41 +08:00
|
|
|
void bind(uint32_t vmHandleId);
|
|
|
|
void unbind(uint32_t vmHandleId);
|
2020-07-02 17:49:46 +08:00
|
|
|
|
2020-06-09 16:00:59 +08:00
|
|
|
void printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int wait(int64_t timeoutNs);
|
|
|
|
bool close();
|
|
|
|
|
|
|
|
inline void reference() {
|
|
|
|
this->refCount++;
|
|
|
|
}
|
|
|
|
uint32_t getRefCount() const;
|
|
|
|
|
2018-02-27 06:23:43 +08:00
|
|
|
size_t peekSize() const { return size; }
|
|
|
|
int peekHandle() const { return handle; }
|
2019-02-20 22:08:03 +08:00
|
|
|
uint64_t peekAddress() const { return gpuAddress; }
|
|
|
|
void setAddress(uint64_t address) { this->gpuAddress = address; }
|
2018-02-27 06:23:43 +08:00
|
|
|
void *peekLockedAddress() const { return lockedAddress; }
|
|
|
|
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
|
2017-12-21 07:45:38 +08:00
|
|
|
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
|
2018-02-27 06:23:43 +08:00
|
|
|
uint64_t peekUnmapSize() const { return unmapSize; }
|
2020-05-06 18:37:15 +08:00
|
|
|
bool peekIsReusableAllocation() const { return this->isReused; }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
protected:
|
2020-02-12 00:48:40 +08:00
|
|
|
Drm *drm = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
std::atomic<uint32_t> refCount;
|
|
|
|
|
|
|
|
int handle; // i915 gem object handle
|
2019-10-22 16:26:23 +08:00
|
|
|
uint64_t size;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool isReused;
|
|
|
|
|
|
|
|
//Tiling
|
|
|
|
uint32_t tiling_mode;
|
|
|
|
|
2020-07-31 13:45:48 +08:00
|
|
|
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_t vmHandleId, uint32_t drmContextId);
|
|
|
|
void fillExecObjectImpl(drm_i915_gem_exec_object2 &execObject, uint32_t vmHandleId);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-20 22:08:03 +08:00
|
|
|
uint64_t gpuAddress = 0llu;
|
|
|
|
|
2018-02-27 06:23:43 +08:00
|
|
|
void *lockedAddress; // CPU side virtual address
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
uint64_t unmapSize = 0;
|
2020-07-28 13:48:41 +08:00
|
|
|
|
|
|
|
std::array<bool, EngineLimits::maxHandleCount> bindInfo;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|