Skip to content

Commit 9a11336

Browse files
Pass VA while constructing BlitProperties instead of allocation + offset
Change-Id: Id6f88ff5252cab650ecf103e1e465bf454e6ba4c Signed-off-by: Dunajski, Bartosz <[email protected]>
1 parent fb8df1a commit 9a11336

File tree

6 files changed

+157
-68
lines changed

6 files changed

+157
-68
lines changed

runtime/helpers/blit_commands_helper.cpp

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,51 @@
1717
namespace NEO {
1818
BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection,
1919
CommandStreamReceiver &commandStreamReceiver,
20-
GraphicsAllocation *memObjAllocation, size_t memObjOffset,
21-
GraphicsAllocation *mapAllocation,
22-
void *hostPtr, size_t hostPtrOffset,
20+
GraphicsAllocation *memObjAllocation,
21+
GraphicsAllocation *preallocatedHostAllocation,
22+
void *hostPtr, uint64_t memObjGpuVa,
23+
uint64_t hostAllocGpuVa, size_t hostPtrOffset,
2324
size_t copyOffset, uint64_t copySize) {
2425

2526
GraphicsAllocation *hostAllocation = nullptr;
2627

27-
if (mapAllocation) {
28-
hostAllocation = mapAllocation;
29-
if (hostPtr) {
30-
hostPtrOffset += ptrDiff(hostPtr, mapAllocation->getGpuAddress());
31-
}
28+
if (preallocatedHostAllocation) {
29+
hostAllocation = preallocatedHostAllocation;
30+
UNRECOVERABLE_IF(hostAllocGpuVa == 0);
3231
} else {
3332
HostPtrSurface hostPtrSurface(hostPtr, static_cast<size_t>(copySize), true);
3433
bool success = commandStreamReceiver.createAllocationForHostSurface(hostPtrSurface, false);
3534
UNRECOVERABLE_IF(!success);
3635
hostAllocation = hostPtrSurface.getAllocation();
36+
hostAllocGpuVa = hostAllocation->getGpuAddress();
3737
}
3838

39-
auto offset = copyOffset + memObjOffset;
4039
if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) {
41-
return {nullptr, blitDirection, {}, AuxTranslationDirection::None, memObjAllocation, hostAllocation, offset, hostPtrOffset, copySize};
40+
return {
41+
nullptr, // outputTimestampPacket
42+
blitDirection, // blitDirection
43+
{}, // csrDependencies
44+
AuxTranslationDirection::None, // auxTranslationDirection
45+
memObjAllocation, // dstAllocation
46+
hostAllocation, // srcAllocation
47+
memObjGpuVa, // dstGpuAddress
48+
hostAllocGpuVa, // srcGpuAddress
49+
copySize, // copySize
50+
copyOffset, // dstOffset
51+
hostPtrOffset}; // srcOffset
4252
} else {
43-
return {nullptr, blitDirection, {}, AuxTranslationDirection::None, hostAllocation, memObjAllocation, hostPtrOffset, offset, copySize};
53+
return {
54+
nullptr, // outputTimestampPacket
55+
blitDirection, // blitDirection
56+
{}, // csrDependencies
57+
AuxTranslationDirection::None, // auxTranslationDirection
58+
hostAllocation, // dstAllocation
59+
memObjAllocation, // srcAllocation
60+
hostAllocGpuVa, // dstGpuAddress
61+
memObjGpuVa, // srcGpuAddress
62+
copySize, // copySize
63+
hostPtrOffset, // dstOffset
64+
copyOffset}; // srcOffset
4465
}
4566
}
4667

@@ -59,61 +80,94 @@ BlitProperties BlitProperties::constructProperties(BlitterConstants::BlitDirecti
5980

6081
GraphicsAllocation *gpuAllocation = nullptr;
6182
size_t copyOffset = 0;
62-
size_t memObjOffset = 0;
6383

6484
void *hostPtr = nullptr;
6585
size_t hostPtrOffset = 0;
6686

87+
uint64_t memObjGpuVa = 0;
88+
uint64_t hostAllocGpuVa = 0;
89+
6790
GraphicsAllocation *hostAllocation = builtinOpParams.transferAllocation;
6891

6992
if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) {
7093
// write buffer
94+
hostPtr = builtinOpParams.srcPtr;
95+
hostPtrOffset = builtinOpParams.srcOffset.x;
96+
copyOffset = builtinOpParams.dstOffset.x;
97+
98+
memObjGpuVa = castToUint64(builtinOpParams.dstPtr);
99+
hostAllocGpuVa = castToUint64(builtinOpParams.srcPtr);
100+
71101
if (builtinOpParams.dstSvmAlloc) {
72102
gpuAllocation = builtinOpParams.dstSvmAlloc;
73103
hostAllocation = builtinOpParams.srcSvmAlloc;
74104
} else {
75105
gpuAllocation = builtinOpParams.dstMemObj->getGraphicsAllocation();
76-
memObjOffset = builtinOpParams.dstMemObj->getOffset();
77-
hostPtr = builtinOpParams.srcPtr;
106+
memObjGpuVa = (gpuAllocation->getGpuAddress() + builtinOpParams.dstMemObj->getOffset());
78107
}
79-
80-
hostPtrOffset = builtinOpParams.srcOffset.x;
81-
copyOffset = builtinOpParams.dstOffset.x;
82108
}
83109

84110
if (BlitterConstants::BlitDirection::BufferToHostPtr == blitDirection) {
85111
// read buffer
112+
hostPtr = builtinOpParams.dstPtr;
113+
114+
hostPtrOffset = builtinOpParams.dstOffset.x;
115+
copyOffset = builtinOpParams.srcOffset.x;
116+
117+
memObjGpuVa = castToUint64(builtinOpParams.srcPtr);
118+
hostAllocGpuVa = castToUint64(builtinOpParams.dstPtr);
119+
86120
if (builtinOpParams.srcSvmAlloc) {
87121
gpuAllocation = builtinOpParams.srcSvmAlloc;
88122
hostAllocation = builtinOpParams.dstSvmAlloc;
89123
} else {
90124
gpuAllocation = builtinOpParams.srcMemObj->getGraphicsAllocation();
91-
memObjOffset = builtinOpParams.srcMemObj->getOffset();
92-
hostPtr = builtinOpParams.dstPtr;
125+
memObjGpuVa = (gpuAllocation->getGpuAddress() + builtinOpParams.srcMemObj->getOffset());
93126
}
94-
95-
hostPtrOffset = builtinOpParams.dstOffset.x;
96-
copyOffset = builtinOpParams.srcOffset.x;
97127
}
98128

99129
UNRECOVERABLE_IF(BlitterConstants::BlitDirection::HostPtrToBuffer != blitDirection &&
100130
BlitterConstants::BlitDirection::BufferToHostPtr != blitDirection);
101131

102-
return constructPropertiesForReadWriteBuffer(blitDirection, commandStreamReceiver, gpuAllocation, memObjOffset,
103-
hostAllocation, hostPtr, hostPtrOffset, copyOffset,
104-
builtinOpParams.size.x);
132+
return constructPropertiesForReadWriteBuffer(blitDirection, commandStreamReceiver, gpuAllocation,
133+
hostAllocation, hostPtr, memObjGpuVa, hostAllocGpuVa,
134+
hostPtrOffset, copyOffset, builtinOpParams.size.x);
105135
}
106136

107137
BlitProperties BlitProperties::constructPropertiesForCopyBuffer(GraphicsAllocation *dstAllocation, GraphicsAllocation *srcAllocation,
108138
size_t dstOffset, size_t srcOffset, uint64_t copySize) {
109139

110-
return {nullptr, BlitterConstants::BlitDirection::BufferToBuffer, {}, AuxTranslationDirection::None, dstAllocation, srcAllocation, dstOffset, srcOffset, copySize};
140+
return {
141+
nullptr, // outputTimestampPacket
142+
BlitterConstants::BlitDirection::BufferToBuffer, // blitDirection
143+
{}, // csrDependencies
144+
AuxTranslationDirection::None, // auxTranslationDirection
145+
dstAllocation, // dstAllocation
146+
srcAllocation, // srcAllocation
147+
dstAllocation->getGpuAddress(), // dstGpuAddress
148+
srcAllocation->getGpuAddress(), // srcGpuAddress
149+
copySize, // copySize
150+
dstOffset, // dstOffset
151+
srcOffset}; // srcOffset
111152
}
112153

113154
BlitProperties BlitProperties::constructPropertiesForAuxTranslation(AuxTranslationDirection auxTranslationDirection,
114155
GraphicsAllocation *allocation) {
156+
115157
auto allocationSize = allocation->getUnderlyingBufferSize();
116-
return {nullptr, BlitterConstants::BlitDirection::BufferToBuffer, {}, auxTranslationDirection, allocation, allocation, 0, 0, allocationSize};
158+
return {
159+
nullptr, // outputTimestampPacket
160+
BlitterConstants::BlitDirection::BufferToBuffer, // blitDirection
161+
{}, // csrDependencies
162+
auxTranslationDirection, // auxTranslationDirection
163+
allocation, // dstAllocation
164+
allocation, // srcAllocation
165+
allocation->getGpuAddress(), // dstGpuAddress
166+
allocation->getGpuAddress(), // srcGpuAddress
167+
allocationSize, // copySize
168+
0, // dstOffset
169+
0 // srcOffset
170+
};
117171
}
118172

119173
BlitterConstants::BlitDirection BlitProperties::obtainBlitDirection(uint32_t commandType) {

runtime/helpers/blit_commands_helper.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ using BlitPropertiesContainer = StackVec<BlitProperties, 16>;
3131
struct BlitProperties {
3232
static BlitProperties constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection,
3333
CommandStreamReceiver &commandStreamReceiver,
34-
GraphicsAllocation *memObjAllocation, size_t memObjOFfset,
35-
GraphicsAllocation *mapAllocation,
36-
void *hostPtr, size_t hostPtrOffset,
34+
GraphicsAllocation *memObjAllocation,
35+
GraphicsAllocation *preallocatedHostAllocation,
36+
void *hostPtr, uint64_t memObjGpuVa,
37+
uint64_t hostAllocGpuVa, size_t hostPtrOffset,
3738
size_t copyOffset, uint64_t copySize);
3839

3940
static BlitProperties constructProperties(BlitterConstants::BlitDirection blitDirection,
@@ -59,9 +60,11 @@ struct BlitProperties {
5960

6061
GraphicsAllocation *dstAllocation = nullptr;
6162
GraphicsAllocation *srcAllocation = nullptr;
63+
uint64_t dstGpuAddress = 0;
64+
uint64_t srcGpuAddress = 0;
65+
uint64_t copySize = 0;
6266
size_t dstOffset = 0;
6367
size_t srcOffset = 0;
64-
uint64_t copySize = 0;
6568
};
6669

6770
template <typename GfxFamily>

runtime/helpers/blit_commands_helper_base.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void BlitCommandsHelper<GfxFamily>::dispatchBlitCommandsForBuffer(const BlitProp
7474
bltCmd->setDestinationPitch(static_cast<uint32_t>(width));
7575
bltCmd->setSourcePitch(static_cast<uint32_t>(width));
7676

77-
bltCmd->setDestinationBaseAddress(blitProperties.dstAllocation->getGpuAddress() + blitProperties.dstOffset + offset);
78-
bltCmd->setSourceBaseAddress(blitProperties.srcAllocation->getGpuAddress() + blitProperties.srcOffset + offset);
77+
bltCmd->setDestinationBaseAddress(blitProperties.dstGpuAddress + blitProperties.dstOffset + offset);
78+
bltCmd->setSourceBaseAddress(blitProperties.srcGpuAddress + blitProperties.srcOffset + offset);
7979

8080
appendBlitCommandsForBuffer(blitProperties, *bltCmd);
8181

unit_tests/command_queue/blit_enqueue_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ struct BlitAuxTranslationTests : public ::testing::Test {
3232
}
3333
BlitOperationResult blitMemoryToAllocation(MemObj &memObj, GraphicsAllocation *memory, void *hostPtr, size_t size) const override {
3434
auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer,
35-
*bcsCsr, memory, 0, nullptr,
36-
hostPtr, 0, 0, size);
35+
*bcsCsr, memory, nullptr,
36+
hostPtr,
37+
memory->getGpuAddress(), 0,
38+
0, 0, size);
3739

3840
BlitPropertiesContainer container;
3941
container.push_back(blitProperties);

0 commit comments

Comments
 (0)