fix: align up surface size in surface state

don't abort when surface size is not aligned
underlying memory size is always aligned

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2023-01-19 12:26:21 +00:00
committed by Compute-Runtime-Automation
parent f928d695e7
commit ce059e7fe3
2 changed files with 25 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -404,10 +404,10 @@ inline void EncodeStoreMMIO<Family>::encode(MI_STORE_REGISTER_MEM *cmdBuffer, ui
template <typename Family>
void EncodeSurfaceState<Family>::encodeBuffer(EncodeSurfaceStateArgs &args) {
auto surfaceState = reinterpret_cast<R_SURFACE_STATE *>(args.outMemory);
UNRECOVERABLE_IF(!isAligned<getSurfaceBaseAddressAlignment()>(args.size));
auto bufferSize = alignUp(args.size, getSurfaceBaseAddressAlignment());
SURFACE_STATE_BUFFER_LENGTH length = {0};
length.Length = static_cast<uint32_t>(args.size - 1);
length.Length = static_cast<uint32_t>(bufferSize - 1);
surfaceState->setWidth(length.SurfaceState.Width + 1);
surfaceState->setHeight(length.SurfaceState.Height + 1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -19,9 +19,30 @@
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "encode_surface_state_args.h"
using namespace NEO;
using CommandEncoderTests = ::testing::Test;
HWTEST_F(CommandEncoderTests, givenMisalignedSizeWhenProgrammingSurfaceStateForBufferThenAlignedSizeIsProgrammed) {
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
RENDER_SURFACE_STATE renderSurfaceState{};
MockExecutionEnvironment executionEnvironment{};
auto misalignedSize = 1u;
auto alignedSize = 4u;
NEO::EncodeSurfaceStateArgs args{};
args.outMemory = &renderSurfaceState;
args.gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
args.size = misalignedSize;
EncodeSurfaceState<FamilyType>::encodeBuffer(args);
EXPECT_EQ(alignedSize, renderSurfaceState.getWidth());
}
HWTEST_F(CommandEncoderTests, givenImmDataWriteWhenProgrammingMiFlushDwThenSetAllRequiredFields) {
using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW;
uint8_t buffer[2 * sizeof(MI_FLUSH_DW)] = {};