2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-02-05 09:58:42 +08:00
|
|
|
* Copyright (C) 2017-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
|
|
|
#include "shared/source/utilities/numeric.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/helpers/sampler_helpers.h"
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
|
|
|
#include "opencl/source/sampler/sampler.h"
|
2020-05-28 20:05:12 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/image_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_kernel.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_program.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "test.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
class Surface;
|
|
|
|
};
|
|
|
|
|
2020-05-28 20:05:12 +08:00
|
|
|
class SamplerSetArgFixture : public ClDeviceFixture {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
|
|
|
SamplerSetArgFixture()
|
|
|
|
|
|
|
|
{
|
|
|
|
memset(&kernelHeader, 0, sizeof(kernelHeader));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SetUp() {
|
2020-05-28 20:05:12 +08:00
|
|
|
ClDeviceFixture::SetUp();
|
2018-08-16 20:28:58 +08:00
|
|
|
pKernelInfo = std::make_unique<KernelInfo>();
|
2020-11-19 19:30:44 +08:00
|
|
|
pKernelInfo->kernelDescriptor.kernelAttributes.simdSize = 1;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// define kernel info
|
|
|
|
pKernelInfo->heapInfo.pDsh = samplerStateHeap;
|
2020-05-26 15:36:04 +08:00
|
|
|
pKernelInfo->heapInfo.DynamicStateHeapSize = sizeof(samplerStateHeap);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// setup kernel arg offsets
|
|
|
|
pKernelInfo->kernelArgInfo.resize(2);
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap = 0x40;
|
|
|
|
pKernelInfo->kernelArgInfo[0].isSampler = true;
|
|
|
|
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetObjectId = 0x0;
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetSamplerSnapWa = 0x4;
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetSamplerAddressingMode = 0x8;
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetSamplerNormalizedCoords = 0x10;
|
|
|
|
|
|
|
|
pKernelInfo->kernelArgInfo[1].offsetHeap = 0x40;
|
|
|
|
pKernelInfo->kernelArgInfo[1].isSampler = true;
|
|
|
|
|
2020-10-16 21:00:28 +08:00
|
|
|
program = std::make_unique<MockProgram>(toClDeviceVector(*pClDevice));
|
2020-12-03 02:19:05 +08:00
|
|
|
pKernel = new MockKernel(program.get(), MockKernel::toKernelInfoContainer(*pKernelInfo, rootDeviceIndex));
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_NE(nullptr, pKernel);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, pKernel->initialize());
|
2021-03-09 18:30:21 +08:00
|
|
|
pMultiDeviceKernel = new MultiDeviceKernel(pKernel);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
pKernel->setKernelArgHandler(0, &Kernel::setArgSampler);
|
|
|
|
pKernel->setKernelArgHandler(1, &Kernel::setArgSampler);
|
|
|
|
|
|
|
|
uint32_t crossThreadData[crossThreadDataSize] = {};
|
|
|
|
pKernel->setCrossThreadData(crossThreadData, sizeof(crossThreadData));
|
2020-01-14 21:32:11 +08:00
|
|
|
context = new MockContext(pClDevice);
|
2017-12-21 07:45:38 +08:00
|
|
|
retVal = CL_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() {
|
2021-03-09 18:30:21 +08:00
|
|
|
delete pMultiDeviceKernel;
|
2018-08-16 20:28:58 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
delete sampler;
|
|
|
|
delete context;
|
2020-05-28 20:05:12 +08:00
|
|
|
ClDeviceFixture::TearDown();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool crossThreadDataUnchanged() {
|
|
|
|
for (uint32_t i = 0; i < crossThreadDataSize; i++) {
|
2020-12-18 00:26:13 +08:00
|
|
|
if (pKernel->mockCrossThreadDatas[rootDeviceIndex][i] != 0u) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void createSampler() {
|
|
|
|
sampler = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32_t crossThreadDataSize = 0x40;
|
|
|
|
|
2018-08-09 17:34:50 +08:00
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
std::unique_ptr<MockProgram> program;
|
|
|
|
MockKernel *pKernel = nullptr;
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
SKernelBinaryHeaderCommon kernelHeader;
|
2018-08-16 20:28:58 +08:00
|
|
|
std::unique_ptr<KernelInfo> pKernelInfo;
|
2018-08-09 17:34:50 +08:00
|
|
|
char samplerStateHeap[0x80];
|
|
|
|
MockContext *context;
|
|
|
|
Sampler *sampler = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef Test<SamplerSetArgFixture> SamplerSetArgTest;
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, WhenSettingKernelArgSamplerThenSamplerStatesAreCorrect) {
|
2017-12-21 07:45:38 +08:00
|
|
|
typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE;
|
|
|
|
createSampler();
|
|
|
|
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = clSetKernelArg(
|
2021-03-09 18:30:21 +08:00
|
|
|
pMultiDeviceKernel,
|
2017-12-21 07:45:38 +08:00
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto samplerState = reinterpret_cast<const SAMPLER_STATE *>(
|
2020-12-08 20:11:40 +08:00
|
|
|
ptrOffset(pKernel->getDynamicStateHeap(rootDeviceIndex),
|
2017-12-21 07:45:38 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap));
|
|
|
|
EXPECT_EQ(static_cast<cl_bool>(CL_TRUE), static_cast<cl_bool>(!samplerState->getNonNormalizedCoordinateEnable()));
|
2019-09-06 20:19:02 +08:00
|
|
|
EXPECT_EQ(SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR, samplerState->getTcxAddressControlMode());
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR, samplerState->getTcyAddressControlMode());
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR, samplerState->getTczAddressControlMode());
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(SAMPLER_STATE::MIN_MODE_FILTER_NEAREST, samplerState->getMinModeFilter());
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::MAG_MODE_FILTER_NEAREST, samplerState->getMagModeFilter());
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::MIP_MODE_FILTER_NEAREST, samplerState->getMipModeFilter());
|
|
|
|
|
|
|
|
std::vector<Surface *> surfaces;
|
2020-11-25 00:07:54 +08:00
|
|
|
pKernel->getResidency(surfaces, rootDeviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(0u, surfaces.size());
|
|
|
|
}
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, WhenGettingKernelArgThenSamplerIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
createSampler();
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(samplerObj, pKernel->getKernelArg(0));
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:42:52 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenSamplerObjectWhenSetKernelArgIsCalledThenIncreaseSamplerRefcount) {
|
|
|
|
cl_sampler samplerObj = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
auto pSampler = castToObject<Sampler>(samplerObj);
|
|
|
|
auto refCountBefore = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
auto refCountAfter = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
EXPECT_EQ(refCountBefore + 1, refCountAfter);
|
|
|
|
|
|
|
|
retVal = clReleaseSampler(samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2018-08-14 22:18:39 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenSamplerObjectWhenSetKernelArgIsCalledThenSamplerObjectSurvivesClReleaseSampler) {
|
|
|
|
cl_sampler samplerObj = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
auto pSampler = castToObject<Sampler>(samplerObj);
|
|
|
|
auto refCountBefore = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseSampler(samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto refCountAfter = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
EXPECT_EQ(refCountBefore, refCountAfter);
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:42:52 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenSamplerObjectWhenSetKernelArgIsCalledAndKernelIsDeletedThenRefCountIsUnchanged) {
|
2020-12-03 02:19:05 +08:00
|
|
|
auto myKernel = std::make_unique<MockKernel>(program.get(), MockKernel::toKernelInfoContainer(*pKernelInfo, rootDeviceIndex));
|
2018-08-10 19:42:52 +08:00
|
|
|
ASSERT_NE(nullptr, myKernel.get());
|
|
|
|
ASSERT_EQ(CL_SUCCESS, myKernel->initialize());
|
|
|
|
|
|
|
|
myKernel->setKernelArgHandler(0, &Kernel::setArgSampler);
|
|
|
|
myKernel->setKernelArgHandler(1, &Kernel::setArgSampler);
|
|
|
|
|
|
|
|
uint32_t crossThreadData[crossThreadDataSize] = {};
|
|
|
|
myKernel->setCrossThreadData(crossThreadData, sizeof(crossThreadData));
|
|
|
|
cl_sampler samplerObj = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
auto pSampler = castToObject<Sampler>(samplerObj);
|
|
|
|
auto refCountBefore = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
retVal = myKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
myKernel.reset();
|
|
|
|
|
|
|
|
auto refCountAfter = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
EXPECT_EQ(refCountBefore, refCountAfter);
|
|
|
|
|
|
|
|
retVal = clReleaseSampler(samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(SamplerSetArgTest, GivenNewSamplerObjectWhensSetKernelArgIsCalledThenDecreaseOldSamplerRefcount) {
|
|
|
|
cl_sampler samplerObj = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
2018-08-14 22:18:39 +08:00
|
|
|
auto pSampler = castToObject<Sampler>(samplerObj);
|
2018-08-10 19:42:52 +08:00
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto refCountBefore = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
cl_sampler samplerObj2 = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj2),
|
|
|
|
&samplerObj2);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto refCountAfter = pSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
EXPECT_EQ(refCountBefore - 1, refCountAfter);
|
|
|
|
|
|
|
|
retVal = clReleaseSampler(samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseSampler(samplerObj2);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(SamplerSetArgTest, GivenIncorrentSamplerObjectWhenSetKernelArgSamplerIsCalledThenLeaveRefcountAsIs) {
|
|
|
|
auto notSamplerObj = std::unique_ptr<Image>(ImageHelper<Image2dDefaults>::create(context));
|
|
|
|
|
|
|
|
auto pNotSampler = castToObject<Image>(notSamplerObj.get());
|
|
|
|
auto refCountBefore = pNotSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
retVal = pKernel->setArgSampler(
|
|
|
|
0,
|
|
|
|
sizeof(notSamplerObj.get()),
|
|
|
|
notSamplerObj.get());
|
|
|
|
auto refCountAfter = pNotSampler->getRefInternalCount();
|
|
|
|
|
|
|
|
EXPECT_EQ(refCountBefore, refCountAfter);
|
|
|
|
}
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenFilteringNearestAndAddressingClampWhenSettingKernelArgumentThenConstantBufferIsSet) {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
sampler = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_CLAMP,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(samplerObj, pKernel->getKernelArg(0));
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto crossThreadData = reinterpret_cast<uint32_t *>(pKernel->getCrossThreadData(rootDeviceIndex));
|
2017-12-21 07:45:38 +08:00
|
|
|
auto snapWaCrossThreadData = ptrOffset(crossThreadData, 0x4);
|
|
|
|
|
|
|
|
unsigned int snapWaValue = 0xffffffff;
|
|
|
|
unsigned int objectId = SAMPLER_OBJECT_ID_SHIFT + pKernelInfo->kernelArgInfo[0].offsetHeap;
|
|
|
|
|
|
|
|
EXPECT_EQ(snapWaValue, *snapWaCrossThreadData);
|
|
|
|
EXPECT_EQ(objectId, *crossThreadData);
|
|
|
|
}
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenKernelWithoutObjIdOffsetWhenSettingArgThenObjIdNotPatched) {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
sampler = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_CLAMP,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
1,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(samplerObj, pKernel->getKernelArg(1));
|
|
|
|
EXPECT_TRUE(crossThreadDataUnchanged());
|
|
|
|
}
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenNullWhenSettingKernelArgThenInvalidSamplerErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
createSampler();
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
nullptr);
|
|
|
|
ASSERT_EQ(CL_INVALID_SAMPLER, retVal);
|
|
|
|
}
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenInvalidSamplerWhenSettingKernelArgThenInvalidSamplerErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
createSampler();
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
const void *notASampler = reinterpret_cast<const void *>(pKernel);
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
notASampler);
|
|
|
|
ASSERT_EQ(CL_INVALID_SAMPLER, retVal);
|
|
|
|
}
|
|
|
|
|
2019-05-16 15:48:32 +08:00
|
|
|
TEST_F(SamplerSetArgTest, givenSamplerTypeStrAndIsSamplerTrueWhenInitializeKernelThenKernelArgumentsTypeIsSamplerObj) {
|
|
|
|
pKernelInfo->kernelArgInfo.resize(2);
|
2020-01-12 01:25:26 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].metadataExtended = std::make_unique<ArgTypeMetadataExtended>();
|
|
|
|
pKernelInfo->kernelArgInfo[0].metadataExtended->type = "sampler*";
|
2019-05-16 15:48:32 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].isSampler = true;
|
2020-01-12 01:25:26 +08:00
|
|
|
pKernelInfo->kernelArgInfo[1].metadataExtended = std::make_unique<ArgTypeMetadataExtended>();
|
|
|
|
pKernelInfo->kernelArgInfo[1].metadataExtended->type = "sampler";
|
2019-05-16 15:48:32 +08:00
|
|
|
pKernelInfo->kernelArgInfo[1].isSampler = true;
|
|
|
|
|
2020-12-03 02:19:05 +08:00
|
|
|
auto pMockKernell = std::make_unique<MockKernel>(program.get(), MockKernel::toKernelInfoContainer(*pKernelInfo, rootDeviceIndex));
|
2019-05-16 15:48:32 +08:00
|
|
|
ASSERT_EQ(CL_SUCCESS, pMockKernell->initialize());
|
|
|
|
EXPECT_EQ(pMockKernell->getKernelArguments()[0].type, MockKernel::SAMPLER_OBJ);
|
|
|
|
EXPECT_EQ(pMockKernell->getKernelArguments()[1].type, MockKernel::SAMPLER_OBJ);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SamplerSetArgTest, givenSamplerTypeStrAndAndIsSamplerFalseWhenInitializeKernelThenKernelArgumentsTypeIsNotSamplerObj) {
|
|
|
|
pKernelInfo->kernelArgInfo.resize(2);
|
2020-01-12 01:25:26 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].metadataExtended = std::make_unique<ArgTypeMetadataExtended>();
|
|
|
|
pKernelInfo->kernelArgInfo[0].metadataExtended->type = "sampler*";
|
2019-05-16 15:48:32 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].isSampler = false;
|
2020-01-12 01:25:26 +08:00
|
|
|
pKernelInfo->kernelArgInfo[1].metadataExtended = std::make_unique<ArgTypeMetadataExtended>();
|
|
|
|
pKernelInfo->kernelArgInfo[1].metadataExtended->type = "sampler";
|
2019-05-16 15:48:32 +08:00
|
|
|
pKernelInfo->kernelArgInfo[1].isSampler = false;
|
|
|
|
|
2020-12-03 02:19:05 +08:00
|
|
|
auto pMockKernell = std::make_unique<MockKernel>(program.get(), MockKernel::toKernelInfoContainer(*pKernelInfo, rootDeviceIndex));
|
2019-05-16 15:48:32 +08:00
|
|
|
ASSERT_EQ(CL_SUCCESS, pMockKernell->initialize());
|
|
|
|
EXPECT_NE(pMockKernell->getKernelArguments()[0].type, MockKernel::SAMPLER_OBJ);
|
|
|
|
EXPECT_NE(pMockKernell->getKernelArguments()[1].type, MockKernel::SAMPLER_OBJ);
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
struct NormalizedTest
|
|
|
|
: public SamplerSetArgFixture,
|
|
|
|
public ::testing::TestWithParam<uint32_t /*cl_bool*/> {
|
|
|
|
void SetUp() override {
|
|
|
|
SamplerSetArgFixture::SetUp();
|
|
|
|
}
|
|
|
|
void TearDown() override {
|
|
|
|
SamplerSetArgFixture::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_P(NormalizedTest, WhenSettingKernelArgSamplerThenCoordsAreCorrect) {
|
2017-12-21 07:45:38 +08:00
|
|
|
typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE;
|
|
|
|
auto normalizedCoordinates = GetParam();
|
|
|
|
sampler = Sampler::create(
|
|
|
|
context,
|
|
|
|
normalizedCoordinates,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto samplerState = reinterpret_cast<const SAMPLER_STATE *>(
|
2020-12-08 20:11:40 +08:00
|
|
|
ptrOffset(pKernel->getDynamicStateHeap(rootDeviceIndex),
|
2017-12-21 07:45:38 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap));
|
|
|
|
|
|
|
|
EXPECT_EQ(normalizedCoordinates, static_cast<cl_bool>(!samplerState->getNonNormalizedCoordinateEnable()));
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto crossThreadData = reinterpret_cast<uint32_t *>(pKernel->getCrossThreadData(rootDeviceIndex));
|
2017-12-21 07:45:38 +08:00
|
|
|
auto normalizedCoordsAddress = ptrOffset(crossThreadData, 0x10);
|
|
|
|
unsigned int normalizedCoordsValue = GetNormCoordsEnum(normalizedCoordinates);
|
|
|
|
|
|
|
|
EXPECT_EQ(normalizedCoordsValue, *normalizedCoordsAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_bool normalizedCoordinatesCases[] = {
|
|
|
|
CL_FALSE,
|
|
|
|
CL_TRUE};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(SamplerSetArg,
|
|
|
|
NormalizedTest,
|
|
|
|
::testing::ValuesIn(normalizedCoordinatesCases));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
struct AddressingModeTest
|
|
|
|
: public SamplerSetArgFixture,
|
|
|
|
public ::testing::TestWithParam<uint32_t /*cl_addressing_mode*/> {
|
|
|
|
void SetUp() override {
|
|
|
|
SamplerSetArgFixture::SetUp();
|
|
|
|
}
|
|
|
|
void TearDown() override {
|
|
|
|
SamplerSetArgFixture::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_P(AddressingModeTest, WhenSettingKernelArgSamplerThenModesAreCorrect) {
|
2017-12-21 07:45:38 +08:00
|
|
|
typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE;
|
|
|
|
auto addressingMode = GetParam();
|
|
|
|
sampler = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
addressingMode,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto samplerState = reinterpret_cast<const SAMPLER_STATE *>(
|
2020-12-08 20:11:40 +08:00
|
|
|
ptrOffset(pKernel->getDynamicStateHeap(rootDeviceIndex),
|
2017-12-21 07:45:38 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap));
|
|
|
|
|
2019-09-06 20:19:02 +08:00
|
|
|
auto expectedModeX = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR;
|
|
|
|
auto expectedModeY = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR;
|
|
|
|
auto expectedModeZ = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
switch (addressingMode) {
|
|
|
|
case CL_ADDRESS_NONE:
|
|
|
|
case CL_ADDRESS_CLAMP:
|
2019-09-06 20:19:02 +08:00
|
|
|
expectedModeX = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_CLAMP_BORDER;
|
|
|
|
expectedModeY = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_CLAMP_BORDER;
|
|
|
|
expectedModeZ = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_CLAMP_BORDER;
|
2017-12-21 07:45:38 +08:00
|
|
|
break;
|
|
|
|
case CL_ADDRESS_CLAMP_TO_EDGE:
|
2019-09-06 20:19:02 +08:00
|
|
|
expectedModeX = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_CLAMP;
|
|
|
|
expectedModeY = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_CLAMP;
|
|
|
|
expectedModeZ = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_CLAMP;
|
2017-12-21 07:45:38 +08:00
|
|
|
break;
|
|
|
|
case CL_ADDRESS_MIRRORED_REPEAT:
|
2019-09-06 20:19:02 +08:00
|
|
|
expectedModeX = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR;
|
|
|
|
expectedModeY = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR;
|
|
|
|
expectedModeZ = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_MIRROR;
|
2017-12-21 07:45:38 +08:00
|
|
|
break;
|
|
|
|
case CL_ADDRESS_REPEAT:
|
2019-09-06 20:19:02 +08:00
|
|
|
expectedModeX = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_WRAP;
|
|
|
|
expectedModeY = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_WRAP;
|
|
|
|
expectedModeZ = SAMPLER_STATE::TEXTURE_COORDINATE_MODE_WRAP;
|
2017-12-21 07:45:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
EXPECT_EQ(expectedModeX, samplerState->getTcxAddressControlMode());
|
|
|
|
EXPECT_EQ(expectedModeY, samplerState->getTcyAddressControlMode());
|
|
|
|
EXPECT_EQ(expectedModeZ, samplerState->getTczAddressControlMode());
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto crossThreadData = reinterpret_cast<uint32_t *>(pKernel->getCrossThreadData(rootDeviceIndex));
|
2017-12-21 07:45:38 +08:00
|
|
|
auto addressingModeAddress = ptrOffset(crossThreadData, 0x8);
|
|
|
|
|
|
|
|
unsigned int addresingValue = GetAddrModeEnum(addressingMode);
|
|
|
|
|
|
|
|
EXPECT_EQ(addresingValue, *addressingModeAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_addressing_mode addressingModeCases[] = {
|
|
|
|
CL_ADDRESS_NONE,
|
|
|
|
CL_ADDRESS_CLAMP_TO_EDGE,
|
|
|
|
CL_ADDRESS_CLAMP,
|
|
|
|
CL_ADDRESS_REPEAT,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(SamplerSetArg,
|
|
|
|
AddressingModeTest,
|
|
|
|
::testing::ValuesIn(addressingModeCases));
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_F(SamplerSetArgTest, GivenMipmapsWhenSettingKernelArgSamplerThenLodAreCorrect) {
|
2018-04-10 23:36:34 +08:00
|
|
|
typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE;
|
|
|
|
|
|
|
|
FixedU4D8 minLod = 2.0f;
|
|
|
|
FixedU4D8 maxLod = 3.0f;
|
|
|
|
|
|
|
|
sampler = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_NONE,
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
CL_FILTER_LINEAR,
|
|
|
|
minLod.asFloat(), maxLod.asFloat(),
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
cl_sampler samplerObj = sampler;
|
|
|
|
|
|
|
|
retVal = pKernel->setArg(
|
|
|
|
0,
|
|
|
|
sizeof(samplerObj),
|
|
|
|
&samplerObj);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto samplerState = reinterpret_cast<const SAMPLER_STATE *>(
|
2020-12-08 20:11:40 +08:00
|
|
|
ptrOffset(pKernel->getDynamicStateHeap(rootDeviceIndex),
|
2018-04-10 23:36:34 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap));
|
|
|
|
|
|
|
|
EXPECT_EQ(FamilyType::SAMPLER_STATE::MIP_MODE_FILTER_LINEAR, samplerState->getMipModeFilter());
|
|
|
|
EXPECT_EQ(minLod.getRawAccess(), samplerState->getMinLod());
|
|
|
|
EXPECT_EQ(maxLod.getRawAccess(), samplerState->getMaxLod());
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
struct FilterModeTest
|
|
|
|
: public SamplerSetArgFixture,
|
|
|
|
public ::testing::TestWithParam<uint32_t /*cl_filter_mode*/> {
|
|
|
|
void SetUp() override {
|
|
|
|
SamplerSetArgFixture::SetUp();
|
|
|
|
}
|
|
|
|
void TearDown() override {
|
|
|
|
SamplerSetArgFixture::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-22 18:47:56 +08:00
|
|
|
HWTEST_P(FilterModeTest, WhenSettingKernelArgSamplerThenFiltersAreCorrect) {
|
2017-12-21 07:45:38 +08:00
|
|
|
typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE;
|
|
|
|
auto filterMode = GetParam();
|
|
|
|
sampler = Sampler::create(
|
|
|
|
context,
|
|
|
|
CL_TRUE,
|
|
|
|
CL_ADDRESS_MIRRORED_REPEAT,
|
|
|
|
filterMode,
|
|
|
|
retVal);
|
|
|
|
|
|
|
|
auto samplerState = reinterpret_cast<const SAMPLER_STATE *>(
|
2020-12-08 20:11:40 +08:00
|
|
|
ptrOffset(pKernel->getDynamicStateHeap(rootDeviceIndex),
|
2017-12-21 07:45:38 +08:00
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap));
|
|
|
|
|
2021-02-05 09:58:42 +08:00
|
|
|
sampler->setArg(const_cast<SAMPLER_STATE *>(samplerState), *defaultHwInfo);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
if (CL_FILTER_NEAREST == filterMode) {
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::MIN_MODE_FILTER_NEAREST, samplerState->getMinModeFilter());
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::MAG_MODE_FILTER_NEAREST, samplerState->getMagModeFilter());
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::MIP_MODE_FILTER_NEAREST, samplerState->getMipModeFilter());
|
|
|
|
EXPECT_FALSE(samplerState->getUAddressMinFilterRoundingEnable());
|
|
|
|
EXPECT_FALSE(samplerState->getUAddressMagFilterRoundingEnable());
|
|
|
|
EXPECT_FALSE(samplerState->getVAddressMinFilterRoundingEnable());
|
|
|
|
EXPECT_FALSE(samplerState->getVAddressMagFilterRoundingEnable());
|
|
|
|
EXPECT_FALSE(samplerState->getRAddressMagFilterRoundingEnable());
|
|
|
|
EXPECT_FALSE(samplerState->getRAddressMinFilterRoundingEnable());
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::MIN_MODE_FILTER_LINEAR, samplerState->getMinModeFilter());
|
|
|
|
EXPECT_EQ(SAMPLER_STATE::MAG_MODE_FILTER_LINEAR, samplerState->getMagModeFilter());
|
2018-04-10 23:36:34 +08:00
|
|
|
EXPECT_EQ(SAMPLER_STATE::MIP_MODE_FILTER_NEAREST, samplerState->getMipModeFilter());
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_TRUE(samplerState->getUAddressMinFilterRoundingEnable());
|
|
|
|
EXPECT_TRUE(samplerState->getUAddressMagFilterRoundingEnable());
|
|
|
|
EXPECT_TRUE(samplerState->getVAddressMinFilterRoundingEnable());
|
|
|
|
EXPECT_TRUE(samplerState->getVAddressMagFilterRoundingEnable());
|
|
|
|
EXPECT_TRUE(samplerState->getRAddressMagFilterRoundingEnable());
|
|
|
|
EXPECT_TRUE(samplerState->getRAddressMinFilterRoundingEnable());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_filter_mode filterModeCase[] = {
|
|
|
|
CL_FILTER_NEAREST,
|
|
|
|
CL_FILTER_LINEAR};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(SamplerSetArg,
|
|
|
|
FilterModeTest,
|
|
|
|
::testing::ValuesIn(filterModeCase));
|