Add concept of chunks into timestamp packets.

Change-Id: Ic9a978224862e237a7268525f05b059756da06e7
This commit is contained in:
Mrozek, Michal 2018-11-21 14:05:01 +01:00 committed by sys_ocldev
parent 7488d7971e
commit e2c9a25d03
2 changed files with 25 additions and 10 deletions

View File

@ -22,9 +22,17 @@ class MemoryManager;
template <typename TagType>
struct TagNode;
namespace TimestampPacketSizeControl {
constexpr uint32_t preferedChunkCount = 16u;
}
#pragma pack(1)
class TimestampPacket {
public:
TimestampPacket() {
initialize();
}
enum class DataIndex : uint32_t {
ContextStart = 0,
GlobalStart,
@ -50,7 +58,9 @@ class TimestampPacket {
}
void initialize() {
data = {{1, 1, 1, 1}};
for (auto index = 0u; index < data.size(); index++) {
data[index] = 1;
}
implicitDependenciesCount.store(0);
}
@ -58,12 +68,12 @@ class TimestampPacket {
uint64_t pickImplicitDependenciesCountWriteAddress() const { return reinterpret_cast<uint64_t>(&implicitDependenciesCount); }
protected:
std::array<uint32_t, static_cast<uint32_t>(DataIndex::Max)> data = {{1, 1, 1, 1}};
std::atomic<uint32_t> implicitDependenciesCount{0};
std::array<uint32_t, static_cast<uint32_t>(DataIndex::Max) * TimestampPacketSizeControl::preferedChunkCount> data;
std::atomic<uint32_t> implicitDependenciesCount;
};
#pragma pack()
static_assert(((static_cast<uint32_t>(TimestampPacket::DataIndex::Max) + 1) * sizeof(uint32_t)) == sizeof(TimestampPacket),
static_assert(((static_cast<uint32_t>(TimestampPacket::DataIndex::Max) * TimestampPacketSizeControl::preferedChunkCount + 1) * sizeof(uint32_t)) == sizeof(TimestampPacket),
"This structure is consumed by GPU and has to follow specific restrictions for padding and size");
struct TimestampPacketHelper {

View File

@ -163,7 +163,10 @@ TEST_F(TimestampPacketSimpleTests, whenNewTagIsTakenThenReinitialize) {
MockTagAllocator<MockTimestampPacket> allocator(&memoryManager, 1);
auto firstNode = allocator.getTag();
firstNode->tag->data = {{5, 6, 7, 8}};
for (uint32_t i = 0; i < static_cast<uint32_t>(TimestampPacket::DataIndex::Max) * TimestampPacketSizeControl::preferedChunkCount; i++) {
firstNode->tag->data[i] = i;
}
auto dependenciesCount = reinterpret_cast<std::atomic<uint32_t> *>(reinterpret_cast<void *>(firstNode->tag->pickImplicitDependenciesCountWriteAddress()));
setTagToReadyState(firstNode->tag);
@ -174,19 +177,21 @@ TEST_F(TimestampPacketSimpleTests, whenNewTagIsTakenThenReinitialize) {
EXPECT_EQ(secondNode, firstNode);
EXPECT_EQ(0u, dependenciesCount->load());
for (uint32_t i = 0; i < static_cast<uint32_t>(TimestampPacket::DataIndex::Max); i++) {
for (uint32_t i = 0; i < static_cast<uint32_t>(TimestampPacket::DataIndex::Max) * TimestampPacketSizeControl::preferedChunkCount; i++) {
EXPECT_EQ(1u, secondNode->tag->data[i]);
}
}
TEST_F(TimestampPacketSimpleTests, whenObjectIsCreatedThenInitializeAllStamps) {
MockTimestampPacket timestampPacket;
auto maxElements = static_cast<uint32_t>(TimestampPacket::DataIndex::Max);
EXPECT_EQ(4u, maxElements);
auto entityElements = static_cast<uint32_t>(TimestampPacket::DataIndex::Max);
auto allElements = entityElements * TimestampPacketSizeControl::preferedChunkCount;
EXPECT_EQ(4u, entityElements);
EXPECT_EQ(64u, allElements);
EXPECT_EQ(maxElements, timestampPacket.data.size());
EXPECT_EQ(allElements, timestampPacket.data.size());
for (uint32_t i = 0; i < maxElements; i++) {
for (uint32_t i = 0; i < allElements; i++) {
EXPECT_EQ(1u, timestampPacket.data[i]);
}
}