Add method checkResourceCompatibility

Change-Id: I858f54cbeac86121882ca0dec1a5f35eca034dbd
Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
Kamil Diedrich 2019-03-29 11:48:32 +01:00 committed by sys_ocldev
parent a025dc6985
commit 0ff6358c17
7 changed files with 81 additions and 1 deletions

View File

@ -10,6 +10,7 @@
#include "runtime/command_stream/linear_stream.h"
#include "runtime/gen_common/aub_mapper.h"
#include "runtime/gen_common/hw_cmds.h"
#include "runtime/mem_obj/buffer.h"
#include "CL/cl.h"
@ -42,6 +43,7 @@ class HwHelper {
virtual const AubMemDump::LrcaHelper &getCsTraits(aub_stream::EngineType engineType) const = 0;
virtual bool supportsYTiling() const = 0;
virtual bool obtainRenderBufferCompressionPreference(const HardwareInfo &hwInfo) const = 0;
virtual void checkResourceCompatibility(Buffer *buffer, cl_int &errorCode) = 0;
static bool renderCompressedBuffersSupported(const HardwareInfo &hwInfo);
static bool renderCompressedImagesSupported(const HardwareInfo &hwInfo);
static bool cacheFlushAfterWalkerSupported(const HardwareInfo &hwInfo);
@ -127,6 +129,8 @@ class HwHelperHw : public HwHelper {
bool obtainRenderBufferCompressionPreference(const HardwareInfo &hwInfo) const override;
void checkResourceCompatibility(Buffer *buffer, cl_int &errorCode) override;
bool timestampPacketWriteSupported() const override;
bool isPageTableManagerSupported(const HardwareInfo &hwInfo) const override;

View File

@ -97,6 +97,10 @@ bool HwHelperHw<Family>::timestampPacketWriteSupported() const {
return false;
}
template <typename GfxFamily>
inline void HwHelperHw<GfxFamily>::checkResourceCompatibility(Buffer *buffer, cl_int &errorCode) {
}
template <typename Family>
void HwHelperHw<Family>::setRenderSurfaceStateForBuffer(ExecutionEnvironment &executionEnvironment,
void *surfaceStateBuffer,

View File

@ -17,6 +17,7 @@
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/basic_math.h"
#include "runtime/helpers/get_info.h"
#include "runtime/helpers/hw_helper.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/mipmap.h"
#include "runtime/helpers/ptr_math.h"
@ -186,6 +187,13 @@ Image *Image::create(Context *context,
bool zeroCopy = false;
bool transferNeeded = false;
if (((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) && (parentBuffer != nullptr)) {
HwHelper::get(context->getDevice(0)->getHardwareInfo().pPlatform->eRenderCoreFamily).checkResourceCompatibility(parentBuffer, errcodeRet);
if (errcodeRet != CL_SUCCESS) {
return nullptr;
}
memory = parentBuffer->getGraphicsAllocation();
// Image from buffer - we never allocate memory, we use what buffer provides
zeroCopy = true;

View File

@ -41,6 +41,7 @@ set(IGDRCL_SRCS_tests_helpers
${CMAKE_CURRENT_SOURCE_DIR}/mipmap_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/per_thread_data_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ptr_math_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/raii_hw_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/queue_helpers_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sampler_helpers_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/string_to_hash_tests.cpp

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/helpers/hw_helper.h"
namespace NEO {
extern HwHelper *hwHelperFactory[IGFX_MAX_CORE];
template <class MockHelper>
class RAIIHwHelperFactory {
public:
GFXCORE_FAMILY gfxCoreFamily;
HwHelper *hwHelper;
MockHelper mockHwHelper;
RAIIHwHelperFactory(GFXCORE_FAMILY gfxCoreFamily) {
this->gfxCoreFamily = gfxCoreFamily;
hwHelper = hwHelperFactory[this->gfxCoreFamily];
hwHelperFactory[this->gfxCoreFamily] = &mockHwHelper;
}
~RAIIHwHelperFactory() {
hwHelperFactory[this->gfxCoreFamily] = hwHelper;
}
};
} // namespace NEO

View File

@ -511,7 +511,7 @@ TEST_F(RenderCompressedBuffersTests, givenBufferNotCompressedAllocationAndNoHost
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
} else {
EXPECT_TRUE(buffer->isMemObjZeroCopy());
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
}
}
}

View File

@ -6,15 +6,21 @@
*/
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/hw_helper.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/mem_obj/image.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/helpers/raii_hw_helper.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_gmm.h"
using namespace NEO;
namespace NEO {
extern HwHelper *hwHelperFactory[IGFX_MAX_CORE];
}
// Tests for cl_khr_image2d_from_buffer
class Image2dFromBufferTest : public DeviceFixture, public ::testing::Test {
public:
@ -391,3 +397,28 @@ TEST_F(Image2dFromBufferTest, givenBufferWhenImageFromBufferThenIsImageFromBuffe
buffer->release();
imageDesc.mem_object = memObj;
}
HWTEST_F(Image2dFromBufferTest, givenBufferWhenImageFromBufferThenIsImageFromBufferSetAndAllocationTypeIsBufferNullptr) {
class MockHwHelperHw : public HwHelperHw<FamilyType> {
public:
void checkResourceCompatibility(Buffer *buffer, cl_int &errorCode) override {
errorCode = CL_INVALID_MEM_OBJECT;
}
};
auto raiiFactory = RAIIHwHelperFactory<MockHwHelperHw>(context.getDevice(0)->getHardwareInfo().pPlatform->eRenderCoreFamily);
cl_int errCode = CL_SUCCESS;
auto buffer = Buffer::create(&context, 0, 1, nullptr, errCode);
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
auto memObj = imageDesc.mem_object;
imageDesc.mem_object = buffer;
Image *imageFromBuffer = createImage();
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
EXPECT_EQ(imageFromBuffer, nullptr);
buffer->release();
imageDesc.mem_object = memObj;
}