2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-01-13 00:57:42 +08:00
|
|
|
* Copyright (C) 2018-2022 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
|
2022-01-13 00:57:42 +08:00
|
|
|
#include "shared/source/command_container/cmdcontainer.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdint>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-07-14 00:50:55 +08:00
|
|
|
class GraphicsAllocation;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class LinearStream {
|
|
|
|
public:
|
|
|
|
virtual ~LinearStream() = default;
|
2022-05-18 03:04:23 +08:00
|
|
|
LinearStream() = default;
|
2017-12-21 07:45:38 +08:00
|
|
|
LinearStream(void *buffer, size_t bufferSize);
|
2022-05-18 03:04:23 +08:00
|
|
|
LinearStream(GraphicsAllocation *gfxAllocation);
|
2019-06-26 21:23:34 +08:00
|
|
|
LinearStream(GraphicsAllocation *gfxAllocation, void *buffer, size_t bufferSize);
|
2022-01-13 00:57:42 +08:00
|
|
|
LinearStream(void *buffer, size_t bufferSize, CommandContainer *cmdContainer, size_t batchBufferEndSize);
|
2022-05-18 03:04:23 +08:00
|
|
|
|
|
|
|
LinearStream(const LinearStream &) = delete;
|
|
|
|
LinearStream &operator=(const LinearStream &) = delete;
|
|
|
|
|
2018-03-05 18:03:38 +08:00
|
|
|
void *getCpuBase() const;
|
2017-12-21 07:45:38 +08:00
|
|
|
void *getSpace(size_t size);
|
|
|
|
size_t getMaxAvailableSpace() const;
|
|
|
|
size_t getAvailableSpace() const;
|
|
|
|
size_t getUsed() const;
|
2022-03-29 22:11:50 +08:00
|
|
|
|
|
|
|
uint64_t getGpuBase() const;
|
2022-06-27 18:30:29 +08:00
|
|
|
void setGpuBase(uint64_t gpuAddress);
|
2022-03-29 22:11:50 +08:00
|
|
|
|
2022-11-24 23:00:51 +08:00
|
|
|
uint64_t getCurrentGpuAddressPosition() const;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void overrideMaxSize(size_t newMaxSize);
|
|
|
|
void replaceBuffer(void *buffer, size_t bufferSize);
|
|
|
|
GraphicsAllocation *getGraphicsAllocation() const;
|
|
|
|
void replaceGraphicsAllocation(GraphicsAllocation *gfxAllocation);
|
|
|
|
|
|
|
|
template <typename Cmd>
|
|
|
|
Cmd *getSpaceForCmd() {
|
|
|
|
auto ptr = getSpace(sizeof(Cmd));
|
|
|
|
return reinterpret_cast<Cmd *>(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2022-10-01 00:10:13 +08:00
|
|
|
size_t sizeUsed = 0;
|
2022-05-18 03:04:23 +08:00
|
|
|
size_t maxAvailableSpace{0};
|
|
|
|
void *buffer{nullptr};
|
|
|
|
GraphicsAllocation *graphicsAllocation{nullptr};
|
|
|
|
CommandContainer *cmdContainer{nullptr};
|
|
|
|
size_t batchBufferEndSize{0};
|
|
|
|
uint64_t gpuBase{0};
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2018-03-05 18:03:38 +08:00
|
|
|
inline void *LinearStream::getCpuBase() const {
|
2017-12-21 07:45:38 +08:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2022-03-29 22:11:50 +08:00
|
|
|
inline void LinearStream::setGpuBase(uint64_t gpuAddress) {
|
|
|
|
gpuBase = gpuAddress;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
inline void *LinearStream::getSpace(size_t size) {
|
2022-09-30 23:18:49 +08:00
|
|
|
if (size == 0u) {
|
|
|
|
return ptrOffset(buffer, sizeUsed);
|
|
|
|
}
|
|
|
|
|
2022-01-13 00:57:42 +08:00
|
|
|
if (cmdContainer != nullptr && getAvailableSpace() < batchBufferEndSize + size) {
|
|
|
|
UNRECOVERABLE_IF(sizeUsed + batchBufferEndSize > maxAvailableSpace);
|
|
|
|
cmdContainer->closeAndAllocateNextCommandBuffer();
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
UNRECOVERABLE_IF(sizeUsed + size > maxAvailableSpace);
|
2022-07-26 00:37:34 +08:00
|
|
|
UNRECOVERABLE_IF(reinterpret_cast<int64_t>(buffer) == 0);
|
2018-04-25 14:52:57 +08:00
|
|
|
auto memory = ptrOffset(buffer, sizeUsed);
|
|
|
|
sizeUsed += size;
|
|
|
|
return memory;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t LinearStream::getMaxAvailableSpace() const {
|
|
|
|
return maxAvailableSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t LinearStream::getAvailableSpace() const {
|
|
|
|
DEBUG_BREAK_IF(sizeUsed > maxAvailableSpace);
|
|
|
|
return maxAvailableSpace - sizeUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t LinearStream::getUsed() const {
|
|
|
|
return sizeUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void LinearStream::overrideMaxSize(size_t newMaxSize) {
|
|
|
|
maxAvailableSpace = newMaxSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void LinearStream::replaceBuffer(void *buffer, size_t bufferSize) {
|
|
|
|
this->buffer = buffer;
|
|
|
|
maxAvailableSpace = bufferSize;
|
|
|
|
sizeUsed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline GraphicsAllocation *LinearStream::getGraphicsAllocation() const {
|
|
|
|
return graphicsAllocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void LinearStream::replaceGraphicsAllocation(GraphicsAllocation *gfxAllocation) {
|
|
|
|
graphicsAllocation = gfxAllocation;
|
|
|
|
}
|
2022-11-24 23:00:51 +08:00
|
|
|
|
|
|
|
inline uint64_t LinearStream::getCurrentGpuAddressPosition() const {
|
|
|
|
return (getGpuBase() + getUsed());
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|