Skip to content

Commit d6eaab1

Browse files
Correct blitter command size estimation
Signed-off-by: Kamil Kopryk <[email protected]>
1 parent 91cf506 commit d6eaab1

File tree

5 files changed

+89
-46
lines changed

5 files changed

+89
-46
lines changed

opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,10 @@ HWTEST_F(BcsTests, givenTimestampPacketWriteRequestWhenEstimatingSizeForCommands
868868
auto expectedSizeWithTimestampPacketWrite = expectedBaseSize + EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite();
869869
auto expectedSizeWithoutTimestampPacketWrite = expectedBaseSize;
870870

871-
auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
872-
{1, 1, 1}, csrDependencies, true, false, pClDevice->getRootDeviceEnvironment());
873-
auto estimatedSizeWithoutTimestampPacketWrite = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
874-
{1, 1, 1}, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment());
871+
auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
872+
{1, 1, 1}, csrDependencies, true, false, false, pClDevice->getRootDeviceEnvironment());
873+
auto estimatedSizeWithoutTimestampPacketWrite = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
874+
{1, 1, 1}, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment());
875875

876876
EXPECT_EQ(expectedSizeWithTimestampPacketWrite, estimatedSizeWithTimestampPacketWrite);
877877
EXPECT_EQ(expectedSizeWithoutTimestampPacketWrite, estimatedSizeWithoutTimestampPacketWrite);
@@ -891,10 +891,10 @@ HWTEST_F(BcsTests, givenTimestampPacketWriteRequestWhenEstimatingSizeForCommands
891891

892892
auto expectedSizeWithTimestampPacketWriteAndProfiling = expectedBaseSize + BlitCommandsHelper<FamilyType>::getProfilingMmioCmdsSize();
893893

894-
auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
895-
{1, 1, 1}, csrDependencies, true, false, pClDevice->getRootDeviceEnvironment());
896-
auto estimatedSizeWithTimestampPacketWriteAndProfiling = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
897-
{1, 1, 1}, csrDependencies, true, true, pClDevice->getRootDeviceEnvironment());
894+
auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
895+
{1, 1, 1}, csrDependencies, true, false, false, pClDevice->getRootDeviceEnvironment());
896+
auto estimatedSizeWithTimestampPacketWriteAndProfiling = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
897+
{1, 1, 1}, csrDependencies, true, true, false, pClDevice->getRootDeviceEnvironment());
898898

899899
EXPECT_EQ(expectedSizeWithTimestampPacketWriteAndProfiling, estimatedSizeWithTimestampPacketWriteAndProfiling);
900900
EXPECT_EQ(expectedBaseSize, estimatedSizeWithTimestampPacketWrite);
@@ -923,12 +923,48 @@ HWTEST_F(BcsTests, givenBltSizeAndCsrDependenciesWhenEstimatingCommandSizeThenAd
923923
expectedSize += EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite();
924924
}
925925

926-
auto estimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
927-
{1, 1, 1}, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment());
926+
auto estimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
927+
{1, 1, 1}, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment());
928928

929929
EXPECT_EQ(expectedSize, estimatedSize);
930930
}
931931

932+
HWTEST_F(BcsTests, givenImageAndBufferWhenEstimateBlitCommandSizeThenReturnCorrectCommandSize) {
933+
934+
for (auto isImage : {false, true}) {
935+
auto expectedSize = sizeof(typename FamilyType::MI_ARB_CHECK);
936+
expectedSize += isImage ? sizeof(typename FamilyType::XY_BLOCK_COPY_BLT) : sizeof(typename FamilyType::XY_COPY_BLT);
937+
938+
if (BlitCommandsHelper<FamilyType>::miArbCheckWaRequired()) {
939+
expectedSize += EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite();
940+
}
941+
if (BlitCommandsHelper<FamilyType>::preBlitCommandWARequired()) {
942+
expectedSize += EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite();
943+
}
944+
945+
auto estimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
946+
{1, 1, 1}, csrDependencies, false, false, isImage, pClDevice->getRootDeviceEnvironment());
947+
948+
EXPECT_EQ(expectedSize, estimatedSize);
949+
}
950+
}
951+
952+
HWTEST_F(BcsTests, givenImageAndBufferBlitDirectionsWhenIsImageOperationIsCalledThenReturnCorrectValue) {
953+
954+
BlitProperties blitProperties{};
955+
std::pair<bool, BlitterConstants::BlitDirection> params[] = {{false, BlitterConstants::BlitDirection::HostPtrToBuffer},
956+
{false, BlitterConstants::BlitDirection::BufferToHostPtr},
957+
{false, BlitterConstants::BlitDirection::BufferToBuffer},
958+
{true, BlitterConstants::BlitDirection::HostPtrToImage},
959+
{true, BlitterConstants::BlitDirection::ImageToHostPtr},
960+
{true, BlitterConstants::BlitDirection::ImageToImage}};
961+
962+
for (auto [isImageDirection, blitDirection] : params) {
963+
blitProperties.blitDirection = blitDirection;
964+
EXPECT_EQ(isImageDirection, blitProperties.isImageOperation());
965+
}
966+
}
967+
932968
HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredCommands) {
933969
using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW;
934970
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;

opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ HWTEST_F(BcsTests, givenBltSizeWhenEstimatingCommandSizeThenAddAllRequiredComman
5555
auto alignedCopySize = Vec3<size_t>{alignedBltSize, 1, 1};
5656
auto notAlignedCopySize = Vec3<size_t>{notAlignedBltSize, 1, 1};
5757

58-
auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
59-
alignedCopySize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment());
60-
auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
61-
notAlignedCopySize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment());
58+
auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
59+
alignedCopySize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment());
60+
auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
61+
notAlignedCopySize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment());
6262

6363
EXPECT_EQ(expectedAlignedSize, alignedEstimatedSize);
6464
EXPECT_EQ(expectedNotAlignedSize, notAlignedEstimatedSize);
@@ -116,10 +116,10 @@ HWTEST_F(BcsTests, givenBltSizeWhenEstimatingCommandSizeForReadBufferRectThenAdd
116116
expectedNotAlignedSize += EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite();
117117
}
118118

119-
auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
120-
alignedBltSize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment());
121-
auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
122-
notAlignedBltSize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment());
119+
auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
120+
alignedBltSize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment());
121+
auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
122+
notAlignedBltSize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment());
123123

124124
EXPECT_EQ(expectedAlignedSize, alignedEstimatedSize);
125125
EXPECT_EQ(expectedNotAlignedSize, notAlignedEstimatedSize);
@@ -154,10 +154,10 @@ HWTEST_F(BcsTests, givenBltWithBigCopySizeWhenEstimatingCommandSizeForReadBuffer
154154
expectedNotAlignedSize += EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite();
155155
}
156156

157-
auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
158-
alignedBltSize, csrDependencies, false, false, rootDeviceEnvironment);
159-
auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize(
160-
notAlignedBltSize, csrDependencies, false, false, rootDeviceEnvironment);
157+
auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
158+
alignedBltSize, csrDependencies, false, false, false, rootDeviceEnvironment);
159+
auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandSize(
160+
notAlignedBltSize, csrDependencies, false, false, false, rootDeviceEnvironment);
161161

162162
EXPECT_EQ(expectedAlignedSize, alignedEstimatedSize);
163163
EXPECT_EQ(expectedNotAlignedSize, notAlignedEstimatedSize);

shared/source/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,9 @@ uint32_t CommandStreamReceiverHw<GfxFamily>::flushBcsTask(const BlitPropertiesCo
10141014

10151015
auto lock = obtainUniqueOwnership();
10161016
bool blitterDirectSubmission = this->isBlitterDirectSubmissionEnabled();
1017-
auto &commandStream = getCS(BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(blitPropertiesContainer, profilingEnabled, PauseOnGpuProperties::featureEnabled(DebugManager.flags.PauseOnBlitCopy.get()),
1018-
blitterDirectSubmission, *this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]));
1017+
auto debugPauseEnabled = PauseOnGpuProperties::featureEnabled(DebugManager.flags.PauseOnBlitCopy.get());
1018+
auto &commandStream = getCS(BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(blitPropertiesContainer, profilingEnabled, debugPauseEnabled, blitterDirectSubmission,
1019+
*this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]));
10191020
auto commandStreamStart = commandStream.getUsed();
10201021
auto newTaskCount = taskCount + 1;
10211022
latestSentTaskCount = newTaskCount;

shared/source/helpers/blit_commands_helper.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct BlitProperties {
6262
CommandStreamReceiver &gpguCsr, CommandStreamReceiver &bcsCsr);
6363

6464
TagNodeBase *outputTimestampPacket = nullptr;
65-
BlitterConstants::BlitDirection blitDirection;
65+
BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::BufferToHostPtr;
6666
CsrDependencies csrDependencies;
6767
AuxTranslationDirection auxTranslationDirection = AuxTranslationDirection::None;
6868

@@ -83,6 +83,12 @@ struct BlitProperties {
8383
Vec3<size_t> dstSize = 0;
8484
Vec3<size_t> srcSize = 0;
8585
size_t bytesPerPixel = 1;
86+
87+
bool isImageOperation() const {
88+
return blitDirection == BlitterConstants::BlitDirection::HostPtrToImage ||
89+
blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr ||
90+
blitDirection == BlitterConstants::BlitDirection::ImageToImage;
91+
}
8692
};
8793

8894
enum class BlitOperationResult {
@@ -118,8 +124,8 @@ struct BlitCommandsHelper {
118124
static size_t estimatePreBlitCommandSize();
119125
static void dispatchPostBlitCommand(LinearStream &linearStream, const HardwareInfo &hwInfo);
120126
static size_t estimatePostBlitCommandSize();
121-
static size_t estimateBlitCommandsSize(const Vec3<size_t> &copySize, const CsrDependencies &csrDependencies, bool updateTimestampPacket,
122-
bool profilingEnabled, const RootDeviceEnvironment &rootDeviceEnvironment);
127+
static size_t estimateBlitCommandSize(const Vec3<size_t> &copySize, const CsrDependencies &csrDependencies, bool updateTimestampPacket,
128+
bool profilingEnabled, bool isImage, const RootDeviceEnvironment &rootDeviceEnvironment);
123129
static size_t estimateBlitCommandsSize(const BlitPropertiesContainer &blitPropertiesContainer, bool profilingEnabled,
124130
bool debugPauseEnabled, bool blitterDirectSubmission, const RootDeviceEnvironment &rootDeviceEnvironment);
125131
static size_t getNumberOfBlitsForCopyRegion(const Vec3<size_t> &copySize, const RootDeviceEnvironment &rootDeviceEnvironment);

shared/source/helpers/blit_commands_helper_base.inl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ size_t BlitCommandsHelper<GfxFamily>::estimatePostBlitCommandSize() {
101101
}
102102

103103
template <typename GfxFamily>
104-
size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(const Vec3<size_t> &copySize, const CsrDependencies &csrDependencies,
105-
bool updateTimestampPacket, bool profilingEnabled,
106-
const RootDeviceEnvironment &rootDeviceEnvironment) {
104+
size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandSize(const Vec3<size_t> &copySize, const CsrDependencies &csrDependencies,
105+
bool updateTimestampPacket, bool profilingEnabled, bool isImage, const RootDeviceEnvironment &rootDeviceEnvironment) {
107106
size_t timestampCmdSize = 0;
108107
if (updateTimestampPacket) {
109108
timestampCmdSize += EncodeMiFlushDW<GfxFamily>::getMiFlushDwCmdSizeForDataWrite();
@@ -112,12 +111,19 @@ size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(const Vec3<size_t
112111
}
113112
}
114113

115-
bool preferRegionCopy = isCopyRegionPreferred(copySize, rootDeviceEnvironment);
116-
auto nBlits = preferRegionCopy ? getNumberOfBlitsForCopyRegion(copySize, rootDeviceEnvironment)
117-
: getNumberOfBlitsForCopyPerRow(copySize, rootDeviceEnvironment);
114+
size_t nBlits = 0u;
115+
size_t sizePerBlit = 0u;
118116

119-
auto sizePerBlit = (sizeof(typename GfxFamily::XY_COPY_BLT) + estimatePostBlitCommandSize());
117+
if (isImage) {
118+
nBlits = getNumberOfBlitsForCopyRegion(copySize, rootDeviceEnvironment);
119+
sizePerBlit = sizeof(typename GfxFamily::XY_BLOCK_COPY_BLT);
120+
} else {
121+
nBlits = std::min(getNumberOfBlitsForCopyRegion(copySize, rootDeviceEnvironment),
122+
getNumberOfBlitsForCopyPerRow(copySize, rootDeviceEnvironment));
123+
sizePerBlit = sizeof(typename GfxFamily::XY_COPY_BLT);
124+
}
120125

126+
sizePerBlit += estimatePostBlitCommandSize();
121127
return TimestampPacketHelper::getRequiredCmdStreamSize<GfxFamily>(csrDependencies) +
122128
TimestampPacketHelper::getRequiredCmdStreamSizeForTaskCountContainer<GfxFamily>(csrDependencies) +
123129
(sizePerBlit * nBlits) +
@@ -131,17 +137,14 @@ size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(const BlitPropert
131137
bool blitterDirectSubmission, const RootDeviceEnvironment &rootDeviceEnvironment) {
132138
size_t size = 0;
133139
for (auto &blitProperties : blitPropertiesContainer) {
134-
size += BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(blitProperties.copySize, blitProperties.csrDependencies,
135-
blitProperties.outputTimestampPacket != nullptr, profilingEnabled,
136-
rootDeviceEnvironment);
140+
auto updateTimestampPacket = blitProperties.outputTimestampPacket != nullptr;
141+
auto isImage = blitProperties.isImageOperation();
142+
size += BlitCommandsHelper<GfxFamily>::estimateBlitCommandSize(blitProperties.copySize, blitProperties.csrDependencies, updateTimestampPacket,
143+
profilingEnabled, isImage, rootDeviceEnvironment);
137144
}
138145
size += MemorySynchronizationCommands<GfxFamily>::getSizeForAdditonalSynchronization(*rootDeviceEnvironment.getHardwareInfo());
139146
size += EncodeMiFlushDW<GfxFamily>::getMiFlushDwCmdSizeForDataWrite();
140-
if (blitterDirectSubmission) {
141-
size += sizeof(typename GfxFamily::MI_BATCH_BUFFER_START);
142-
} else {
143-
size += sizeof(typename GfxFamily::MI_BATCH_BUFFER_END);
144-
}
147+
size += blitterDirectSubmission ? sizeof(typename GfxFamily::MI_BATCH_BUFFER_START) : sizeof(typename GfxFamily::MI_BATCH_BUFFER_END);
145148

146149
if (debugPauseEnabled) {
147150
size += BlitCommandsHelper<GfxFamily>::getSizeForDebugPauseCommands();
@@ -337,10 +340,7 @@ uint32_t BlitCommandsHelper<GfxFamily>::getAvailableBytesPerPixel(size_t copySiz
337340

338341
template <typename GfxFamily>
339342
void BlitCommandsHelper<GfxFamily>::dispatchBlitCommands(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) {
340-
341-
if (blitProperties.blitDirection == BlitterConstants::BlitDirection::HostPtrToImage ||
342-
blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr ||
343-
blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToImage) {
343+
if (blitProperties.isImageOperation()) {
344344
dispatchBlitCommandsForImageRegion(blitProperties, linearStream, rootDeviceEnvironment);
345345
} else {
346346
bool preferCopyBufferRegion = isCopyRegionPreferred(blitProperties.copySize, rootDeviceEnvironment);

0 commit comments

Comments
 (0)