From 159404f38e22115ac36dee7a9ddb985d55422d59 Mon Sep 17 00:00:00 2001 From: Maciej Plewka Date: Mon, 17 May 2021 10:08:54 +0000 Subject: [PATCH] Revert "Program border color once per dsh" Signed-off-by: Maciej Plewka --- .../command_queue/command_queue_tests.cpp | 34 ------- .../hardware_commands_helper_tests.cpp | 6 +- .../source/command_container/cmdcontainer.cpp | 1 - .../command_container/command_encoder.inl | 29 +++--- .../command_stream_receiver.cpp | 2 - .../command_stream_receiver_hw_gen11.cpp | 1 - shared/source/gen11/hw_cmds_base.h | 1 - .../command_stream_receiver_hw_gen12lp.cpp | 1 - shared/source/gen12lp/hw_cmds_base.h | 1 - .../gen8/command_stream_receiver_hw_gen8.cpp | 1 - shared/source/gen8/hw_cmds_base.h | 1 - .../gen9/command_stream_receiver_hw_gen9.cpp | 1 - shared/source/gen9/hw_cmds_base.h | 1 - .../source/helpers/bindless_heaps_helper.cpp | 14 +-- shared/source/helpers/bindless_heaps_helper.h | 5 +- shared/source/indirect_heap/indirect_heap.h | 17 ---- .../helpers/bindless_heaps_helper_tests.cpp | 18 ++-- .../command_container_tests.cpp | 27 ------ .../unit_test/encoders/test_encode_states.cpp | 89 ++++++++++++++++--- 19 files changed, 117 insertions(+), 133 deletions(-) diff --git a/opencl/test/unit_test/command_queue/command_queue_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_tests.cpp index fdaf100a75..be583a2b7d 100644 --- a/opencl/test/unit_test/command_queue/command_queue_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_tests.cpp @@ -571,19 +571,6 @@ TEST_P(CommandQueueIndirectHeapTest, WhenGettingIndirectHeapWithNewSizeThenMaxAv } } -TEST_P(CommandQueueIndirectHeapTest, WhenGettingIndirectHeapWithNewSizeThenBorderColorOffsetIsSetToMaxUint) { - const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; - MockCommandQueue cmdQ(context.get(), pClDevice, props); - - auto &indirectHeapInitial = cmdQ.getIndirectHeap(this->GetParam(), 10); - indirectHeapInitial.setBorderColor(nullptr, 0); - EXPECT_NE(indirectHeapInitial.getBorderColorOffset(), std::numeric_limits::max()); - size_t requiredSize = indirectHeapInitial.getMaxAvailableSpace() + 42; - - const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), requiredSize); - EXPECT_EQ(indirectHeap.getBorderColorOffset(), std::numeric_limits::max()); -} - TEST_P(CommandQueueIndirectHeapTest, WhenGettingIndirectHeapThenSizeIsAlignedToCacheLine) { const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; MockCommandQueue cmdQ(context.get(), pClDevice, props); @@ -720,27 +707,6 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndir EXPECT_EQ(0u, indirectHeap.getMaxAvailableSpace()); } -TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndirectHeapIsReleasedThenBorderColorOffsetResetWasCalled) { - const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; - MockCommandQueue cmdQ(context.get(), pClDevice, props); - - EXPECT_TRUE(pDevice->getDefaultEngine().commandStreamReceiver->getAllocationsForReuse().peekIsEmpty()); - - const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100); - auto heapSize = indirectHeap.getMaxAvailableSpace(); - - EXPECT_NE(0u, heapSize); - - auto graphicsAllocation = indirectHeap.getGraphicsAllocation(); - EXPECT_NE(nullptr, graphicsAllocation); - - auto &csr = pDevice->getUltCommandStreamReceiver(); - csr.indirectHeap[this->GetParam()]->setBorderColor(nullptr, 0); - EXPECT_NE(csr.indirectHeap[this->GetParam()]->getBorderColorOffset(), std::numeric_limits::max()); - cmdQ.releaseIndirectHeap(this->GetParam()); - EXPECT_EQ(csr.indirectHeap[this->GetParam()]->getBorderColorOffset(), std::numeric_limits::max()); -} - TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocatedWhenIndirectHeapIsReleasedThenIndirectHeapAllocationStaysNull) { const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; MockCommandQueue cmdQ(context.get(), pClDevice, props); diff --git a/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp b/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp index 2376214711..2432b26c74 100644 --- a/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp +++ b/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp @@ -946,7 +946,6 @@ HWCMDTEST_F(IGFX_GEN8_CORE, HardwareCommandsTest, GivenKernelWithSamplersWhenInd typedef typename FamilyType::BINDING_TABLE_STATE BINDING_TABLE_STATE; typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE; - typedef typename FamilyType::SAMPLER_BORDER_COLOR_STATE SAMPLER_BORDER_COLOR_STATE; using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; using GPGPU_WALKER = typename FamilyType::GPGPU_WALKER; @@ -961,7 +960,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, HardwareCommandsTest, GivenKernelWithSamplersWhenInd auto &ioh = cmdQ.getIndirectHeap(IndirectHeap::INDIRECT_OBJECT, 8192); auto &ssh = cmdQ.getIndirectHeap(IndirectHeap::SURFACE_STATE, 8192); - const uint32_t samplerTableOffset = static_cast(alignUp(sizeof(SAMPLER_BORDER_COLOR_STATE), INTERFACE_DESCRIPTOR_DATA::SAMPLERSTATEPOINTER_ALIGN_SIZE)); + const uint32_t samplerTableOffset = 64; const uint32_t samplerStateSize = sizeof(SAMPLER_STATE) * 2; mockKernelWithInternal->kernelInfo.setSamplerTable(0, 2, static_cast(samplerTableOffset)); @@ -1008,8 +1007,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, HardwareCommandsTest, GivenKernelWithSamplersWhenInd true, *pDevice); - auto expectedBorderColor = FamilyType::cmdInitBorderColor; - bool isMemorySame = memcmp(borderColorPointer, &expectedBorderColor, sizeof(SAMPLER_BORDER_COLOR_STATE)) == 0; + bool isMemorySame = memcmp(borderColorPointer, mockDsh, samplerTableOffset) == 0; EXPECT_TRUE(isMemorySame); SAMPLER_STATE *pSamplerStatesCopied = reinterpret_cast(borderColorPointer + samplerTableOffset); diff --git a/shared/source/command_container/cmdcontainer.cpp b/shared/source/command_container/cmdcontainer.cpp index d53175b2f2..47c7129b3a 100644 --- a/shared/source/command_container/cmdcontainer.cpp +++ b/shared/source/command_container/cmdcontainer.cpp @@ -203,7 +203,6 @@ IndirectHeap *CommandContainer::getHeapWithRequiredSizeAndAlignment(HeapType hea getResidencyContainer().push_back(newAlloc); getDeallocationContainer().push_back(oldAlloc); setIndirectHeapAllocation(heapType, newAlloc); - indirectHeap->resetBorderColorOffset(); if (oldBase != newBase) { setHeapDirty(heapType); } diff --git a/shared/source/command_container/command_encoder.inl b/shared/source/command_container/command_encoder.inl index 9d17127b18..471c42699a 100644 --- a/shared/source/command_container/command_encoder.inl +++ b/shared/source/command_container/command_encoder.inl @@ -36,6 +36,7 @@ uint32_t EncodeStates::copySamplerState(IndirectHeap *dsh, const void *fnDynamicStateHeap, BindlessHeapsHelper *bindlessHeapHelper) { auto sizeSamplerState = sizeof(SAMPLER_STATE) * samplerCount; + auto borderColorSize = samplerStateOffset - borderColorOffset; SAMPLER_STATE *dstSamplerState = nullptr; uint32_t samplerStateOffsetInDsh = 0; @@ -43,21 +44,27 @@ uint32_t EncodeStates::copySamplerState(IndirectHeap *dsh, dsh->align(EncodeStates::alignIndirectStatePointer); uint32_t borderColorOffsetInDsh = 0; if (!ApiSpecificConfig::getBindlessConfiguration()) { - borderColorOffsetInDsh = dsh->getBorderColorOffset(); - if (borderColorOffsetInDsh == std::numeric_limits::max()) { - auto borderColor = Family::cmdInitBorderColor; - dsh->setBorderColor(&borderColor, sizeof(borderColor)); - borderColorOffsetInDsh = dsh->getBorderColorOffset(); - } + borderColorOffsetInDsh = static_cast(dsh->getUsed()); + auto borderColor = dsh->getSpace(borderColorSize); + + memcpy_s(borderColor, borderColorSize, ptrOffset(fnDynamicStateHeap, borderColorOffset), + borderColorSize); + dsh->align(INTERFACE_DESCRIPTOR_DATA::SAMPLERSTATEPOINTER_ALIGN_SIZE); samplerStateOffsetInDsh = static_cast(dsh->getUsed()); + dstSamplerState = reinterpret_cast(dsh->getSpace(sizeSamplerState)); } else { - borderColorOffsetInDsh = bindlessHeapHelper->getBorderColorOffset(); - if (borderColorOffsetInDsh == std::numeric_limits::max()) { - auto borderColor = Family::cmdInitBorderColor; - bindlessHeapHelper->setBorderColor(&borderColor, sizeof(borderColor)); - borderColorOffsetInDsh = bindlessHeapHelper->getBorderColorOffset(); + auto borderColor = reinterpret_cast(ptrOffset(fnDynamicStateHeap, borderColorOffset)); + if (borderColor->getBorderColorRed() != 0.0f || + borderColor->getBorderColorGreen() != 0.0f || + borderColor->getBorderColorBlue() != 0.0f || + (borderColor->getBorderColorAlpha() != 0.0f && borderColor->getBorderColorAlpha() != 1.0f)) { + UNRECOVERABLE_IF(true); + } else if (borderColor->getBorderColorAlpha() == 0.0f) { + borderColorOffsetInDsh = bindlessHeapHelper->getDefaultBorderColorOffset(); + } else { + borderColorOffsetInDsh = bindlessHeapHelper->getAlphaBorderColorOffset(); } dsh->align(INTERFACE_DESCRIPTOR_DATA::SAMPLERSTATEPOINTER_ALIGN_SIZE); auto samplerStateInDsh = bindlessHeapHelper->allocateSSInHeap(sizeSamplerState, nullptr, BindlessHeapsHelper::BindlesHeapType::GLOBAL_DSH); diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index c12e3dc7bf..a00cf163a7 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -424,7 +424,6 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType, if (indirectHeap) { indirectHeap->replaceBuffer(heapMemory->getUnderlyingBuffer(), finalHeapSize); indirectHeap->replaceGraphicsAllocation(heapMemory); - indirectHeap->resetBorderColorOffset(); } else { indirectHeap = new IndirectHeap(heapMemory, requireInternalHeap); indirectHeap->overrideMaxSize(finalHeapSize); @@ -442,7 +441,6 @@ void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) { internalAllocationStorage->storeAllocation(std::unique_ptr(heapMemory), REUSABLE_ALLOCATION); heap->replaceBuffer(nullptr, 0); heap->replaceGraphicsAllocation(nullptr); - heap->resetBorderColorOffset(); } } diff --git a/shared/source/gen11/command_stream_receiver_hw_gen11.cpp b/shared/source/gen11/command_stream_receiver_hw_gen11.cpp index 500adf3bab..febec92a4d 100644 --- a/shared/source/gen11/command_stream_receiver_hw_gen11.cpp +++ b/shared/source/gen11/command_stream_receiver_hw_gen11.cpp @@ -189,5 +189,4 @@ const Family::MI_USER_INTERRUPT Family::cmdInitUserInterrupt = Family::MI_USER_I const Family::XY_SRC_COPY_BLT Family::cmdInitXyCopyBlt = Family::XY_SRC_COPY_BLT::sInit(); const Family::MI_FLUSH_DW Family::cmdInitMiFlushDw = Family::MI_FLUSH_DW::sInit(); const Family::XY_COLOR_BLT Family::cmdInitXyColorBlt = Family::XY_COLOR_BLT::sInit(); -const Family::SAMPLER_BORDER_COLOR_STATE Family::cmdInitBorderColor = Family::SAMPLER_BORDER_COLOR_STATE::sInit(); } // namespace NEO diff --git a/shared/source/gen11/hw_cmds_base.h b/shared/source/gen11/hw_cmds_base.h index 52e4d4eca0..26a01401a1 100644 --- a/shared/source/gen11/hw_cmds_base.h +++ b/shared/source/gen11/hw_cmds_base.h @@ -84,7 +84,6 @@ struct ICLFamily : public GEN11 { static const XY_SRC_COPY_BLT cmdInitXyCopyBlt; static const MI_FLUSH_DW cmdInitMiFlushDw; static const XY_COLOR_BLT cmdInitXyColorBlt; - static const SAMPLER_BORDER_COLOR_STATE cmdInitBorderColor; static constexpr bool supportsCmdSet(GFXCORE_FAMILY cmdSetBaseFamily) { return cmdSetBaseFamily == IGFX_GEN8_CORE; diff --git a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp index 057c56b16e..5d8d57ba17 100644 --- a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp +++ b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp @@ -194,5 +194,4 @@ const Family::L3_CONTROL Family::cmdInitL3ControlWithPostSync = Family::L3_CONTR const Family::XY_COPY_BLT Family::cmdInitXyCopyBlt = Family::XY_COPY_BLT::sInit(); const Family::MI_FLUSH_DW Family::cmdInitMiFlushDw = Family::MI_FLUSH_DW::sInit(); const Family::XY_FAST_COLOR_BLT Family::cmdInitXyColorBlt = Family::XY_FAST_COLOR_BLT::sInit(); -const Family::SAMPLER_BORDER_COLOR_STATE Family::cmdInitBorderColor = Family::SAMPLER_BORDER_COLOR_STATE::sInit(); } // namespace NEO diff --git a/shared/source/gen12lp/hw_cmds_base.h b/shared/source/gen12lp/hw_cmds_base.h index 2b80dbabc6..335dac52bf 100644 --- a/shared/source/gen12lp/hw_cmds_base.h +++ b/shared/source/gen12lp/hw_cmds_base.h @@ -90,7 +90,6 @@ struct TGLLPFamily : public GEN12LP { static const XY_COPY_BLT cmdInitXyCopyBlt; static const MI_FLUSH_DW cmdInitMiFlushDw; static const XY_FAST_COLOR_BLT cmdInitXyColorBlt; - static const SAMPLER_BORDER_COLOR_STATE cmdInitBorderColor; static constexpr bool supportsCmdSet(GFXCORE_FAMILY cmdSetBaseFamily) { return cmdSetBaseFamily == IGFX_GEN8_CORE; diff --git a/shared/source/gen8/command_stream_receiver_hw_gen8.cpp b/shared/source/gen8/command_stream_receiver_hw_gen8.cpp index 8575342b65..e8a4a2d241 100644 --- a/shared/source/gen8/command_stream_receiver_hw_gen8.cpp +++ b/shared/source/gen8/command_stream_receiver_hw_gen8.cpp @@ -68,5 +68,4 @@ const Family::MI_USER_INTERRUPT Family::cmdInitUserInterrupt = Family::MI_USER_I const Family::XY_SRC_COPY_BLT Family::cmdInitXyCopyBlt = Family::XY_SRC_COPY_BLT::sInit(); const Family::MI_FLUSH_DW Family::cmdInitMiFlushDw = Family::MI_FLUSH_DW::sInit(); const Family::XY_COLOR_BLT Family::cmdInitXyColorBlt = Family::XY_COLOR_BLT::sInit(); -const Family::SAMPLER_BORDER_COLOR_STATE Family::cmdInitBorderColor = Family::SAMPLER_BORDER_COLOR_STATE::sInit(); } // namespace NEO diff --git a/shared/source/gen8/hw_cmds_base.h b/shared/source/gen8/hw_cmds_base.h index a80fb51742..ab6481ce42 100644 --- a/shared/source/gen8/hw_cmds_base.h +++ b/shared/source/gen8/hw_cmds_base.h @@ -85,7 +85,6 @@ struct BDWFamily : public GEN8 { static const XY_SRC_COPY_BLT cmdInitXyCopyBlt; static const MI_FLUSH_DW cmdInitMiFlushDw; static const XY_COLOR_BLT cmdInitXyColorBlt; - static const SAMPLER_BORDER_COLOR_STATE cmdInitBorderColor; static constexpr bool supportsCmdSet(GFXCORE_FAMILY cmdSetBaseFamily) { return cmdSetBaseFamily == IGFX_GEN8_CORE; diff --git a/shared/source/gen9/command_stream_receiver_hw_gen9.cpp b/shared/source/gen9/command_stream_receiver_hw_gen9.cpp index 04930c5dd6..9f2266247d 100644 --- a/shared/source/gen9/command_stream_receiver_hw_gen9.cpp +++ b/shared/source/gen9/command_stream_receiver_hw_gen9.cpp @@ -63,5 +63,4 @@ const Family::MI_USER_INTERRUPT Family::cmdInitUserInterrupt = Family::MI_USER_I const Family::XY_SRC_COPY_BLT Family::cmdInitXyCopyBlt = Family::XY_SRC_COPY_BLT::sInit(); const Family::MI_FLUSH_DW Family::cmdInitMiFlushDw = Family::MI_FLUSH_DW::sInit(); const Family::XY_COLOR_BLT Family::cmdInitXyColorBlt = Family::XY_COLOR_BLT::sInit(); -const Family::SAMPLER_BORDER_COLOR_STATE Family::cmdInitBorderColor = Family::SAMPLER_BORDER_COLOR_STATE::sInit(); } // namespace NEO diff --git a/shared/source/gen9/hw_cmds_base.h b/shared/source/gen9/hw_cmds_base.h index 84d373b89f..c80cb8566c 100644 --- a/shared/source/gen9/hw_cmds_base.h +++ b/shared/source/gen9/hw_cmds_base.h @@ -86,7 +86,6 @@ struct SKLFamily : public GEN9 { static const XY_SRC_COPY_BLT cmdInitXyCopyBlt; static const MI_FLUSH_DW cmdInitMiFlushDw; static const XY_COLOR_BLT cmdInitXyColorBlt; - static const SAMPLER_BORDER_COLOR_STATE cmdInitBorderColor; static constexpr bool supportsCmdSet(GFXCORE_FAMILY cmdSetBaseFamily) { return cmdSetBaseFamily == IGFX_GEN8_CORE; diff --git a/shared/source/helpers/bindless_heaps_helper.cpp b/shared/source/helpers/bindless_heaps_helper.cpp index d90a4db14d..187e30f014 100644 --- a/shared/source/helpers/bindless_heaps_helper.cpp +++ b/shared/source/helpers/bindless_heaps_helper.cpp @@ -14,6 +14,7 @@ namespace NEO { constexpr size_t globalSshAllocationSize = 4 * MemoryConstants::pageSize64k; +constexpr size_t borderColorAlphaOffset = alignUp(4 * sizeof(float), MemoryConstants::cacheLineSize); using BindlesHeapType = BindlessHeapsHelper::BindlesHeapType; BindlessHeapsHelper::BindlessHeapsHelper(MemoryManager *memManager, bool isMultiOsContextCapable, const uint32_t rootDeviceIndex) : memManager(memManager), isMultiOsContextCapable(isMultiOsContextCapable), rootDeviceIndex(rootDeviceIndex) { @@ -27,6 +28,10 @@ BindlessHeapsHelper::BindlessHeapsHelper(MemoryManager *memManager, bool isMulti borderColorStates = getHeapAllocation(MemoryConstants::pageSize, MemoryConstants::pageSize, true); UNRECOVERABLE_IF(borderColorStates == nullptr); + float borderColorDefault[4] = {0, 0, 0, 0}; + memcpy_s(borderColorStates->getUnderlyingBuffer(), sizeof(borderColorDefault), borderColorDefault, sizeof(borderColorDefault)); + float borderColorAlpha[4] = {0, 0, 0, 1.0}; + memcpy_s(ptrOffset(borderColorStates->getUnderlyingBuffer(), borderColorAlphaOffset), sizeof(borderColorAlpha), borderColorAlpha, sizeof(borderColorDefault)); } BindlessHeapsHelper::~BindlessHeapsHelper() { @@ -89,12 +94,11 @@ uint64_t BindlessHeapsHelper::getGlobalHeapsBase() { return surfaceStateHeaps[BindlesHeapType::GLOBAL_SSH]->getGraphicsAllocation()->getGpuBaseAddress(); } -uint32_t BindlessHeapsHelper::getBorderColorOffset() { - return borderColorOffset; +uint32_t BindlessHeapsHelper::getDefaultBorderColorOffset() { + return static_cast(borderColorStates->getGpuAddress() - borderColorStates->getGpuBaseAddress()); } -void BindlessHeapsHelper::setBorderColor(void *borderColor, size_t size) { - borderColorOffset = static_cast(borderColorStates->getGpuAddress() - borderColorStates->getGpuBaseAddress()); - memcpy_s(borderColorStates->getUnderlyingBuffer(), borderColorStates->getUnderlyingBufferSize(), borderColor, size); +uint32_t BindlessHeapsHelper::getAlphaBorderColorOffset() { + return getDefaultBorderColorOffset() + borderColorAlphaOffset; } IndirectHeap *BindlessHeapsHelper::getHeap(BindlesHeapType heapType) { diff --git a/shared/source/helpers/bindless_heaps_helper.h b/shared/source/helpers/bindless_heaps_helper.h index 4b02602d5e..f171d8ae11 100644 --- a/shared/source/helpers/bindless_heaps_helper.h +++ b/shared/source/helpers/bindless_heaps_helper.h @@ -44,8 +44,8 @@ class BindlessHeapsHelper { SurfaceStateInHeapInfo allocateSSInHeap(size_t ssSize, GraphicsAllocation *surfaceAllocation, BindlesHeapType heapType); uint64_t getGlobalHeapsBase(); void *getSpaceInHeap(size_t ssSize, BindlesHeapType heapType); - uint32_t getBorderColorOffset(); - void setBorderColor(void *borderColor, size_t size); + uint32_t getDefaultBorderColorOffset(); + uint32_t getAlphaBorderColorOffset(); IndirectHeap *getHeap(BindlesHeapType heapType); void placeSSAllocationInReuseVectorOnFreeMemory(GraphicsAllocation *gfxAllocation); @@ -54,7 +54,6 @@ class BindlessHeapsHelper { MemoryManager *memManager = nullptr; bool isMultiOsContextCapable = false; const uint32_t rootDeviceIndex; - uint32_t borderColorOffset = std::numeric_limits::max(); std::unique_ptr surfaceStateHeaps[BindlesHeapType::NUM_HEAP_TYPES]; GraphicsAllocation *borderColorStates; std::vector ssHeapsAllocations; diff --git a/shared/source/indirect_heap/indirect_heap.h b/shared/source/indirect_heap/indirect_heap.h index bcec9b8f65..ca1c8217fa 100644 --- a/shared/source/indirect_heap/indirect_heap.h +++ b/shared/source/indirect_heap/indirect_heap.h @@ -11,7 +11,6 @@ #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/constants.h" #include "shared/source/helpers/ptr_math.h" -#include "shared/source/helpers/string.h" #include "shared/source/memory_manager/graphics_allocation.h" namespace NEO { @@ -45,13 +44,9 @@ class IndirectHeap : public LinearStream { uint64_t getHeapGpuStartOffset() const; uint64_t getHeapGpuBase() const; uint32_t getHeapSizeInPages() const; - uint32_t getBorderColorOffset() const; - void setBorderColor(void *borderColor, size_t size); - void resetBorderColorOffset(); protected: bool canBeUtilizedAs4GbHeap = false; - uint32_t borderColorOffset = std::numeric_limits::max(); }; inline void IndirectHeap::align(size_t alignment) { @@ -82,16 +77,4 @@ inline uint64_t IndirectHeap::getHeapGpuBase() const { return this->graphicsAllocation->getGpuAddress(); } } - -inline uint32_t IndirectHeap::getBorderColorOffset() const { - return borderColorOffset; -} -inline void IndirectHeap::setBorderColor(void *borderColor, size_t size) { - borderColorOffset = static_cast(getUsed()); - auto ptr = getSpace(size); - memcpy_s(ptr, size, borderColor, size); -} -inline void IndirectHeap::resetBorderColorOffset() { - borderColorOffset = std::numeric_limits::max(); -} } // namespace NEO diff --git a/shared/test/common/helpers/bindless_heaps_helper_tests.cpp b/shared/test/common/helpers/bindless_heaps_helper_tests.cpp index e23e08da28..a3db1629e1 100644 --- a/shared/test/common/helpers/bindless_heaps_helper_tests.cpp +++ b/shared/test/common/helpers/bindless_heaps_helper_tests.cpp @@ -110,17 +110,17 @@ TEST_F(BindlessHeapsHelperTests, givenBindlessHeapHelperWhenCreatedThenAllocatio } } -TEST_F(BindlessHeapsHelperTests, givenBindlessHeapHelperWhenGetDefaultBorderColorOffsetWithoutSettingThenMaxUintReturned) { - auto bindlessHeapHelper = std::make_unique(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); - auto expectedOffset = std::numeric_limits::max(); - EXPECT_EQ(bindlessHeapHelper->getBorderColorOffset(), expectedOffset); -} - -TEST_F(BindlessHeapsHelperTests, givenBindlessHeapHelperWhenGetDefaultBorderColorOffsetAfterSettingThenCorrectOffsetReturned) { +TEST_F(BindlessHeapsHelperTests, givenBindlessHeapHelperWhenGetDefaultBorderColorOffsetCalledThenCorrectOffsetReturned) { auto bindlessHeapHelper = std::make_unique(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); auto expectedOffset = bindlessHeapHelper->borderColorStates->getGpuAddress() - bindlessHeapHelper->borderColorStates->getGpuBaseAddress(); - bindlessHeapHelper->setBorderColor(nullptr, 0); - EXPECT_EQ(bindlessHeapHelper->getBorderColorOffset(), expectedOffset); + EXPECT_EQ(bindlessHeapHelper->getDefaultBorderColorOffset(), expectedOffset); +} + +TEST_F(BindlessHeapsHelperTests, givenBindlessHeapHelperWhenGetAlphaBorderColorOffsetCalledThenCorrectOffsetReturned) { + auto borderColorSize = 0x40; + auto bindlessHeapHelper = std::make_unique(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); + auto expectedOffset = bindlessHeapHelper->borderColorStates->getGpuAddress() - bindlessHeapHelper->borderColorStates->getGpuBaseAddress() + borderColorSize; + EXPECT_EQ(bindlessHeapHelper->getAlphaBorderColorOffset(), expectedOffset); } TEST_F(BindlessHeapsHelperTests, givenBindlessHeapHelperWhenAllocateSsInSpecialHeapThenOffsetLessThanFrontWindowSize) { diff --git a/shared/test/unit_test/command_container/command_container_tests.cpp b/shared/test/unit_test/command_container/command_container_tests.cpp index 0b9100129c..db6d196486 100644 --- a/shared/test/unit_test/command_container/command_container_tests.cpp +++ b/shared/test/unit_test/command_container/command_container_tests.cpp @@ -367,33 +367,6 @@ TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenGetHeapWithRequiredSizeAndAl cmdContainer->getDeallocationContainer().clear(); } -TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenGetHeapWithRequiredSizeAndAlignmentCalledThenBorderColorOffestHasBeenReset) { - std::unique_ptr cmdContainer(new CommandContainer); - cmdContainer->initialize(pDevice); - cmdContainer->setDirtyStateForAllHeaps(false); - HeapType types[] = {HeapType::SURFACE_STATE, - HeapType::DYNAMIC_STATE}; - - for (auto type : types) { - auto heap = cmdContainer->getIndirectHeap(type); - heap->setBorderColor(nullptr, 0); - EXPECT_NE(heap->getBorderColorOffset(), std::numeric_limits::max()); - const size_t sizeRequested = 32; - const size_t alignment = 32; - size_t availableSize = heap->getAvailableSpace(); - - heap->getSpace(availableSize - sizeRequested / 2); - - EXPECT_LT(heap->getAvailableSpace(), sizeRequested + alignment); - auto heapRequested = cmdContainer->getHeapWithRequiredSizeAndAlignment(type, sizeRequested, alignment); - EXPECT_EQ(heapRequested->getBorderColorOffset(), std::numeric_limits::max()); - } - for (auto deallocation : cmdContainer->getDeallocationContainer()) { - cmdContainer->getDevice()->getMemoryManager()->freeGraphicsMemory(deallocation); - } - cmdContainer->getDeallocationContainer().clear(); -} - TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenCreatedAlocationHaveDifferentBaseThenHeapIsDirty) { std::unique_ptr cmdContainer(new CommandContainer); cmdContainer->initialize(pDevice); diff --git a/shared/test/unit_test/encoders/test_encode_states.cpp b/shared/test/unit_test/encoders/test_encode_states.cpp index c8fd876273..66aee1abad 100644 --- a/shared/test/unit_test/encoders/test_encode_states.cpp +++ b/shared/test/unit_test/encoders/test_encode_states.cpp @@ -33,7 +33,7 @@ HWTEST_F(CommandEncodeStatesTest, GivenCommandStreamWhenEncodeCopySamplerStateTh } using BindlessCommandEncodeStatesTest = Test; -HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenCopySamplerStateThenBorderSetCorrectly) { +HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenBorderColorWithoutAlphaThenBorderColorPtrReturned) { using SAMPLER_BORDER_COLOR_STATE = typename FamilyType::SAMPLER_BORDER_COLOR_STATE; DebugManagerStateRestore restorer; DebugManager.flags.UseBindlessMode.set(1); @@ -41,34 +41,99 @@ HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenCopySamplerSta uint32_t numSamplers = 1; pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->createBindlessHeapsHelper(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); - uint32_t borderColorSize = 0; + uint32_t borderColorSize = 0x40; SAMPLER_BORDER_COLOR_STATE samplerState; samplerState.init(); auto dsh = pDevice->getBindlessHeapsHelper()->getHeap(BindlessHeapsHelper::BindlesHeapType::GLOBAL_DSH); EncodeStates::copySamplerState(dsh, borderColorSize, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()); - auto expectedValue = pDevice->getBindlessHeapsHelper()->getBorderColorOffset(); + auto expectedValue = pDevice->getBindlessHeapsHelper()->getDefaultBorderColorOffset(); auto pSmplr = reinterpret_cast(dsh->getGraphicsAllocation()->getUnderlyingBuffer()); EXPECT_EQ(pSmplr->getIndirectStatePointer(), expectedValue); } -HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenCopySamplerStateCalledTwiceThenTheSameIndirectPointerIsSet) { - using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE; - using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; +HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenBorderColorWithAlphaThenBorderColorPtrOffseted) { + using SAMPLER_BORDER_COLOR_STATE = typename FamilyType::SAMPLER_BORDER_COLOR_STATE; DebugManagerStateRestore restorer; DebugManager.flags.UseBindlessMode.set(1); + using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE; uint32_t numSamplers = 1; pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->createBindlessHeapsHelper(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); - SAMPLER_STATE samplerState; + uint32_t borderColorSize = 0x40; + SAMPLER_BORDER_COLOR_STATE samplerState; samplerState.init(); + samplerState.setBorderColorAlpha(1.0); auto dsh = pDevice->getBindlessHeapsHelper()->getHeap(BindlessHeapsHelper::BindlesHeapType::GLOBAL_DSH); - EncodeStates::copySamplerState(dsh, 0, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()); - EncodeStates::copySamplerState(dsh, 0, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()); + EncodeStates::copySamplerState(dsh, borderColorSize, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()); + auto expectedValue = pDevice->getBindlessHeapsHelper()->getAlphaBorderColorOffset(); - auto pSmplr1 = reinterpret_cast(dsh->getGraphicsAllocation()->getUnderlyingBuffer()); - auto pSmplr2 = reinterpret_cast(ptrOffset(dsh->getGraphicsAllocation()->getUnderlyingBuffer(), static_cast(alignUp(sizeof(samplerState), EncodeStates::alignIndirectStatePointer)))); - EXPECT_EQ(pSmplr1->getIndirectStatePointer(), pSmplr2->getIndirectStatePointer()); + auto pSmplr = reinterpret_cast(dsh->getGraphicsAllocation()->getUnderlyingBuffer()); + EXPECT_EQ(pSmplr->getIndirectStatePointer(), expectedValue); +} + +HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenBorderColorsRedChanelIsNotZeroThenExceptionThrown) { + using SAMPLER_BORDER_COLOR_STATE = typename FamilyType::SAMPLER_BORDER_COLOR_STATE; + DebugManagerStateRestore restorer; + DebugManager.flags.UseBindlessMode.set(1); + using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE; + uint32_t numSamplers = 1; + pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->createBindlessHeapsHelper(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); + + uint32_t borderColorSize = 0x40; + SAMPLER_BORDER_COLOR_STATE samplerState; + samplerState.init(); + samplerState.setBorderColorRed(0.5); + auto dsh = pDevice->getBindlessHeapsHelper()->getHeap(BindlessHeapsHelper::BindlesHeapType::GLOBAL_DSH); + EXPECT_THROW(EncodeStates::copySamplerState(dsh, borderColorSize, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()), std::exception); +} + +HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenBorderColorsGreenChanelIsNotZeroThenExceptionThrown) { + using SAMPLER_BORDER_COLOR_STATE = typename FamilyType::SAMPLER_BORDER_COLOR_STATE; + DebugManagerStateRestore restorer; + DebugManager.flags.UseBindlessMode.set(1); + using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE; + uint32_t numSamplers = 1; + pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->createBindlessHeapsHelper(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); + + uint32_t borderColorSize = 0x40; + SAMPLER_BORDER_COLOR_STATE samplerState; + samplerState.init(); + samplerState.setBorderColorGreen(0.5); + auto dsh = pDevice->getBindlessHeapsHelper()->getHeap(BindlessHeapsHelper::BindlesHeapType::GLOBAL_DSH); + EXPECT_THROW(EncodeStates::copySamplerState(dsh, borderColorSize, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()), std::exception); +} + +HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenBorderColorsBlueChanelIsNotZeroThenExceptionThrown) { + using SAMPLER_BORDER_COLOR_STATE = typename FamilyType::SAMPLER_BORDER_COLOR_STATE; + DebugManagerStateRestore restorer; + DebugManager.flags.UseBindlessMode.set(1); + using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE; + uint32_t numSamplers = 1; + pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->createBindlessHeapsHelper(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); + + uint32_t borderColorSize = 0x40; + SAMPLER_BORDER_COLOR_STATE samplerState; + samplerState.init(); + samplerState.setBorderColorBlue(0.5); + auto dsh = pDevice->getBindlessHeapsHelper()->getHeap(BindlessHeapsHelper::BindlesHeapType::GLOBAL_DSH); + EXPECT_THROW(EncodeStates::copySamplerState(dsh, borderColorSize, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()), std::exception); +} + +HWTEST_F(BindlessCommandEncodeStatesTest, GivenBindlessEnabledWhenBorderColorsAlphaChanelIsNotZeroOrOneThenExceptionThrown) { + using SAMPLER_BORDER_COLOR_STATE = typename FamilyType::SAMPLER_BORDER_COLOR_STATE; + DebugManagerStateRestore restorer; + DebugManager.flags.UseBindlessMode.set(1); + using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE; + uint32_t numSamplers = 1; + pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->createBindlessHeapsHelper(pDevice->getMemoryManager(), pDevice->getNumAvailableDevices() > 1, pDevice->getRootDeviceIndex()); + + uint32_t borderColorSize = 0x40; + SAMPLER_BORDER_COLOR_STATE samplerState; + samplerState.init(); + samplerState.setBorderColorAlpha(0.5); + auto dsh = pDevice->getBindlessHeapsHelper()->getHeap(BindlessHeapsHelper::BindlesHeapType::GLOBAL_DSH); + EXPECT_THROW(EncodeStates::copySamplerState(dsh, borderColorSize, numSamplers, 0, &samplerState, pDevice->getBindlessHeapsHelper()), std::exception); } HWTEST_F(CommandEncodeStatesTest, givenCreatedSurfaceStateBufferWhenAllocationProvidedThenUseAllocationAsInput) {