mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Use device instead of context when programing surface state.
Change-Id: I67615036d373cf905762a43a92562bf3d84854a5
This commit is contained in:

committed by
sys_ocldev

parent
ded1a445f8
commit
0cc10e47cc
@ -578,7 +578,7 @@ bool CommandQueue::setupDebugSurface(Kernel *kernel) {
|
||||
kernel->getKernelInfo().patchInfo.pAllocateSystemThreadSurface->Offset);
|
||||
void *addressToPatch = reinterpret_cast<void *>(debugSurface->getGpuAddress());
|
||||
size_t sizeToPatch = debugSurface->getUnderlyingBufferSize();
|
||||
Buffer::setSurfaceState(context, surfaceState, sizeToPatch, addressToPatch, debugSurface);
|
||||
Buffer::setSurfaceState(device, surfaceState, sizeToPatch, addressToPatch, debugSurface);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ void Kernel::patchWithImplicitSurface(void *ptrToPatchInCrossThreadData, Graphic
|
||||
auto surfaceState = ptrOffset(ssh, sshOffset);
|
||||
void *addressToPatch = reinterpret_cast<void *>(allocation.getUnderlyingBuffer());
|
||||
size_t sizeToPatch = allocation.getUnderlyingBufferSize();
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, sizeToPatch, addressToPatch, &allocation);
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, sizeToPatch, addressToPatch, &allocation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ cl_int Kernel::initialize() {
|
||||
if (requiresSshForBuffers()) {
|
||||
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(getSurfaceStateHeap()),
|
||||
patchInfo.pAllocateStatelessEventPoolSurface->SurfaceStateHeapOffset);
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, 0, nullptr);
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ cl_int Kernel::initialize() {
|
||||
if (requiresSshForBuffers()) {
|
||||
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(getSurfaceStateHeap()),
|
||||
patchInfo.pAllocateStatelessDefaultDeviceQueueSurface->SurfaceStateHeapOffset);
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, 0, nullptr);
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -841,7 +841,7 @@ cl_int Kernel::setArgSvm(uint32_t argIndex, size_t svmAllocSize, void *svmPtr, G
|
||||
if (requiresSshForBuffers()) {
|
||||
const auto &kernelArgInfo = kernelInfo.kernelArgInfo[argIndex];
|
||||
auto surfaceState = ptrOffset(getSurfaceStateHeap(), kernelArgInfo.offsetHeap);
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, svmAllocSize + ptrDiff(svmPtr, ptrToPatch), ptrToPatch, svmAlloc, svmFlags);
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, svmAllocSize + ptrDiff(svmPtr, ptrToPatch), ptrToPatch, svmAlloc, svmFlags);
|
||||
}
|
||||
if (!kernelArguments[argIndex].isPatched) {
|
||||
patchedArgumentsNum++;
|
||||
@ -875,7 +875,7 @@ cl_int Kernel::setArgSvmAlloc(uint32_t argIndex, void *svmPtr, GraphicsAllocatio
|
||||
size_t offset = ptrDiff(ptrToPatch, svmAlloc->getUnderlyingBuffer());
|
||||
allocSize -= offset;
|
||||
}
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, allocSize, ptrToPatch, nullptr);
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, allocSize, ptrToPatch, nullptr);
|
||||
}
|
||||
|
||||
if (!kernelArguments[argIndex].isPatched) {
|
||||
@ -1141,7 +1141,7 @@ cl_int Kernel::setArgBuffer(uint32_t argIndex,
|
||||
|
||||
if (requiresSshForBuffers()) {
|
||||
auto surfaceState = ptrOffset(getSurfaceStateHeap(), kernelArgInfo.offsetHeap);
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, 0, nullptr);
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, 0, nullptr);
|
||||
}
|
||||
|
||||
return CL_SUCCESS;
|
||||
@ -1188,7 +1188,7 @@ cl_int Kernel::setArgPipe(uint32_t argIndex,
|
||||
|
||||
if (requiresSshForBuffers()) {
|
||||
auto surfaceState = ptrOffset(getSurfaceStateHeap(), kernelArgInfo.offsetHeap);
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState,
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState,
|
||||
pipe->getSize(), pipe->getCpuAddress(),
|
||||
pipe->getGraphicsAllocation());
|
||||
}
|
||||
@ -2016,7 +2016,7 @@ void Kernel::patchDefaultDeviceQueue(DeviceQueue *devQueue) {
|
||||
if (requiresSshForBuffers()) {
|
||||
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(getSurfaceStateHeap()),
|
||||
patchInfo.pAllocateStatelessDefaultDeviceQueueSurface->SurfaceStateHeapOffset);
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, devQueue->getQueueBuffer()->getUnderlyingBufferSize(), (void *)devQueue->getQueueBuffer()->getGpuAddress(), devQueue->getQueueBuffer());
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, devQueue->getQueueBuffer()->getUnderlyingBufferSize(), (void *)devQueue->getQueueBuffer()->getGpuAddress(), devQueue->getQueueBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2036,7 +2036,7 @@ void Kernel::patchEventPool(DeviceQueue *devQueue) {
|
||||
if (requiresSshForBuffers()) {
|
||||
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(getSurfaceStateHeap()),
|
||||
patchInfo.pAllocateStatelessEventPoolSurface->SurfaceStateHeapOffset);
|
||||
Buffer::setSurfaceState(&getContext(), surfaceState, devQueue->getEventPoolBuffer()->getUnderlyingBufferSize(), (void *)devQueue->getEventPoolBuffer()->getGpuAddress(), devQueue->getEventPoolBuffer());
|
||||
Buffer::setSurfaceState(&getDevice(), surfaceState, devQueue->getEventPoolBuffer()->getUnderlyingBufferSize(), (void *)devQueue->getEventPoolBuffer()->getGpuAddress(), devQueue->getEventPoolBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -374,13 +374,32 @@ Buffer *Buffer::createBufferHw(Context *context,
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
void Buffer::setSurfaceState(Context *context,
|
||||
Buffer *Buffer::createBufferHwFromDevice(const Device *device,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
GraphicsAllocation *gfxAllocation,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isImageRedescribed) {
|
||||
|
||||
const auto &hwInfo = device->getHardwareInfo();
|
||||
|
||||
auto funcCreate = bufferFactory[hwInfo.pPlatform->eRenderCoreFamily].createBufferFunction;
|
||||
DEBUG_BREAK_IF(nullptr == funcCreate);
|
||||
auto pBuffer = funcCreate(nullptr, flags, size, memoryStorage, hostPtr, gfxAllocation,
|
||||
zeroCopy, isHostPtrSVM, isImageRedescribed);
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
void Buffer::setSurfaceState(const Device *device,
|
||||
void *surfaceState,
|
||||
size_t svmSize,
|
||||
void *svmPtr,
|
||||
GraphicsAllocation *gfxAlloc,
|
||||
cl_mem_flags flags) {
|
||||
auto buffer = Buffer::createBufferHw(context, flags, svmSize, svmPtr, svmPtr, gfxAlloc, false, false, false);
|
||||
auto buffer = Buffer::createBufferHwFromDevice(device, flags, svmSize, svmPtr, svmPtr, gfxAlloc, false, false, false);
|
||||
buffer->setArgStateful(surfaceState);
|
||||
buffer->graphicsAllocation = nullptr;
|
||||
delete buffer;
|
||||
|
@ -75,11 +75,21 @@ class Buffer : public MemObj {
|
||||
bool isHostPtrSVM,
|
||||
bool isImageRedescribed);
|
||||
|
||||
static Buffer *createBufferHwFromDevice(const Device *device,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
GraphicsAllocation *gfxAllocation,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isImageRedescribed);
|
||||
|
||||
Buffer *createSubBuffer(cl_mem_flags flags,
|
||||
const cl_buffer_region *region,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static void setSurfaceState(Context *context,
|
||||
static void setSurfaceState(const Device *device,
|
||||
void *surfaceState,
|
||||
size_t svmSize,
|
||||
void *svmPtr,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
* Copyright (c) 2017 - 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
@ -66,7 +66,7 @@ void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo)
|
||||
kernel->getKernelInfo().patchInfo.pAllocateStatelessPrintfSurface->SurfaceStateHeapOffset);
|
||||
void *addressToPatch = printfSurface->getUnderlyingBuffer();
|
||||
size_t sizeToPatch = printfSurface->getUnderlyingBufferSize();
|
||||
Buffer::setSurfaceState(&kernel->getContext(), surfaceState, sizeToPatch, addressToPatch, printfSurface);
|
||||
Buffer::setSurfaceState(&device, surfaceState, sizeToPatch, addressToPatch, printfSurface);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ HWTEST_F(KernelArgSvmTest, PatchWithImplicitSurface) {
|
||||
{
|
||||
void *addressToPatch = svmAlloc.getUnderlyingBuffer();
|
||||
size_t sizeToPatch = svmAlloc.getUnderlyingBufferSize();
|
||||
Buffer::setSurfaceState(pContext, &expectedSurfaceState, sizeToPatch, addressToPatch, &svmAlloc);
|
||||
Buffer::setSurfaceState(pDevice, &expectedSurfaceState, sizeToPatch, addressToPatch, &svmAlloc);
|
||||
}
|
||||
|
||||
// verify ssh was properly patched
|
||||
@ -369,6 +369,8 @@ HWTEST_TYPED_TEST(KernelArgSvmTestTyped, GivenBufferKernelArgWhenBufferOffsetIsN
|
||||
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
|
||||
constexpr size_t rendSurfSize = sizeof(RENDER_SURFACE_STATE);
|
||||
|
||||
std::unique_ptr<Device> device(Device::create<MockDevice>(*platformDevices));
|
||||
|
||||
uint32_t svmSize = MemoryConstants::pageSize;
|
||||
char *svmPtr = reinterpret_cast<char *>(alignedMalloc(svmSize, MemoryConstants::pageSize));
|
||||
|
||||
@ -416,7 +418,7 @@ HWTEST_TYPED_TEST(KernelArgSvmTestTyped, GivenBufferKernelArgWhenBufferOffsetIsN
|
||||
EXPECT_EQ(0U, *expectedOffsetPatchPtr);
|
||||
}
|
||||
|
||||
Buffer::setSurfaceState(this->pContext, &expectedSurfaceState, svmAlloc.getUnderlyingBufferSize(), svmAlloc.getUnderlyingBuffer(), &svmAlloc);
|
||||
Buffer::setSurfaceState(device.get(), &expectedSurfaceState, svmAlloc.getUnderlyingBufferSize(), svmAlloc.getUnderlyingBuffer(), &svmAlloc);
|
||||
|
||||
// verify ssh was properly patched
|
||||
int32_t cmpResult = memcmp(&expectedSurfaceState, surfState, rendSurfSize);
|
||||
|
@ -765,10 +765,11 @@ TEST(SharedBuffersTest, whenBuffersIsCreatedWithSharingHandlerThenItIsSharedBuff
|
||||
class BufferTests : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
device.reset(Device::create<MockDevice>(*platformDevices));
|
||||
}
|
||||
void TearDown() override {
|
||||
}
|
||||
MockContext context;
|
||||
std::unique_ptr<Device> device;
|
||||
};
|
||||
|
||||
typedef BufferTests BufferSetSurfaceTests;
|
||||
@ -782,7 +783,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatMemoryPtrAndSizeIsAlign
|
||||
RENDER_SURFACE_STATE surfaceState = {};
|
||||
|
||||
Buffer::setSurfaceState(
|
||||
&context,
|
||||
device.get(),
|
||||
&surfaceState,
|
||||
size,
|
||||
ptr);
|
||||
@ -804,7 +805,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatMemoryPtrIsUnalignedToC
|
||||
RENDER_SURFACE_STATE surfaceState = {};
|
||||
|
||||
Buffer::setSurfaceState(
|
||||
&context,
|
||||
device.get(),
|
||||
&surfaceState,
|
||||
size,
|
||||
offsetedPtr);
|
||||
@ -826,7 +827,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatMemorySizeIsUnalignedTo
|
||||
RENDER_SURFACE_STATE surfaceState = {};
|
||||
|
||||
Buffer::setSurfaceState(
|
||||
&context,
|
||||
device.get(),
|
||||
&surfaceState,
|
||||
offsetedSize,
|
||||
ptr);
|
||||
@ -848,7 +849,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatMemoryIsUnalignedToCach
|
||||
RENDER_SURFACE_STATE surfaceState = {};
|
||||
|
||||
Buffer::setSurfaceState(
|
||||
&context,
|
||||
device.get(),
|
||||
&surfaceState,
|
||||
offsetedSize,
|
||||
ptr,
|
||||
@ -872,7 +873,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatMemorySizeIsUnalignedTh
|
||||
RENDER_SURFACE_STATE surfaceState = {};
|
||||
|
||||
Buffer::setSurfaceState(
|
||||
&context,
|
||||
device.get(),
|
||||
&surfaceState,
|
||||
offsetedSize,
|
||||
ptr);
|
||||
@ -892,7 +893,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatMemoryPtrIsNotNullThenB
|
||||
RENDER_SURFACE_STATE surfaceState = {};
|
||||
|
||||
Buffer::setSurfaceState(
|
||||
&context,
|
||||
device.get(),
|
||||
&surfaceState,
|
||||
size,
|
||||
ptr);
|
||||
@ -909,7 +910,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatMemoryPtrIsNullThenNull
|
||||
RENDER_SURFACE_STATE surfaceState = {};
|
||||
|
||||
Buffer::setSurfaceState(
|
||||
&context,
|
||||
device.get(),
|
||||
&surfaceState,
|
||||
0,
|
||||
nullptr);
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "runtime/mem_obj/buffer.h"
|
||||
#include "unit_tests/mocks/mock_graphics_allocation.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "unit_tests/mocks/mock_device.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
@ -56,9 +57,9 @@ class MockBuffer : public MockBufferStorage, public Buffer {
|
||||
}
|
||||
}
|
||||
void setArgStateful(void *memory) override {
|
||||
Buffer::setSurfaceState(&context, memory, getSize(), getCpuAddress(), (externalAlloc != nullptr) ? externalAlloc : &mockGfxAllocation);
|
||||
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), (externalAlloc != nullptr) ? externalAlloc : &mockGfxAllocation);
|
||||
}
|
||||
MockContext context;
|
||||
std::unique_ptr<Device> device = std::unique_ptr<Device>(OCLRT::Device::create<OCLRT::MockDevice>(nullptr));
|
||||
GraphicsAllocation *externalAlloc = nullptr;
|
||||
};
|
||||
|
||||
@ -69,9 +70,9 @@ class AlignedBuffer : public MockBufferStorage, public Buffer {
|
||||
AlignedBuffer(GraphicsAllocation *gfxAllocation) : MockBufferStorage(), Buffer(nullptr, CL_MEM_USE_HOST_PTR, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64), gfxAllocation, true, false, false) {
|
||||
}
|
||||
void setArgStateful(void *memory) override {
|
||||
Buffer::setSurfaceState(&context, memory, getSize(), getCpuAddress(), &mockGfxAllocation);
|
||||
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), &mockGfxAllocation);
|
||||
}
|
||||
MockContext context;
|
||||
std::unique_ptr<Device> device = std::unique_ptr<Device>(OCLRT::Device::create<OCLRT::MockDevice>(nullptr));
|
||||
};
|
||||
|
||||
class UnalignedBuffer : public MockBufferStorage, public Buffer {
|
||||
@ -81,7 +82,7 @@ class UnalignedBuffer : public MockBufferStorage, public Buffer {
|
||||
UnalignedBuffer(GraphicsAllocation *gfxAllocation) : MockBufferStorage(true), Buffer(nullptr, CL_MEM_USE_HOST_PTR, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4), gfxAllocation, false, false, false) {
|
||||
}
|
||||
void setArgStateful(void *memory) override {
|
||||
Buffer::setSurfaceState(&context, memory, getSize(), getCpuAddress(), &mockGfxAllocation);
|
||||
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), &mockGfxAllocation);
|
||||
}
|
||||
MockContext context;
|
||||
std::unique_ptr<Device> device = std::unique_ptr<Device>(OCLRT::Device::create<OCLRT::MockDevice>(nullptr));
|
||||
};
|
||||
|
Reference in New Issue
Block a user