11/*
2- * Copyright (C) 2020 Intel Corporation
2+ * Copyright (C) 2020-2021 Intel Corporation
33 *
44 * SPDX-License-Identifier: MIT
55 *
1010#include " shared/source/gmm_helper/gmm_helper.h"
1111#include " shared/source/helpers/state_base_address.h"
1212#include " shared/source/os_interface/device_factory.h"
13+ #include " shared/test/unit_test/cmd_parse/gen_cmd_parse.h"
1314#include " shared/test/unit_test/helpers/debug_manager_state_restore.h"
1415#include " shared/test/unit_test/helpers/default_hw_info.h"
1516#include " shared/test/unit_test/helpers/variable_backup.h"
17+ #include " shared/test/unit_test/mocks/mock_bindless_heaps_helper.h"
1618#include " shared/test/unit_test/mocks/mock_command_stream_receiver.h"
19+ #include " shared/test/unit_test/mocks/mock_graphics_allocation.h"
1720
1821#include " opencl/test/unit_test/libult/ult_command_stream_receiver.h"
1922#include " opencl/test/unit_test/mocks/mock_memory_manager.h"
@@ -301,7 +304,7 @@ HWTEST2_F(CommandQueueProgramSBATest, whenCreatingCommandQueueThenItIsInitialize
301304 .Times (1 ); // instruction heap
302305 }
303306
304- commandQueue->programGeneralStateBaseAddress (0u , true , child);
307+ commandQueue->programStateBaseAddress (0u , true , child);
305308
306309 if (isaInLocalMemory) {
307310 EXPECT_CALL (*memoryManager, getInternalHeapBaseAddress (rootDeviceIndex, false ))
@@ -317,7 +320,7 @@ HWTEST2_F(CommandQueueProgramSBATest, whenCreatingCommandQueueThenItIsInitialize
317320 .Times (2 );
318321 }
319322
320- commandQueue->programGeneralStateBaseAddress (0u , false , child);
323+ commandQueue->programStateBaseAddress (0u , false , child);
321324
322325 commandQueue->destroy ();
323326}
@@ -333,7 +336,7 @@ HWTEST2_F(CommandQueueProgramSBATest,
333336 uint32_t alignedSize = 4096u ;
334337 NEO::LinearStream child (commandQueue->commandStream ->getSpace (alignedSize), alignedSize);
335338
336- commandQueue->programGeneralStateBaseAddress (0u , true , child);
339+ commandQueue->programStateBaseAddress (0u , true , child);
337340 auto pSbaCmd = static_cast <STATE_BASE_ADDRESS *>(commandQueue->commandStream ->getSpace (sizeof (STATE_BASE_ADDRESS)));
338341 uint32_t statelessMocsIndex = pSbaCmd->getStatelessDataPortAccessMemoryObjectControlState ();
339342
@@ -344,6 +347,82 @@ HWTEST2_F(CommandQueueProgramSBATest,
344347 commandQueue->destroy ();
345348}
346349
350+ using BindlessCommandQueueSBASupport = IsAtLeastProduct<IGFX_SKYLAKE>;
351+
352+ HWTEST2_F (CommandQueueProgramSBATest,
353+ givenBindlessModeEnabledWhenProgrammingStateBaseAddressThenBindlessBaseAddressIsPassed, BindlessCommandQueueSBASupport) {
354+ using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
355+ DebugManagerStateRestore dbgRestorer;
356+ DebugManager.flags .UseBindlessMode .set (1 );
357+ auto bindlessHeapsHelper = std::make_unique<MockBindlesHeapsHelper>(neoDevice->getMemoryManager (), neoDevice->getNumAvailableDevices () > 1 , neoDevice->getRootDeviceIndex ());
358+ MockBindlesHeapsHelper *bindlessHeapsHelperPtr = bindlessHeapsHelper.get ();
359+ neoDevice->bindlessHeapHelper .reset (bindlessHeapsHelper.release ());
360+ NEO::MockGraphicsAllocation baseAllocation;
361+ bindlessHeapsHelperPtr->surfaceStateHeaps [NEO::BindlessHeapsHelper::GLOBAL_SSH].reset (new IndirectHeap (&baseAllocation, true ));
362+ baseAllocation.setGpuBaseAddress (0x123000 );
363+ ze_command_queue_desc_t desc = {};
364+ auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver ());
365+ auto commandQueue = new MockCommandQueueHw<gfxCoreFamily>(device, csr.get (), &desc);
366+ commandQueue->initialize (false , false );
367+
368+ uint32_t alignedSize = 4096u ;
369+ NEO::LinearStream child (commandQueue->commandStream ->getSpace (alignedSize), alignedSize);
370+
371+ commandQueue->programStateBaseAddress (0u , true , child);
372+
373+ auto usedSpaceAfter = commandQueue->commandStream ->getUsed ();
374+
375+ GenCmdList cmdList;
376+ ASSERT_TRUE (FamilyType::PARSE::parseCommandBuffer (
377+ cmdList, ptrOffset (commandQueue->commandStream ->getCpuBase (), 0 ), usedSpaceAfter));
378+
379+ auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin (), cmdList.end ());
380+ ASSERT_NE (cmdList.end (), itor);
381+
382+ auto cmdSba = genCmdCast<STATE_BASE_ADDRESS *>(*itor);
383+ EXPECT_EQ (cmdSba->getBindlessSurfaceStateBaseAddressModifyEnable (), true );
384+ EXPECT_EQ (cmdSba->getBindlessSurfaceStateBaseAddress (), neoDevice->bindlessHeapHelper ->getGlobalHeapsBase ());
385+ EXPECT_EQ (cmdSba->getBindlessSurfaceStateSize (), MemoryConstants::sizeOf4GBinPageEntities);
386+
387+ commandQueue->destroy ();
388+ }
389+
390+ HWTEST2_F (CommandQueueProgramSBATest,
391+ givenBindlessModeDisabledWhenProgrammingStateBaseAddressThenBindlessBaseAddressNotPassed, CommandQueueSBASupport) {
392+ using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
393+ DebugManagerStateRestore dbgRestorer;
394+ DebugManager.flags .UseBindlessMode .set (0 );
395+ auto bindlessHeapsHelper = std::make_unique<MockBindlesHeapsHelper>(neoDevice->getMemoryManager (), neoDevice->getNumAvailableDevices () > 1 , neoDevice->getRootDeviceIndex ());
396+ MockBindlesHeapsHelper *bindlessHeapsHelperPtr = bindlessHeapsHelper.get ();
397+ neoDevice->bindlessHeapHelper .reset (bindlessHeapsHelper.release ());
398+ NEO::MockGraphicsAllocation baseAllocation;
399+ bindlessHeapsHelperPtr->surfaceStateHeaps [NEO::BindlessHeapsHelper::GLOBAL_SSH].reset (new IndirectHeap (&baseAllocation, true ));
400+ baseAllocation.setGpuBaseAddress (0x123000 );
401+ ze_command_queue_desc_t desc = {};
402+ auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver ());
403+ auto commandQueue = new MockCommandQueueHw<gfxCoreFamily>(device, csr.get (), &desc);
404+ commandQueue->initialize (false , false );
405+
406+ uint32_t alignedSize = 4096u ;
407+ NEO::LinearStream child (commandQueue->commandStream ->getSpace (alignedSize), alignedSize);
408+
409+ commandQueue->programStateBaseAddress (0u , true , child);
410+
411+ auto usedSpaceAfter = commandQueue->commandStream ->getUsed ();
412+
413+ GenCmdList cmdList;
414+ ASSERT_TRUE (FamilyType::PARSE::parseCommandBuffer (
415+ cmdList, ptrOffset (commandQueue->commandStream ->getCpuBase (), 0 ), usedSpaceAfter));
416+
417+ auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin (), cmdList.end ());
418+ ASSERT_NE (cmdList.end (), itor);
419+
420+ auto cmdSba = genCmdCast<STATE_BASE_ADDRESS *>(*itor);
421+ EXPECT_NE (cmdSba->getBindlessSurfaceStateBaseAddress (), neoDevice->bindlessHeapHelper ->getGlobalHeapsBase ());
422+
423+ commandQueue->destroy ();
424+ }
425+
347426TEST_F (CommandQueueCreate, givenCmdQueueWithBlitCopyWhenExecutingNonCopyBlitCommandListThenWrongCommandListStatusReturned) {
348427 const ze_command_queue_desc_t desc = {};
349428 ze_result_t returnValue;
0 commit comments