fix: correct programming inline samplers with bindless addressing L0

Related-To: NEO-14216
Signed-off-by: Kamil Kopryk <kamil.kopryk@intel.com>
This commit is contained in:
Kamil Kopryk 2025-03-11 23:29:37 +00:00 committed by Compute-Runtime-Automation
parent fa2e3adad3
commit c23f3c0666
2 changed files with 68 additions and 1 deletions

View File

@ -1009,7 +1009,19 @@ void KernelImp::setInlineSamplers() {
auto sampler = std::unique_ptr<L0::Sampler>(L0::Sampler::create(productFamily, device, &samplerDesc));
UNRECOVERABLE_IF(sampler.get() == nullptr);
sampler->copySamplerStateToDSH(dynamicStateHeapData.get(), dynamicStateHeapDataSize, inlineSampler.getSamplerBindfulOffset());
if (NEO::isValidOffset(inlineSampler.bindless)) {
auto samplerStateIndex = inlineSampler.samplerIndex;
auto &gfxCoreHelper = device->getGfxCoreHelper();
auto samplerStateSize = gfxCoreHelper.getSamplerStateSize();
uint32_t offset = inlineSampler.borderColorStateSize;
offset += static_cast<uint32_t>(samplerStateSize) * samplerStateIndex;
sampler->copySamplerStateToDSH(dynamicStateHeapData.get(), dynamicStateHeapDataSize, offset);
} else {
sampler->copySamplerStateToDSH(dynamicStateHeapData.get(), dynamicStateHeapDataSize, inlineSampler.getSamplerBindfulOffset());
}
}
}

View File

@ -513,6 +513,61 @@ HWTEST2_F(KernelTest, GivenInlineSamplersWhenSettingInlineSamplerThenDshIsPatche
EXPECT_EQ(SamplerState::MAG_MODE_FILTER_NEAREST, samplerState->getMagModeFilter());
}
HWTEST2_F(KernelTest, givenTwoInlineSamplersWithBindlessAddressingWhenSettingInlineSamplerThenDshIsPatchedCorrectly, SupportsSampler) {
using SamplerState = typename FamilyType::SAMPLER_STATE;
constexpr auto borderColorStateSize = 64u;
WhiteBox<::L0::KernelImmutableData> kernelImmData = {};
NEO::KernelDescriptor descriptor;
kernelImmData.kernelDescriptor = &descriptor;
descriptor.inlineSamplers.resize(2);
auto &inlineSampler = descriptor.inlineSamplers[0];
inlineSampler.addrMode = NEO::KernelDescriptor::InlineSampler::AddrMode::clampEdge;
inlineSampler.filterMode = NEO::KernelDescriptor::InlineSampler::FilterMode::nearest;
inlineSampler.isNormalized = false;
inlineSampler.bindless = 0x98u;
inlineSampler.samplerIndex = 0u;
ASSERT_TRUE(NEO::isValidOffset(inlineSampler.bindless));
auto &inlineSampler2 = descriptor.inlineSamplers[1];
inlineSampler2.addrMode = NEO::KernelDescriptor::InlineSampler::AddrMode::clampBorder;
inlineSampler2.filterMode = NEO::KernelDescriptor::InlineSampler::FilterMode::linear;
inlineSampler2.isNormalized = false;
inlineSampler2.bindless = 0x90u;
inlineSampler2.samplerIndex = 1u;
ASSERT_TRUE(NEO::isValidOffset(inlineSampler.bindless));
Mock<Module> module(device, nullptr);
Mock<KernelImp> kernel;
kernel.module = &module;
kernel.kernelImmData = &kernelImmData;
kernel.dynamicStateHeapData.reset(new uint8_t[borderColorStateSize + 2 * sizeof(SamplerState)]);
kernel.dynamicStateHeapDataSize = borderColorStateSize + 2 * sizeof(SamplerState);
kernel.setInlineSamplers();
const SamplerState *samplerState = reinterpret_cast<const SamplerState *>(kernel.dynamicStateHeapData.get() + borderColorStateSize);
const SamplerState *samplerState2 = reinterpret_cast<const SamplerState *>(kernel.dynamicStateHeapData.get() + sizeof(SamplerState) + borderColorStateSize);
EXPECT_TRUE(samplerState->getNonNormalizedCoordinateEnable());
EXPECT_EQ(SamplerState::TEXTURE_COORDINATE_MODE_CLAMP, samplerState->getTcxAddressControlMode());
EXPECT_EQ(SamplerState::TEXTURE_COORDINATE_MODE_CLAMP, samplerState->getTcyAddressControlMode());
EXPECT_EQ(SamplerState::TEXTURE_COORDINATE_MODE_CLAMP, samplerState->getTczAddressControlMode());
EXPECT_EQ(SamplerState::MIN_MODE_FILTER_NEAREST, samplerState->getMinModeFilter());
EXPECT_EQ(SamplerState::MAG_MODE_FILTER_NEAREST, samplerState->getMagModeFilter());
EXPECT_TRUE(samplerState2->getNonNormalizedCoordinateEnable());
EXPECT_EQ(SamplerState::TEXTURE_COORDINATE_MODE_CLAMP_BORDER, samplerState2->getTcxAddressControlMode());
EXPECT_EQ(SamplerState::TEXTURE_COORDINATE_MODE_CLAMP_BORDER, samplerState2->getTcyAddressControlMode());
EXPECT_EQ(SamplerState::TEXTURE_COORDINATE_MODE_CLAMP_BORDER, samplerState2->getTczAddressControlMode());
EXPECT_EQ(SamplerState::MIN_MODE_FILTER_LINEAR, samplerState2->getMinModeFilter());
EXPECT_EQ(SamplerState::MAG_MODE_FILTER_LINEAR, samplerState2->getMagModeFilter());
}
using KernelImmutableDataBindlessTest = Test<DeviceFixture>;
HWTEST2_F(KernelImmutableDataBindlessTest, givenGlobalConstBufferAndBindlessExplicitAndImplicitArgsAndNoBindlessHeapsHelperWhenInitializeKernelImmutableDataThenSurfaceStateIsSetAndImplicitArgBindlessOffsetIsPatched, IsAtLeastXeHpgCore) {