2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-04-04 15:29:48 +08:00
|
|
|
* Copyright (c) 2017 - 2018, Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/mem_obj/buffer.h"
|
|
|
|
#include "unit_tests/mocks/mock_graphics_allocation.h"
|
|
|
|
#include "unit_tests/mocks/mock_context.h"
|
2018-06-11 20:58:35 +08:00
|
|
|
#include "unit_tests/mocks/mock_device.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
using namespace OCLRT;
|
|
|
|
|
|
|
|
class MockBufferStorage {
|
|
|
|
public:
|
|
|
|
MockBufferStorage() : mockGfxAllocation(data, sizeof(data) / 2) {
|
|
|
|
}
|
|
|
|
MockBufferStorage(bool unaligned) : mockGfxAllocation(unaligned ? alignUp(&data, 4) : alignUp(&data, 64), sizeof(data) / 2) {
|
|
|
|
}
|
|
|
|
char data[128];
|
|
|
|
MockGraphicsAllocation mockGfxAllocation;
|
2018-07-03 16:00:12 +08:00
|
|
|
std::unique_ptr<Device> device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MockBuffer : public MockBufferStorage, public Buffer {
|
|
|
|
public:
|
2018-04-04 15:29:48 +08:00
|
|
|
using Buffer::magic;
|
2018-07-03 16:00:12 +08:00
|
|
|
using MockBufferStorage::device;
|
2018-04-04 15:29:48 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
MockBuffer(GraphicsAllocation &alloc)
|
|
|
|
: MockBufferStorage(), Buffer(nullptr, CL_MEM_USE_HOST_PTR, alloc.getUnderlyingBufferSize(), alloc.getUnderlyingBuffer(), alloc.getUnderlyingBuffer(), &alloc, true, false, false),
|
|
|
|
externalAlloc(&alloc) {
|
|
|
|
}
|
|
|
|
MockBuffer() : MockBufferStorage(), Buffer(nullptr, CL_MEM_USE_HOST_PTR, sizeof(data), &data, &data, &mockGfxAllocation, true, false, false) {
|
|
|
|
}
|
|
|
|
~MockBuffer() override {
|
|
|
|
if (externalAlloc != nullptr) {
|
|
|
|
// no ownership over graphics allocation
|
|
|
|
// return to mock allocations
|
|
|
|
this->graphicsAllocation = &this->mockGfxAllocation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void setArgStateful(void *memory) override {
|
2018-06-11 20:58:35 +08:00
|
|
|
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), (externalAlloc != nullptr) ? externalAlloc : &mockGfxAllocation);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
GraphicsAllocation *externalAlloc = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AlignedBuffer : public MockBufferStorage, public Buffer {
|
|
|
|
public:
|
2018-07-03 16:00:12 +08:00
|
|
|
using MockBufferStorage::device;
|
2017-12-21 07:45:38 +08:00
|
|
|
AlignedBuffer() : MockBufferStorage(false), Buffer(nullptr, CL_MEM_USE_HOST_PTR, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64), &mockGfxAllocation, true, false, false) {
|
|
|
|
}
|
|
|
|
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 {
|
2018-06-11 20:58:35 +08:00
|
|
|
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), &mockGfxAllocation);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class UnalignedBuffer : public MockBufferStorage, public Buffer {
|
|
|
|
public:
|
2018-07-03 16:00:12 +08:00
|
|
|
using MockBufferStorage::device;
|
2017-12-21 07:45:38 +08:00
|
|
|
UnalignedBuffer() : MockBufferStorage(true), Buffer(nullptr, CL_MEM_USE_HOST_PTR, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4), &mockGfxAllocation, false, false, false) {
|
|
|
|
}
|
|
|
|
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 {
|
2018-06-11 20:58:35 +08:00
|
|
|
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), &mockGfxAllocation);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
};
|
2018-07-25 00:36:26 +08:00
|
|
|
|
|
|
|
class MockPublicAccessBuffer : public Buffer {
|
|
|
|
public:
|
|
|
|
using Buffer::getGraphicsAllocationType;
|
|
|
|
};
|