Correct media compression format for planar images

Set most significant bit for chroma planes.

Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2022-03-25 14:19:49 +00:00
committed by Compute-Runtime-Automation
parent 586e8510de
commit 3123ab5bf9
9 changed files with 71 additions and 10 deletions

View File

@ -410,6 +410,7 @@ Image *Image::create(Context *context,
image->setQPitch(imgInfo.qPitch);
image->setSurfaceOffsets(imgInfo.offset, imgInfo.xOffset, imgInfo.yOffset, imgInfo.yOffsetForUVPlane);
image->setMipCount(imgInfo.mipCount);
image->setPlane(imgInfo.plane);
if (parentImage) {
image->setMediaPlaneType(static_cast<cl_uint>(imageDesc->image_depth));
image->setParentSharingHandler(parentImage->getSharingHandler());
@ -516,6 +517,7 @@ Image *Image::createSharedImage(Context *context, SharingHandler *sharingHandler
sharedImage->setCubeFaceIndex(cubeFaceIndex);
sharedImage->setSurfaceOffsets(imgInfo.offset, imgInfo.xOffset, imgInfo.yOffset, imgInfo.yOffsetForUVPlane);
sharedImage->setMcsSurfaceInfo(mcsSurfaceInfo);
sharedImage->setPlane(imgInfo.plane);
return sharedImage;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -185,6 +185,8 @@ class Image : public MemObj {
cl_int writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch, uint32_t rootDeviceIndex);
void setMcsSurfaceInfo(const McsSurfaceInfo &info) { mcsSurfaceInfo = info; }
const McsSurfaceInfo &getMcsSurfaceInfo() { return mcsSurfaceInfo; }
void setPlane(const GMM_YUV_PLANE_ENUM plane) { this->plane = plane; }
GMM_YUV_PLANE_ENUM getPlane() const { return this->plane; }
size_t calculateOffsetForMapping(const MemObjOffsetArray &origin) const override;
virtual void transformImage2dArrayTo3d(void *memory) = 0;
@ -237,6 +239,7 @@ class Image : public MemObj {
SurfaceOffsets surfaceOffsets = {0};
uint32_t baseMipLevel = 0;
uint32_t mipCount = 1;
GMM_YUV_PLANE_ENUM plane = GMM_NO_PLANE;
static bool isValidSingleChannelFormat(const cl_image_format *imageFormat);
static bool isValidIntensityFormat(const cl_image_format *imageFormat);

View File

@ -93,7 +93,8 @@ void ImageHw<GfxFamily>::setImageArg(void *memory, bool setAsMediaBlockImage, ui
EncodeSurfaceState<GfxFamily>::disableCompressionFlags(surfaceState);
}
appendSurfaceStateDepthParams(surfaceState, gmm);
EncodeSurfaceState<GfxFamily>::appendImageCompressionParams(surfaceState, graphicsAllocation, gmmHelper, isImageFromBuffer());
EncodeSurfaceState<GfxFamily>::appendImageCompressionParams(surfaceState, graphicsAllocation, gmmHelper, isImageFromBuffer(),
this->plane);
appendSurfaceStateParams(surfaceState, rootDeviceIndex, useGlobalAtomics);
appendSurfaceStateExt(surfaceState);
}

View File

@ -148,6 +148,7 @@ TYPED_TEST_P(D3DTests, givenNV12FormatAndEvenPlaneWhen2dCreatedThenSetPlaneParam
auto image = std::unique_ptr<Image>(D3DTexture<TypeParam>::create2d(this->context, reinterpret_cast<D3DTexture2d *>(&this->dummyD3DTexture), CL_MEM_READ_WRITE, 4, nullptr));
ASSERT_NE(nullptr, image.get());
EXPECT_EQ(GMM_PLANE_Y, image->getPlane());
auto expectedFormat = D3DTexture<TypeParam>::findYuvSurfaceFormatInfo(DXGI_FORMAT_NV12, ImagePlane::PLANE_Y, CL_MEM_READ_WRITE);
EXPECT_TRUE(memcmp(expectedFormat, &image->getSurfaceFormatInfo(), sizeof(SurfaceFormatInfo)) == 0);
@ -233,6 +234,7 @@ TYPED_TEST_P(D3DTests, givenNV12FormatAndOddPlaneWhen2dCreatedThenSetPlaneParams
auto image = std::unique_ptr<Image>(D3DTexture<TypeParam>::create2d(this->context, reinterpret_cast<D3DTexture2d *>(&this->dummyD3DTexture), CL_MEM_READ_WRITE, 7, nullptr));
ASSERT_NE(nullptr, image.get());
EXPECT_EQ(GMM_PLANE_U, image->getPlane());
auto expectedFormat = D3DTexture<TypeParam>::findYuvSurfaceFormatInfo(DXGI_FORMAT_NV12, ImagePlane::PLANE_UV, CL_MEM_READ_WRITE);
EXPECT_TRUE(memcmp(expectedFormat, &image->getSurfaceFormatInfo(), sizeof(SurfaceFormatInfo)) == 0);

View File

@ -343,7 +343,7 @@ HWTEST2_F(XeHPAndLaterImageHelperTests, givenMediaCompressedImageWhenAppendingSu
const auto expectedGetMediaSurfaceStateCompressionFormatCalled = gmmClientContext->getMediaSurfaceStateCompressionFormatCalled + 1;
EncodeSurfaceState<FamilyType>::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(),
context->getDevice(0)->getGmmHelper(), false);
context->getDevice(0)->getGmmHelper(), false, GMM_NO_PLANE);
EXPECT_EQ(platform(), nullptr);
EXPECT_EQ(mockCompressionFormat, rss.getCompressionFormat());
@ -351,6 +351,47 @@ HWTEST2_F(XeHPAndLaterImageHelperTests, givenMediaCompressedImageWhenAppendingSu
EXPECT_EQ(expectedGetMediaSurfaceStateCompressionFormatCalled, gmmClientContext->getMediaSurfaceStateCompressionFormatCalled);
}
HWTEST2_F(XeHPAndLaterImageHelperTests, givenMediaCompressedPlanarImageWhenAppendingSurfaceStateParamsForCompressionThenCorrectCompressionFormatIsSet, CompressionParamsSupportedMatcher) {
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
RENDER_SURFACE_STATE rss{};
platformsImpl->clear();
rss.setMemoryCompressionEnable(true);
mockGmmResourceInfo->getResourceFlags()->Info.MediaCompressed = true;
struct {
uint8_t returnedCompressionFormat;
uint8_t expectedCompressionFormat;
GMM_YUV_PLANE_ENUM plane;
} testInputs[] = {
// regular image
{0x0, 0x0, GMM_NO_PLANE},
{0xF, 0xF, GMM_NO_PLANE},
{0x10, 0x10, GMM_NO_PLANE},
{0x1F, 0x1F, GMM_NO_PLANE},
// luma plane
{0x0, 0x0, GMM_PLANE_Y},
{0xF, 0xF, GMM_PLANE_Y},
{0x10, 0x0, GMM_PLANE_Y},
{0x1F, 0xF, GMM_PLANE_Y},
// chroma plane
{0x0, 0x10, GMM_PLANE_U},
{0x0, 0x10, GMM_PLANE_V},
{0xF, 0x1F, GMM_PLANE_U},
{0xF, 0x1F, GMM_PLANE_V},
{0x10, 0x10, GMM_PLANE_U},
{0x10, 0x10, GMM_PLANE_V},
{0x1F, 0x1F, GMM_PLANE_U},
{0x1F, 0x1F, GMM_PLANE_V},
};
for (auto &testInput : testInputs) {
gmmClientContext->compressionFormatToReturn = testInput.returnedCompressionFormat;
EncodeSurfaceState<FamilyType>::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(),
context->getDevice(0)->getGmmHelper(), false, testInput.plane);
EXPECT_EQ(testInput.expectedCompressionFormat, rss.getCompressionFormat());
}
}
HWTEST2_F(XeHPAndLaterImageHelperTests, givenNotMediaCompressedImageWhenAppendingSurfaceStateParamsForCompressionThenCallAppriopriateFunction, CompressionParamsSupportedMatcher) {
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
RENDER_SURFACE_STATE rss{};
@ -362,7 +403,7 @@ HWTEST2_F(XeHPAndLaterImageHelperTests, givenNotMediaCompressedImageWhenAppendin
const auto expectedGetMediaSurfaceStateCompressionFormatCalled = gmmClientContext->getMediaSurfaceStateCompressionFormatCalled;
EncodeSurfaceState<FamilyType>::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(),
context->getDevice(0)->getGmmHelper(), false);
context->getDevice(0)->getGmmHelper(), false, GMM_NO_PLANE);
EXPECT_EQ(platform(), nullptr);
EXPECT_EQ(mockCompressionFormat, rss.getCompressionFormat());
EXPECT_EQ(expectedGetSurfaceStateCompressionFormatCalled, gmmClientContext->getSurfaceStateCompressionFormatCalled);
@ -382,7 +423,7 @@ HWTEST2_F(XeHPAndLaterImageHelperTests, givenAuxModeMcsLceWhenAppendingSurfaceSt
const auto expectedGetMediaSurfaceStateCompressionFormatCalled = gmmClientContext->getMediaSurfaceStateCompressionFormatCalled + 1;
EncodeSurfaceState<FamilyType>::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(),
context->getDevice(0)->getGmmHelper(), false);
context->getDevice(0)->getGmmHelper(), false, GMM_NO_PLANE);
EXPECT_EQ(platform(), nullptr);
EXPECT_EQ(mockCompressionFormat, rss.getCompressionFormat());

View File

@ -242,6 +242,7 @@ TEST_F(Nv12ImageTest, WhenCreatingYPlaneImageThenDimensionsAreSetCorrectly) {
EXPECT_EQ(true, imageYPlane->isImageFromImage());
EXPECT_EQ(imageNV12->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()),
imageYPlane->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
EXPECT_EQ(GMM_PLANE_Y, imageYPlane->getPlane());
cl_image_desc parentDimensions, planeDimensions;
parentDimensions = imageNV12->getImageDesc();
@ -277,6 +278,7 @@ TEST_F(Nv12ImageTest, WhenCreatingUVPlaneImageThenDimensionsAreSetCorrectly) {
EXPECT_EQ(true, imageUVPlane->isImageFromImage());
EXPECT_EQ(imageNV12->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()),
imageUVPlane->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
EXPECT_EQ(GMM_PLANE_U, imageUVPlane->getPlane());
cl_image_desc parentDimensions, planeDimensions;
parentDimensions = imageNV12->getImageDesc();

View File

@ -6,9 +6,11 @@
*/
#pragma once
#include "shared/source/command_container/cmdcontainer.h"
#include "shared/source/debugger/debugger.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/gmm_helper/gmm_lib.h"
#include "shared/source/helpers/definitions/mi_flush_args.h"
#include "shared/source/helpers/pipe_control_args.h"
#include "shared/source/helpers/register_offsets.h"
@ -269,7 +271,8 @@ struct EncodeSurfaceState {
const void *srcKernelSsh, size_t srcKernelSshSize,
size_t numberOfBindingTableStates, size_t offsetOfBindingTable);
static void appendImageCompressionParams(R_SURFACE_STATE *surfaceState, GraphicsAllocation *allocation, GmmHelper *gmmHelper, bool imageFromBuffer);
static void appendImageCompressionParams(R_SURFACE_STATE *surfaceState, GraphicsAllocation *allocation, GmmHelper *gmmHelper,
bool imageFromBuffer, GMM_YUV_PLANE_ENUM plane);
static void setCoherencyType(R_SURFACE_STATE *surfaceState, COHERENCY_TYPE coherencyType);
static void setBufferAuxParamsForCCS(R_SURFACE_STATE *surfaceState);
static void setImageAuxParamsForCCS(R_SURFACE_STATE *surfaceState, Gmm *gmm);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -7,7 +7,8 @@
namespace NEO {
template <typename Family>
void EncodeSurfaceState<Family>::appendImageCompressionParams(R_SURFACE_STATE *surfaceState, GraphicsAllocation *allocation, GmmHelper *gmmHelper, bool imageFromBuffer) {
void EncodeSurfaceState<Family>::appendImageCompressionParams(R_SURFACE_STATE *surfaceState, GraphicsAllocation *allocation,
GmmHelper *gmmHelper, bool imageFromBuffer, GMM_YUV_PLANE_ENUM plane) {
}
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -11,7 +11,8 @@
namespace NEO {
template <typename Family>
void EncodeSurfaceState<Family>::appendImageCompressionParams(R_SURFACE_STATE *surfaceState, GraphicsAllocation *allocation, GmmHelper *gmmHelper, bool imageFromBuffer) {
void EncodeSurfaceState<Family>::appendImageCompressionParams(R_SURFACE_STATE *surfaceState, GraphicsAllocation *allocation, GmmHelper *gmmHelper, bool imageFromBuffer,
GMM_YUV_PLANE_ENUM plane) {
const auto ccsMode = R_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E;
const auto mcsLceMode = R_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_MCS_LCE;
if ((ccsMode == surfaceState->getAuxiliarySurfaceMode() || mcsLceMode == surfaceState->getAuxiliarySurfaceMode() || surfaceState->getMemoryCompressionEnable())) {
@ -19,6 +20,11 @@ void EncodeSurfaceState<Family>::appendImageCompressionParams(R_SURFACE_STATE *s
auto gmmResourceInfo = allocation->getDefaultGmm()->gmmResourceInfo.get();
if (gmmResourceInfo->getResourceFlags()->Info.MediaCompressed) {
compressionFormat = gmmHelper->getClientContext()->getMediaSurfaceStateCompressionFormat(gmmResourceInfo->getResourceFormat());
if (plane == GMM_PLANE_Y) {
compressionFormat &= 0xf;
} else if ((plane == GMM_PLANE_U) || (plane == GMM_PLANE_V)) {
compressionFormat |= 0x10;
}
} else {
compressionFormat = gmmHelper->getClientContext()->getSurfaceStateCompressionFormat(gmmResourceInfo->getResourceFormat());
}