Skip to content

Commit 2b177ca

Browse files
Correct programming width of media block surface
Programmed value should be a number of all dwords, rounded up Related-To: NEO-6466 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 4ddcda6 commit 2b177ca

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

level_zero/core/source/image/image_hw.inl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -204,8 +204,7 @@ void ImageCoreFamily<gfxCoreFamily>::copySurfaceStateToSSH(void *surfaceStateHea
204204
&surfaceState, sizeof(RENDER_SURFACE_STATE));
205205
if (isMediaBlockArg) {
206206
RENDER_SURFACE_STATE *dstRss = static_cast<RENDER_SURFACE_STATE *>(destSurfaceState);
207-
uint32_t elSize = static_cast<uint32_t>(imgInfo.surfaceFormat->ImageElementSizeInBytes);
208-
dstRss->setWidth(static_cast<uint32_t>((imgInfo.imgDesc.imageWidth * elSize) / sizeof(uint32_t)));
207+
NEO::setWidthForMediaBlockSurfaceState<GfxFamily>(dstRss, imgInfo);
209208
}
210209
}
211210

opencl/source/mem_obj/image.inl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -61,8 +61,7 @@ void ImageHw<GfxFamily>::setImageArg(void *memory, bool setAsMediaBlockImage, ui
6161
} else {
6262
setImageSurfaceStateDimensions<GfxFamily>(surfaceState, imgInfo, cubeFaceIndex, surfaceType);
6363
if (setAsMediaBlockImage) {
64-
uint32_t elSize = static_cast<uint32_t>(getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes);
65-
surfaceState->setWidth(static_cast<uint32_t>((getImageDesc().image_width * elSize) / sizeof(uint32_t)));
64+
setWidthForMediaBlockSurfaceState<GfxFamily>(surfaceState, imgInfo);
6665
}
6766
}
6867

shared/source/image/image_surface_state.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ inline void setImageSurfaceStateDimensions(typename GfxFamily::RENDER_SURFACE_ST
124124
surfaceState->setSurfaceType(surfaceType);
125125
}
126126

127+
template <typename GfxFamily>
128+
inline void setWidthForMediaBlockSurfaceState(typename GfxFamily::RENDER_SURFACE_STATE *surfaceState, const ImageInfo &imageInfo) {
129+
auto elSize = imageInfo.surfaceFormat->ImageElementSizeInBytes;
130+
auto numDwords = static_cast<uint32_t>(Math::divideAndRoundUp(imageInfo.imgDesc.imageWidth * elSize, sizeof(uint32_t)));
131+
surfaceState->setWidth(numDwords);
132+
}
133+
127134
template <typename GfxFamily>
128135
inline void setUnifiedAuxBaseAddress(typename GfxFamily::RENDER_SURFACE_STATE *surfaceState, const Gmm *gmm) {
129136
uint64_t baseAddress = surfaceState->getSurfaceBaseAddress() +

shared/test/unit_test/image/image_surface_state_tests.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,63 @@ HWTEST_F(ImageSurfaceStateTests, givenImage1DWhen2dImageWAIsEnabledThenArrayFlag
222222
setImageSurfaceState<FamilyType>(castSurfaceState, imageInfo, mockGmm.get(), *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, true);
223223
EXPECT_FALSE(castSurfaceState->getSurfaceArray());
224224
}
225+
226+
struct ImageWidthTest : ImageSurfaceStateTests {
227+
228+
struct ImageWidthParams {
229+
uint32_t imageWidth;
230+
uint32_t expectedWidthInDwords;
231+
};
232+
233+
template <typename FamilyType>
234+
void verifyProgramming(typename FamilyType::RENDER_SURFACE_STATE &renderSurfaceState, const std::array<ImageWidthParams, 6> &params) {
235+
for (auto &param : params) {
236+
imageInfo.imgDesc.imageWidth = param.imageWidth;
237+
setWidthForMediaBlockSurfaceState<FamilyType>(&renderSurfaceState, imageInfo);
238+
EXPECT_EQ(param.expectedWidthInDwords, renderSurfaceState.getWidth());
239+
}
240+
}
241+
};
242+
243+
HWTEST_F(ImageWidthTest, givenMediaBlockWhenProgrammingWidthInSurfaceStateThenCorrectValueIsProgrammed) {
244+
SurfaceFormatInfo surfaceFormatInfo{};
245+
imageInfo.surfaceFormat = &surfaceFormatInfo;
246+
247+
auto renderSurfaceState = FamilyType::cmdInitRenderSurfaceState;
248+
{
249+
surfaceFormatInfo.ImageElementSizeInBytes = 1u;
250+
constexpr std::array<ImageWidthParams, 6> params = {{
251+
{1, 1},
252+
{2, 1},
253+
{3, 1},
254+
{4, 1},
255+
{5, 2},
256+
{6, 2},
257+
}};
258+
verifyProgramming<FamilyType>(renderSurfaceState, params);
259+
}
260+
{
261+
surfaceFormatInfo.ImageElementSizeInBytes = 2u;
262+
constexpr std::array<ImageWidthParams, 6> params = {{
263+
{1, 1},
264+
{2, 1},
265+
{3, 2},
266+
{4, 2},
267+
{5, 3},
268+
{6, 3},
269+
}};
270+
verifyProgramming<FamilyType>(renderSurfaceState, params);
271+
}
272+
{
273+
surfaceFormatInfo.ImageElementSizeInBytes = 4u;
274+
constexpr std::array<ImageWidthParams, 6> params = {{
275+
{1, 1},
276+
{2, 2},
277+
{3, 3},
278+
{4, 4},
279+
{5, 5},
280+
{6, 6},
281+
}};
282+
verifyProgramming<FamilyType>(renderSurfaceState, params);
283+
}
284+
}

0 commit comments

Comments
 (0)