2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-03 23:18:21 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/memory_manager/mem_obj_surface.h"
|
|
|
|
#include "opencl/source/platform/platform.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_buffer.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_csr.h"
|
2020-03-17 21:25:44 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "test.h"
|
2019-02-13 00:27:13 +08:00
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef ::testing::Types<NullSurface, HostPtrSurface, MemObjSurface, GeneralSurface> SurfaceTypes;
|
|
|
|
|
|
|
|
namespace createSurface {
|
|
|
|
template <typename surfType>
|
|
|
|
Surface *Create(char *data, MockBuffer *buffer, GraphicsAllocation *gfxAllocation);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
Surface *Create<NullSurface>(char *data, MockBuffer *buffer, GraphicsAllocation *gfxAllocation) {
|
|
|
|
return new NullSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
Surface *Create<HostPtrSurface>(char *data, MockBuffer *buffer, GraphicsAllocation *gfxAllocation) {
|
2018-02-09 05:52:58 +08:00
|
|
|
return new HostPtrSurface(data, 10, gfxAllocation);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
Surface *Create<MemObjSurface>(char *data, MockBuffer *buffer, GraphicsAllocation *gfxAllocation) {
|
|
|
|
return new MemObjSurface(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
Surface *Create<GeneralSurface>(char *data, MockBuffer *buffer, GraphicsAllocation *gfxAllocation) {
|
|
|
|
return new GeneralSurface(gfxAllocation);
|
|
|
|
}
|
2018-02-09 05:52:58 +08:00
|
|
|
} // namespace createSurface
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class SurfaceTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
char data[10];
|
|
|
|
MockBuffer buffer;
|
2018-10-30 22:24:15 +08:00
|
|
|
MockGraphicsAllocation gfxAllocation{nullptr, 0};
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TYPED_TEST_CASE(SurfaceTest, SurfaceTypes);
|
|
|
|
|
|
|
|
HWTEST_TYPED_TEST(SurfaceTest, GivenSurfaceWhenInterfaceIsUsedThenSurfaceBehavesCorrectly) {
|
|
|
|
int32_t execStamp;
|
|
|
|
|
2020-02-03 23:18:21 +08:00
|
|
|
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
|
2019-03-15 17:22:35 +08:00
|
|
|
executionEnvironment->initializeMemoryManager();
|
2019-11-05 20:38:20 +08:00
|
|
|
auto csr = std::make_unique<MockCsr<FamilyType>>(execStamp, *executionEnvironment, 0);
|
2020-03-24 18:42:54 +08:00
|
|
|
auto hwInfo = *defaultHwInfo;
|
2020-03-03 16:21:18 +08:00
|
|
|
auto engine = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances(hwInfo)[0];
|
2020-03-04 06:33:31 +08:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr.get(), engine, 1,
|
|
|
|
PreemptionHelper::getDefaultPreemptionMode(hwInfo),
|
|
|
|
false, false, false);
|
2019-02-18 20:59:16 +08:00
|
|
|
csr->setupContext(*osContext);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
Surface *surface = createSurface::Create<TypeParam>(this->data,
|
|
|
|
&this->buffer,
|
|
|
|
&this->gfxAllocation);
|
|
|
|
ASSERT_NE(nullptr, surface);
|
|
|
|
|
|
|
|
Surface *duplicatedSurface = surface->duplicate();
|
|
|
|
ASSERT_NE(nullptr, duplicatedSurface);
|
|
|
|
|
|
|
|
surface->makeResident(*csr);
|
|
|
|
|
|
|
|
if (std::is_same<TypeParam, HostPtrSurface>::value ||
|
|
|
|
std::is_same<TypeParam, MemObjSurface>::value ||
|
|
|
|
std::is_same<TypeParam, GeneralSurface>::value) {
|
|
|
|
EXPECT_EQ(1u, csr->madeResidentGfxAllocations.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
delete duplicatedSurface;
|
|
|
|
delete surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CoherentMemObjSurface : public SurfaceTest<MemObjSurface> {
|
|
|
|
public:
|
|
|
|
CoherentMemObjSurface() {
|
|
|
|
this->buffer.getGraphicsAllocation()->setCoherent(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(CoherentMemObjSurface, BufferFromCoherentSvm) {
|
|
|
|
Surface *surface = createSurface::Create<MemObjSurface>(this->data,
|
|
|
|
&this->buffer,
|
|
|
|
&this->gfxAllocation);
|
|
|
|
|
|
|
|
EXPECT_TRUE(surface->IsCoherent);
|
|
|
|
|
|
|
|
delete surface;
|
|
|
|
}
|
2018-02-28 19:09:48 +08:00
|
|
|
|
|
|
|
TEST(HostPtrSurfaceTest, givenHostPtrSurfaceWhenCreatedWithoutSpecifyingPtrCopyAllowanceThenPtrCopyIsNotAllowed) {
|
|
|
|
char memory[2];
|
|
|
|
HostPtrSurface surface(memory, sizeof(memory));
|
|
|
|
|
|
|
|
EXPECT_FALSE(surface.peekIsPtrCopyAllowed());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HostPtrSurfaceTest, givenHostPtrSurfaceWhenCreatedWithPtrCopyAllowedThenQueryReturnsTrue) {
|
|
|
|
char memory[2];
|
|
|
|
HostPtrSurface surface(memory, sizeof(memory), true);
|
|
|
|
|
|
|
|
EXPECT_TRUE(surface.peekIsPtrCopyAllowed());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HostPtrSurfaceTest, givenHostPtrSurfaceWhenCreatedWithPtrCopyNotAllowedThenQueryReturnsFalse) {
|
|
|
|
char memory[2];
|
|
|
|
HostPtrSurface surface(memory, sizeof(memory), false);
|
|
|
|
|
|
|
|
EXPECT_FALSE(surface.peekIsPtrCopyAllowed());
|
|
|
|
}
|