mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Improve dirtyHeaps check in CommandContainer
Change-Id: I798c916ff267671650a30d06d67aa1c1162c567f Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
b49424772f
commit
9522734801
@ -95,7 +95,7 @@ void CommandContainer::addToResidencyContainer(NEO::GraphicsAllocation *alloc) {
|
||||
}
|
||||
|
||||
void CommandContainer::reset() {
|
||||
dirtyHeaps = std::numeric_limits<uint32_t>::max();
|
||||
setDirtyStateForAllHeaps(true);
|
||||
slmSize = std::numeric_limits<uint32_t>::max();
|
||||
getResidencyContainer().clear();
|
||||
getDeallocationContainer().clear();
|
||||
|
@ -59,13 +59,17 @@ class CommandContainer : public NonCopyableOrMovableClass {
|
||||
|
||||
virtual ~CommandContainer();
|
||||
|
||||
uint32_t dirtyHeaps = std::numeric_limits<uint32_t>::max();
|
||||
uint32_t slmSize = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
Device *getDevice() const { return device; }
|
||||
|
||||
void reset();
|
||||
|
||||
bool isHeapDirty(HeapType heapType) const { return (dirtyHeaps & (1u << heapType)); }
|
||||
bool isAnyHeapDirty() const { return dirtyHeaps != 0; }
|
||||
void setHeapDirty(HeapType heapType) { dirtyHeaps |= (1u << heapType); }
|
||||
void setDirtyStateForAllHeaps(bool dirty) { dirtyHeaps = dirty ? std::numeric_limits<uint32_t>::max() : 0; }
|
||||
|
||||
protected:
|
||||
Device *device = nullptr;
|
||||
std::unique_ptr<HeapHelper> heapHelper;
|
||||
@ -74,6 +78,7 @@ class CommandContainer : public NonCopyableOrMovableClass {
|
||||
GraphicsAllocation *allocationIndirectHeaps[HeapType::NUM_TYPES] = {};
|
||||
|
||||
uint64_t instructionHeapBaseAddress = 0u;
|
||||
uint32_t dirtyHeaps = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
std::unique_ptr<LinearStream> commandStream;
|
||||
std::unique_ptr<IndirectHeap> indirectHeaps[HeapType::NUM_TYPES] = {};
|
||||
|
@ -26,6 +26,60 @@ class CommandContainerTest : public DeviceFixture,
|
||||
}
|
||||
};
|
||||
|
||||
struct CommandContainerHeapStateTests : public ::testing::Test {
|
||||
class MyMockCommandContainer : public CommandContainer {
|
||||
public:
|
||||
using CommandContainer::dirtyHeaps;
|
||||
};
|
||||
|
||||
MyMockCommandContainer myCommandContainer;
|
||||
};
|
||||
|
||||
TEST_F(CommandContainerHeapStateTests, givenDirtyHeapsWhenSettingStateForAllThenValuesAreCorrect) {
|
||||
EXPECT_EQ(std::numeric_limits<uint32_t>::max(), myCommandContainer.dirtyHeaps);
|
||||
EXPECT_TRUE(myCommandContainer.isAnyHeapDirty());
|
||||
|
||||
myCommandContainer.setDirtyStateForAllHeaps(false);
|
||||
EXPECT_EQ(0u, myCommandContainer.dirtyHeaps);
|
||||
EXPECT_FALSE(myCommandContainer.isAnyHeapDirty());
|
||||
|
||||
for (uint32_t i = 0; i < HeapType::NUM_TYPES; i++) {
|
||||
HeapType heapType = static_cast<HeapType>(i);
|
||||
EXPECT_FALSE(myCommandContainer.isHeapDirty(heapType));
|
||||
}
|
||||
|
||||
myCommandContainer.setDirtyStateForAllHeaps(true);
|
||||
EXPECT_EQ(std::numeric_limits<uint32_t>::max(), myCommandContainer.dirtyHeaps);
|
||||
|
||||
for (uint32_t i = 0; i < HeapType::NUM_TYPES; i++) {
|
||||
HeapType heapType = static_cast<HeapType>(i);
|
||||
EXPECT_TRUE(myCommandContainer.isHeapDirty(heapType));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CommandContainerHeapStateTests, givenDirtyHeapsWhenSettingStateForSingleHeapThenValuesAreCorrect) {
|
||||
myCommandContainer.dirtyHeaps = 0;
|
||||
EXPECT_FALSE(myCommandContainer.isAnyHeapDirty());
|
||||
|
||||
uint32_t controlVariable = 0;
|
||||
for (uint32_t i = 0; i < HeapType::NUM_TYPES; i++) {
|
||||
HeapType heapType = static_cast<HeapType>(i);
|
||||
|
||||
EXPECT_FALSE(myCommandContainer.isHeapDirty(heapType));
|
||||
myCommandContainer.setHeapDirty(heapType);
|
||||
EXPECT_TRUE(myCommandContainer.isHeapDirty(heapType));
|
||||
EXPECT_TRUE(myCommandContainer.isAnyHeapDirty());
|
||||
|
||||
controlVariable |= (1 << i);
|
||||
EXPECT_EQ(controlVariable, myCommandContainer.dirtyHeaps);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < HeapType::NUM_TYPES; i++) {
|
||||
HeapType heapType = static_cast<HeapType>(i);
|
||||
EXPECT_TRUE(myCommandContainer.isHeapDirty(heapType));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CommandContainerTest, givenCommandContainerWhenInitializeThenEverythingIsInitialized) {
|
||||
CommandContainer cmdContainer;
|
||||
auto status = cmdContainer.initialize(pDevice);
|
||||
@ -114,4 +168,4 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenWantToAddAleradyAddedAlloc
|
||||
auto sizeAfterSecondAdd = cmdContainer.getResidencyContainer().size();
|
||||
|
||||
EXPECT_EQ(sizeAfterFirstAdd, sizeAfterSecondAdd);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user