1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/*
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_container/encode_surface_state.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "shared/test/unit_test/image/image_surface_state_fixture.h"
using namespace NEO;
HWTEST2_F(ImageSurfaceStateTests, givenImageInfoWhenSetImageSurfaceStateThenProperFieldsAreSet, MatchAny) {
auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE);
auto surfaceState = std::make_unique<char[]>(size);
auto castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
const uint32_t cubeFaceIndex = 2u;
imageInfo.qPitch = 1u;
imageInfo.imgDesc.imageArraySize = 2u;
imageInfo.imgDesc.imageDepth = 3u;
imageInfo.imgDesc.imageHeight = 4u;
imageInfo.imgDesc.imageRowPitch = 5u;
imageInfo.imgDesc.imageSlicePitch = 6u;
imageInfo.imgDesc.imageWidth = 7u;
imageInfo.imgDesc.numMipLevels = 8u;
imageInfo.imgDesc.numSamples = 9u;
imageInfo.imgDesc.imageType = ImageType::image2DArray;
SurfaceFormatInfo surfaceFormatInfo;
surfaceFormatInfo.genxSurfaceFormat = SurfaceFormat::GFX3DSTATE_SURFACEFORMAT_A32_FLOAT;
imageInfo.surfaceFormat = &surfaceFormatInfo;
SurfaceOffsets surfaceOffsets;
surfaceOffsets.offset = 0u;
surfaceOffsets.xOffset = 11u;
surfaceOffsets.yOffset = 12u;
surfaceOffsets.yOffsetForUVplane = 13u;
const uint64_t gpuAddress = 0x000001a78a8a8000;
uint32_t minArrayElement, renderTargetViewExtent;
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceState(castSurfaceState, imageInfo, mockGmm.get(), *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, true, minArrayElement, renderTargetViewExtent);
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
using SURFACE_FORMAT = typename RENDER_SURFACE_STATE::SURFACE_FORMAT;
using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
EXPECT_EQ(castSurfaceState->getRenderTargetViewExtent(), 1u);
EXPECT_EQ(castSurfaceState->getMinimumArrayElement(), cubeFaceIndex);
EXPECT_EQ(castSurfaceState->getSurfaceQPitch(), imageInfo.qPitch >> RENDER_SURFACE_STATE::tagSURFACEQPITCH::SURFACEQPITCH_BIT_SHIFT);
EXPECT_EQ(castSurfaceState->getSurfaceArray(), true);
EXPECT_EQ(castSurfaceState->getSurfaceHorizontalAlignment(), static_cast<typename RENDER_SURFACE_STATE::SURFACE_HORIZONTAL_ALIGNMENT>(mockGmm->gmmResourceInfo->getHAlignSurfaceState()));
EXPECT_EQ(castSurfaceState->getSurfaceVerticalAlignment(), static_cast<typename RENDER_SURFACE_STATE::SURFACE_VERTICAL_ALIGNMENT>(mockGmm->gmmResourceInfo->getVAlignSurfaceState()));
EXPECT_EQ(castSurfaceState->getTileMode(), mockGmm->gmmResourceInfo->getTileModeSurfaceState());
EXPECT_EQ(castSurfaceState->getMemoryObjectControlState(), gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE));
if constexpr (IsAtMostXeCore::isMatched<productFamily>()) {
EXPECT_EQ(castSurfaceState->getCoherencyType(), RENDER_SURFACE_STATE::COHERENCY_TYPE_GPU_COHERENT);
}
EXPECT_EQ(castSurfaceState->getMultisampledSurfaceStorageFormat(), RENDER_SURFACE_STATE::MULTISAMPLED_SURFACE_STORAGE_FORMAT::MULTISAMPLED_SURFACE_STORAGE_FORMAT_MSS);
EXPECT_EQ(castSurfaceState->getSurfaceBaseAddress(), gpuAddress + surfaceOffsets.offset);
uint32_t xOffset = surfaceOffsets.xOffset >> RENDER_SURFACE_STATE::tagXOFFSET::XOFFSET_BIT_SHIFT;
uint32_t yOffset = surfaceOffsets.yOffset >> RENDER_SURFACE_STATE::tagYOFFSET::YOFFSET_BIT_SHIFT;
EXPECT_EQ(castSurfaceState->getXOffset(), xOffset << RENDER_SURFACE_STATE::tagXOFFSET::XOFFSET_BIT_SHIFT);
EXPECT_EQ(castSurfaceState->getYOffset(), yOffset << RENDER_SURFACE_STATE::tagYOFFSET::YOFFSET_BIT_SHIFT);
EXPECT_EQ(castSurfaceState->getShaderChannelSelectAlpha(), RENDER_SURFACE_STATE::SHADER_CHANNEL_SELECT_ONE);
EXPECT_EQ(castSurfaceState->getYOffsetForUOrUvPlane(), surfaceOffsets.yOffsetForUVplane);
EXPECT_EQ(castSurfaceState->getXOffsetForUOrUvPlane(), surfaceOffsets.xOffset);
EXPECT_EQ(castSurfaceState->getSurfaceFormat(), static_cast<SURFACE_FORMAT>(imageInfo.surfaceFormat->genxSurfaceFormat));
surfaceState = std::make_unique<char[]>(size);
castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceState(castSurfaceState, imageInfo, nullptr, *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, false, minArrayElement, renderTargetViewExtent);
EXPECT_EQ(castSurfaceState->getSurfaceHorizontalAlignment(), RENDER_SURFACE_STATE::SURFACE_HORIZONTAL_ALIGNMENT_HALIGN_DEFAULT);
EXPECT_EQ(castSurfaceState->getSurfaceVerticalAlignment(), RENDER_SURFACE_STATE::SURFACE_VERTICAL_ALIGNMENT_VALIGN_4);
EXPECT_EQ(castSurfaceState->getShaderChannelSelectAlpha(), RENDER_SURFACE_STATE::SHADER_CHANNEL_SELECT_ALPHA);
EXPECT_EQ(castSurfaceState->getYOffsetForUOrUvPlane(), 0u);
EXPECT_EQ(castSurfaceState->getXOffsetForUOrUvPlane(), 0u);
EXPECT_EQ(castSurfaceState->getAuxiliarySurfaceMode(), AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE);
EXPECT_EQ(castSurfaceState->getAuxiliarySurfacePitch(), 1u);
EXPECT_EQ(castSurfaceState->getAuxiliarySurfaceQPitch(), 0u);
EXPECT_EQ(castSurfaceState->getAuxiliarySurfaceBaseAddress(), 0u);
surfaceState = std::make_unique<char[]>(size);
castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
typename FamilyType::RENDER_SURFACE_STATE::SURFACE_TYPE surfaceType = RENDER_SURFACE_STATE::SURFACE_TYPE::SURFACE_TYPE_SURFTYPE_3D;
uint32_t depth;
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceStateDimensions(castSurfaceState, imageInfo, cubeFaceIndex, surfaceType, depth);
EXPECT_EQ(castSurfaceState->getWidth(), static_cast<uint32_t>(imageInfo.imgDesc.imageWidth));
EXPECT_EQ(castSurfaceState->getHeight(), static_cast<uint32_t>(imageInfo.imgDesc.imageHeight));
EXPECT_EQ(castSurfaceState->getDepth(), __GMM_MAX_CUBE_FACE - cubeFaceIndex);
EXPECT_EQ(castSurfaceState->getSurfacePitch(), static_cast<uint32_t>(imageInfo.imgDesc.imageRowPitch));
EXPECT_EQ(castSurfaceState->getSurfaceType(), surfaceType);
}
HWTEST_F(ImageSurfaceStateTests, givenGmmWhenSetAuxParamsForCCSThenAuxiliarySurfaceModeIsSet) {
auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE);
auto surfaceState = std::make_unique<char[]>(size);
auto castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
EncodeSurfaceState<FamilyType>::setImageAuxParamsForCCS(castSurfaceState, mockGmm.get());
mockGmm->setCompressionEnabled(true);
EXPECT_TRUE(EncodeSurfaceState<FamilyType>::isAuxModeEnabled(castSurfaceState, mockGmm.get()));
}
HWTEST_F(ImageSurfaceStateTests, givenImage2DWhen2dImageWAIsEnabledThenArrayFlagIsSet) {
DebugManagerStateRestore debugSettingsRestore;
debugManager.flags.Force2dImageAsArray.set(1);
auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE);
auto surfaceState = std::make_unique<char[]>(size);
auto castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
imageInfo.imgDesc.imageType = ImageType::image2D;
imageInfo.imgDesc.imageDepth = 1;
imageInfo.imgDesc.imageArraySize = 1;
imageInfo.qPitch = 0;
SurfaceOffsets surfaceOffsets = {0, 0, 0, 0};
const uint32_t cubeFaceIndex = __GMM_NO_CUBE_MAP;
SurfaceFormatInfo surfaceFormatInfo;
surfaceFormatInfo.genxSurfaceFormat = SurfaceFormat::GFX3DSTATE_SURFACEFORMAT_A32_FLOAT;
imageInfo.surfaceFormat = &surfaceFormatInfo;
const uint64_t gpuAddress = 0x000001a78a8a8000;
uint32_t minArrayElement, renderTargetViewExtent;
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceState(castSurfaceState, imageInfo, mockGmm.get(), *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, true, minArrayElement, renderTargetViewExtent);
EXPECT_TRUE(castSurfaceState->getSurfaceArray());
}
HWTEST_F(ImageSurfaceStateTests, givenImage2DWhen2dImageWAIsDisabledThenArrayFlagIsNotSet) {
DebugManagerStateRestore debugSettingsRestore;
debugManager.flags.Force2dImageAsArray.set(0);
auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE);
auto surfaceState = std::make_unique<char[]>(size);
auto castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
imageInfo.imgDesc.imageType = ImageType::image2D;
imageInfo.imgDesc.imageDepth = 1;
imageInfo.imgDesc.imageArraySize = 1;
imageInfo.qPitch = 0;
SurfaceOffsets surfaceOffsets = {0, 0, 0, 0};
const uint32_t cubeFaceIndex = __GMM_NO_CUBE_MAP;
SurfaceFormatInfo surfaceFormatInfo;
surfaceFormatInfo.genxSurfaceFormat = SurfaceFormat::GFX3DSTATE_SURFACEFORMAT_A32_FLOAT;
imageInfo.surfaceFormat = &surfaceFormatInfo;
const uint64_t gpuAddress = 0x000001a78a8a8000;
uint32_t minArrayElement, renderTargetViewExtent;
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceState(castSurfaceState, imageInfo, mockGmm.get(), *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, true, minArrayElement, renderTargetViewExtent);
EXPECT_FALSE(castSurfaceState->getSurfaceArray());
}
HWTEST_F(ImageSurfaceStateTests, givenImage2DArrayOfSize1When2dImageWAIsEnabledThenArrayFlagIsSet) {
DebugManagerStateRestore debugSettingsRestore;
debugManager.flags.Force2dImageAsArray.set(1);
auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE);
auto surfaceState = std::make_unique<char[]>(size);
auto castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
imageInfo.imgDesc.imageType = ImageType::image2DArray;
imageInfo.imgDesc.imageDepth = 1;
imageInfo.imgDesc.imageArraySize = 1;
imageInfo.qPitch = 0;
SurfaceOffsets surfaceOffsets = {0, 0, 0, 0};
const uint32_t cubeFaceIndex = __GMM_NO_CUBE_MAP;
SurfaceFormatInfo surfaceFormatInfo;
surfaceFormatInfo.genxSurfaceFormat = SurfaceFormat::GFX3DSTATE_SURFACEFORMAT_A32_FLOAT;
imageInfo.surfaceFormat = &surfaceFormatInfo;
const uint64_t gpuAddress = 0x000001a78a8a8000;
uint32_t minArrayElement, renderTargetViewExtent;
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceState(castSurfaceState, imageInfo, mockGmm.get(), *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, true, minArrayElement, renderTargetViewExtent);
EXPECT_TRUE(castSurfaceState->getSurfaceArray());
}
HWTEST_F(ImageSurfaceStateTests, givenImage2DArrayOfSize1When2dImageWAIsDisabledThenArrayFlagIsNotSet) {
DebugManagerStateRestore debugSettingsRestore;
debugManager.flags.Force2dImageAsArray.set(0);
auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE);
auto surfaceState = std::make_unique<char[]>(size);
auto castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
imageInfo.imgDesc.imageType = ImageType::image2DArray;
imageInfo.imgDesc.imageDepth = 1;
imageInfo.imgDesc.imageArraySize = 1;
imageInfo.qPitch = 0;
SurfaceOffsets surfaceOffsets = {0, 0, 0, 0};
const uint32_t cubeFaceIndex = __GMM_NO_CUBE_MAP;
SurfaceFormatInfo surfaceFormatInfo;
surfaceFormatInfo.genxSurfaceFormat = SurfaceFormat::GFX3DSTATE_SURFACEFORMAT_A32_FLOAT;
imageInfo.surfaceFormat = &surfaceFormatInfo;
const uint64_t gpuAddress = 0x000001a78a8a8000;
uint32_t minArrayElement, renderTargetViewExtent;
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceState(castSurfaceState, imageInfo, mockGmm.get(), *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, true, minArrayElement, renderTargetViewExtent);
if (ImageSurfaceStateHelper<FamilyType>::imageAsArrayWithArraySizeOf1NotPreferred()) {
EXPECT_FALSE(castSurfaceState->getSurfaceArray());
} else {
EXPECT_TRUE(castSurfaceState->getSurfaceArray());
}
}
HWTEST_F(ImageSurfaceStateTests, givenImage1DWhen2dImageWAIsEnabledThenArrayFlagIsNotSet) {
DebugManagerStateRestore debugSettingsRestore;
debugManager.flags.Force2dImageAsArray.set(1);
auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE);
auto surfaceState = std::make_unique<char[]>(size);
auto castSurfaceState = reinterpret_cast<typename FamilyType::RENDER_SURFACE_STATE *>(surfaceState.get());
imageInfo.imgDesc.imageType = ImageType::image1D;
imageInfo.imgDesc.imageDepth = 1;
imageInfo.imgDesc.imageArraySize = 1;
imageInfo.qPitch = 0;
SurfaceOffsets surfaceOffsets = {0, 0, 0, 0};
const uint32_t cubeFaceIndex = __GMM_NO_CUBE_MAP;
SurfaceFormatInfo surfaceFormatInfo;
surfaceFormatInfo.genxSurfaceFormat = SurfaceFormat::GFX3DSTATE_SURFACEFORMAT_A32_FLOAT;
imageInfo.surfaceFormat = &surfaceFormatInfo;
const uint64_t gpuAddress = 0x000001a78a8a8000;
uint32_t minArrayElement, renderTargetViewExtent;
ImageSurfaceStateHelper<FamilyType>::setImageSurfaceState(castSurfaceState, imageInfo, mockGmm.get(), *gmmHelper, cubeFaceIndex, gpuAddress, surfaceOffsets, true, minArrayElement, renderTargetViewExtent);
EXPECT_FALSE(castSurfaceState->getSurfaceArray());
}
struct ImageWidthTest : ImageSurfaceStateTests {
struct ImageWidthParams {
uint32_t imageWidth;
uint32_t expectedWidthInDwords;
};
template <typename FamilyType>
void verifyProgramming(typename FamilyType::RENDER_SURFACE_STATE &renderSurfaceState, const std::array<ImageWidthParams, 6> ¶ms) {
for (auto ¶m : params) {
imageInfo.imgDesc.imageWidth = param.imageWidth;
ImageSurfaceStateHelper<FamilyType>::setWidthForMediaBlockSurfaceState(&renderSurfaceState, imageInfo);
EXPECT_EQ(param.expectedWidthInDwords, renderSurfaceState.getWidth());
}
}
};
HWTEST_F(ImageWidthTest, givenMediaBlockWhenProgrammingWidthInSurfaceStateThenCorrectValueIsProgrammed) {
SurfaceFormatInfo surfaceFormatInfo{};
imageInfo.surfaceFormat = &surfaceFormatInfo;
auto renderSurfaceState = FamilyType::cmdInitRenderSurfaceState;
{
surfaceFormatInfo.imageElementSizeInBytes = 1u;
static constexpr std::array<ImageWidthParams, 6> params = {{
{1, 1},
{2, 1},
{3, 1},
{4, 1},
{5, 2},
{6, 2},
}};
verifyProgramming<FamilyType>(renderSurfaceState, params);
}
{
surfaceFormatInfo.imageElementSizeInBytes = 2u;
static constexpr std::array<ImageWidthParams, 6> params = {{
{1, 1},
{2, 1},
{3, 2},
{4, 2},
{5, 3},
{6, 3},
}};
verifyProgramming<FamilyType>(renderSurfaceState, params);
}
{
surfaceFormatInfo.imageElementSizeInBytes = 4u;
static constexpr std::array<ImageWidthParams, 6> params = {{
{1, 1},
{2, 2},
{3, 3},
{4, 4},
{5, 5},
{6, 6},
}};
verifyProgramming<FamilyType>(renderSurfaceState, params);
}
}
|