mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-19 16:24:18 +08:00
Adding mipmap support in sampler
* sampler mipmap lod/filtering programming * sampler queries * clCreateSamplerWithProperties * fixed point numeric type (e.g. U4.8) Change-Id: I6b496e6f067f6232bab464ab3ee74af8b00904d3
This commit is contained in:
@@ -967,6 +967,9 @@ cl_sampler CL_API_CALL clCreateSampler(cl_context context,
|
||||
normalizedCoords,
|
||||
addressingMode,
|
||||
filterMode,
|
||||
CL_FILTER_NEAREST,
|
||||
0.0f,
|
||||
std::numeric_limits<float>::max(),
|
||||
retVal);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,20 +27,33 @@
|
||||
#include "runtime/helpers/hw_info.h"
|
||||
#include "patch_list.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
SamplerCreateFunc samplerFactory[IGFX_MAX_CORE] = {};
|
||||
getSamplerStateSizeHwFunc getSamplerStateSizeHw[IGFX_MAX_CORE] = {};
|
||||
|
||||
Sampler::Sampler(Context *context, cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode, cl_filter_mode filterMode)
|
||||
cl_addressing_mode addressingMode, cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode, float lodMin, float lodMax)
|
||||
: context(context), normalizedCoordinates(normalizedCoordinates),
|
||||
addressingMode(addressingMode), filterMode(filterMode) {
|
||||
addressingMode(addressingMode), filterMode(filterMode),
|
||||
mipFilterMode(mipFilterMode), lodMin(lodMin), lodMax(lodMax) {
|
||||
}
|
||||
|
||||
Sampler::Sampler(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode)
|
||||
: Sampler(context, normalizedCoordinates, addressingMode, filterMode,
|
||||
CL_FILTER_NEAREST, 0.0f, std::numeric_limits<float>::max()) {
|
||||
}
|
||||
|
||||
Sampler *Sampler::create(Context *context, cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode, cl_int &errcodeRet) {
|
||||
cl_addressing_mode addressingMode, cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode, float lodMin, float lodMax,
|
||||
cl_int &errcodeRet) {
|
||||
errcodeRet = CL_SUCCESS;
|
||||
Sampler *sampler = nullptr;
|
||||
|
||||
@@ -50,7 +63,7 @@ Sampler *Sampler::create(Context *context, cl_bool normalizedCoordinates,
|
||||
|
||||
auto funcCreate = samplerFactory[hwInfo.pPlatform->eRenderCoreFamily];
|
||||
DEBUG_BREAK_IF(nullptr == funcCreate);
|
||||
sampler = funcCreate(context, normalizedCoordinates, addressingMode, filterMode);
|
||||
sampler = funcCreate(context, normalizedCoordinates, addressingMode, filterMode, mipFilterMode, lodMin, lodMax);
|
||||
|
||||
if (sampler == nullptr) {
|
||||
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
||||
@@ -63,42 +76,42 @@ size_t Sampler::getSamplerStateSize(const HardwareInfo &hwInfo) {
|
||||
return getSamplerStateSizeHw[hwInfo.pPlatform->eRenderCoreFamily]();
|
||||
}
|
||||
|
||||
template <typename ParameterType, ParameterType minValue, ParameterType maxValue>
|
||||
template <typename ParameterType>
|
||||
struct SetOnce {
|
||||
SetOnce(ParameterType defaultValue) : value(defaultValue),
|
||||
setValueInternal(&SetOnce::setValueValid) {
|
||||
SetOnce(ParameterType defaultValue, ParameterType min, ParameterType max)
|
||||
: value(defaultValue), min(min), max(max) {
|
||||
}
|
||||
|
||||
cl_int setValue(cl_ulong property) {
|
||||
auto result = (this->*setValueInternal)(property);
|
||||
setValueInternal = &SetOnce::setValueInvalid;
|
||||
return result;
|
||||
}
|
||||
|
||||
ParameterType value;
|
||||
|
||||
protected:
|
||||
cl_int (SetOnce::*setValueInternal)(cl_ulong property);
|
||||
|
||||
cl_int setValueValid(cl_ulong property) {
|
||||
if (property >= minValue && property <= maxValue) {
|
||||
value = static_cast<ParameterType>(property);
|
||||
return CL_SUCCESS;
|
||||
cl_int setValue(ParameterType property) {
|
||||
if (alreadySet) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
return CL_INVALID_VALUE;
|
||||
|
||||
if ((property < min) || (property > max)) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
this->value = property;
|
||||
alreadySet = true;
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
cl_int setValueInvalid(cl_ulong property) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
bool alreadySet = false;
|
||||
ParameterType value;
|
||||
ParameterType min;
|
||||
ParameterType max;
|
||||
};
|
||||
|
||||
Sampler *Sampler::create(Context *context,
|
||||
const cl_sampler_properties *samplerProperties,
|
||||
cl_int &errcodeRet) {
|
||||
SetOnce<uint32_t, CL_FALSE, CL_TRUE> normalizedCoords(CL_TRUE);
|
||||
SetOnce<uint32_t, CL_FILTER_NEAREST, CL_FILTER_LINEAR> filterMode(CL_FILTER_NEAREST);
|
||||
SetOnce<uint32_t, CL_ADDRESS_NONE, CL_ADDRESS_MIRRORED_REPEAT> addressingMode(CL_ADDRESS_CLAMP);
|
||||
SetOnce<uint32_t> normalizedCoords(CL_TRUE, CL_FALSE, CL_TRUE);
|
||||
SetOnce<uint32_t> filterMode(CL_FILTER_NEAREST, CL_FILTER_NEAREST, CL_FILTER_LINEAR);
|
||||
SetOnce<uint32_t> addressingMode(CL_ADDRESS_CLAMP, CL_ADDRESS_NONE, CL_ADDRESS_MIRRORED_REPEAT);
|
||||
SetOnce<uint32_t> mipFilterMode(CL_FILTER_NEAREST, CL_FILTER_NEAREST, CL_FILTER_LINEAR);
|
||||
SetOnce<float> lodMin(0.0f, 0.0f, std::numeric_limits<float>::max());
|
||||
SetOnce<float> lodMax(std::numeric_limits<float>::max(), 0.0f, std::numeric_limits<float>::max());
|
||||
|
||||
errcodeRet = CL_SUCCESS;
|
||||
if (samplerProperties) {
|
||||
@@ -109,14 +122,29 @@ Sampler *Sampler::create(Context *context,
|
||||
auto samValue = *samplerProperties;
|
||||
switch (samType) {
|
||||
case CL_SAMPLER_NORMALIZED_COORDS:
|
||||
errcodeRet = normalizedCoords.setValue(samValue);
|
||||
errcodeRet = normalizedCoords.setValue(static_cast<uint32_t>(samValue));
|
||||
break;
|
||||
case CL_SAMPLER_ADDRESSING_MODE:
|
||||
errcodeRet = addressingMode.setValue(samValue);
|
||||
errcodeRet = addressingMode.setValue(static_cast<uint32_t>(samValue));
|
||||
break;
|
||||
case CL_SAMPLER_FILTER_MODE:
|
||||
errcodeRet = filterMode.setValue(samValue);
|
||||
errcodeRet = filterMode.setValue(static_cast<uint32_t>(samValue));
|
||||
break;
|
||||
case CL_SAMPLER_MIP_FILTER_MODE:
|
||||
errcodeRet = mipFilterMode.setValue(static_cast<uint32_t>(samValue));
|
||||
break;
|
||||
case CL_SAMPLER_LOD_MIN: {
|
||||
SamplerLodProperty lodData;
|
||||
lodData.data = samValue;
|
||||
errcodeRet = lodMin.setValue(lodData.lod);
|
||||
break;
|
||||
}
|
||||
case CL_SAMPLER_LOD_MAX: {
|
||||
SamplerLodProperty lodData;
|
||||
lodData.data = samValue;
|
||||
errcodeRet = lodMax.setValue(lodData.lod);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
errcodeRet = CL_INVALID_VALUE;
|
||||
break;
|
||||
@@ -127,7 +155,9 @@ Sampler *Sampler::create(Context *context,
|
||||
|
||||
Sampler *sampler = nullptr;
|
||||
if (errcodeRet == CL_SUCCESS) {
|
||||
sampler = create(context, normalizedCoords.value, addressingMode.value, filterMode.value, errcodeRet);
|
||||
sampler = create(context, normalizedCoords.value, addressingMode.value, filterMode.value,
|
||||
mipFilterMode.value, lodMin.value, lodMax.value,
|
||||
errcodeRet);
|
||||
}
|
||||
|
||||
return sampler;
|
||||
@@ -169,6 +199,21 @@ cl_int Sampler::getInfo(cl_sampler_info paramName, size_t paramValueSize,
|
||||
pValue = &this->filterMode;
|
||||
break;
|
||||
|
||||
case CL_SAMPLER_MIP_FILTER_MODE:
|
||||
valueSize = sizeof(cl_filter_mode);
|
||||
pValue = &this->mipFilterMode;
|
||||
break;
|
||||
|
||||
case CL_SAMPLER_LOD_MIN:
|
||||
valueSize = sizeof(float);
|
||||
pValue = &this->lodMin;
|
||||
break;
|
||||
|
||||
case CL_SAMPLER_LOD_MAX:
|
||||
valueSize = sizeof(float);
|
||||
pValue = &this->lodMax;
|
||||
break;
|
||||
|
||||
case CL_SAMPLER_REFERENCE_COUNT:
|
||||
refCount = static_cast<cl_uint>(this->getReference());
|
||||
valueSize = sizeof(refCount);
|
||||
|
||||
@@ -33,6 +33,11 @@ struct OpenCLObjectMapper<_cl_sampler> {
|
||||
typedef class Sampler DerivedType;
|
||||
};
|
||||
|
||||
union SamplerLodProperty {
|
||||
cl_sampler_properties data;
|
||||
float lod;
|
||||
};
|
||||
|
||||
class Sampler : public BaseObject<_cl_sampler> {
|
||||
public:
|
||||
static const cl_ulong objectMagic = 0x4684913AC213EF00LL;
|
||||
@@ -40,8 +45,17 @@ class Sampler : public BaseObject<_cl_sampler> {
|
||||
|
||||
static Sampler *create(Context *context, cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode, cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode, float lodMin, float lodMax,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static Sampler *create(Context *context, cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode, cl_filter_mode filterMode,
|
||||
cl_int &errcodeRet) {
|
||||
return Sampler::create(context, normalizedCoordinates, addressingMode, filterMode,
|
||||
CL_FILTER_NEAREST, 0.0f, std::numeric_limits<float>::max(),
|
||||
errcodeRet);
|
||||
}
|
||||
|
||||
static Sampler *create(Context *context,
|
||||
const cl_sampler_properties *samplerProperties,
|
||||
cl_int &errcodeRet);
|
||||
@@ -54,6 +68,14 @@ class Sampler : public BaseObject<_cl_sampler> {
|
||||
static size_t getSamplerStateSize(const HardwareInfo &hwInfo);
|
||||
bool isTransformable() const;
|
||||
|
||||
Sampler(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode,
|
||||
float lodMin,
|
||||
float lodMax);
|
||||
|
||||
Sampler(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
@@ -65,30 +87,51 @@ class Sampler : public BaseObject<_cl_sampler> {
|
||||
cl_bool normalizedCoordinates;
|
||||
cl_addressing_mode addressingMode;
|
||||
cl_filter_mode filterMode;
|
||||
cl_filter_mode mipFilterMode;
|
||||
float lodMin;
|
||||
float lodMax;
|
||||
};
|
||||
|
||||
template <typename GfxFamily>
|
||||
struct SamplerHw : public Sampler {
|
||||
void setArg(void *memory) override;
|
||||
void appendSamplerStateParams(typename GfxFamily::SAMPLER_STATE *state);
|
||||
static constexpr float getGenSamplerMaxLod() {
|
||||
return 14.0f;
|
||||
}
|
||||
|
||||
SamplerHw(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode) : Sampler(context,
|
||||
normalizedCoordinates,
|
||||
addressingMode,
|
||||
filterMode) {
|
||||
cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode,
|
||||
float lodMin,
|
||||
float lodMax)
|
||||
: Sampler(context, normalizedCoordinates, addressingMode, filterMode,
|
||||
mipFilterMode, lodMin, lodMax) {
|
||||
}
|
||||
|
||||
SamplerHw(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode)
|
||||
: Sampler(context, normalizedCoordinates, addressingMode, filterMode) {
|
||||
}
|
||||
|
||||
static Sampler *create(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode) {
|
||||
cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode,
|
||||
float lodMin,
|
||||
float lodMax) {
|
||||
return new SamplerHw<GfxFamily>(context,
|
||||
normalizedCoordinates,
|
||||
addressingMode,
|
||||
filterMode);
|
||||
filterMode,
|
||||
mipFilterMode,
|
||||
lodMin,
|
||||
lodMax);
|
||||
}
|
||||
|
||||
static size_t getSamplerStateSize();
|
||||
@@ -97,7 +140,10 @@ struct SamplerHw : public Sampler {
|
||||
typedef Sampler *(*SamplerCreateFunc)(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode);
|
||||
cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode,
|
||||
float lodMin,
|
||||
float lodMax);
|
||||
|
||||
typedef size_t (*getSamplerStateSizeHwFunc)();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "runtime/utilities/numeric.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
template <typename GfxFamily>
|
||||
@@ -65,6 +69,9 @@ void SamplerHw<GfxFamily>::setArg(void *memory) {
|
||||
if (CL_FILTER_LINEAR == filterMode) {
|
||||
minMode = SAMPLER_STATE::MIN_MODE_FILTER_LINEAR;
|
||||
magMode = SAMPLER_STATE::MAG_MODE_FILTER_LINEAR;
|
||||
}
|
||||
|
||||
if (CL_FILTER_LINEAR == mipFilterMode) {
|
||||
mipMode = SAMPLER_STATE::MIP_MODE_FILTER_LINEAR;
|
||||
}
|
||||
|
||||
@@ -90,6 +97,12 @@ void SamplerHw<GfxFamily>::setArg(void *memory) {
|
||||
samplerState->setUAddressMinFilterRoundingEnable(false);
|
||||
samplerState->setUAddressMagFilterRoundingEnable(false);
|
||||
}
|
||||
|
||||
FixedU4D8 minLodValue = FixedU4D8(std::min(getGenSamplerMaxLod(), this->lodMin));
|
||||
FixedU4D8 maxLodValue = FixedU4D8(std::min(getGenSamplerMaxLod(), this->lodMax));
|
||||
samplerState->setMinLod(minLodValue.getRawAccess());
|
||||
samplerState->setMaxLod(maxLodValue.getRawAccess());
|
||||
|
||||
appendSamplerStateParams(samplerState);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ set(RUNTIME_SRCS_UTILITIES_BASE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/heap_allocator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/iflist.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/idlist.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/numeric.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/range.h
|
||||
|
||||
105
runtime/utilities/numeric.h
Normal file
105
runtime/utilities/numeric.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 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"),
|
||||
* 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 <cstdint>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
template <uint8_t NumBits>
|
||||
struct StorageType;
|
||||
|
||||
template <>
|
||||
struct StorageType<8> {
|
||||
using Type = uint8_t;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct StorageType<16> {
|
||||
using Type = uint16_t;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct StorageType<32> {
|
||||
using Type = uint32_t;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct StorageType<64> {
|
||||
using Type = uint64_t;
|
||||
};
|
||||
|
||||
template <uint8_t NumBits>
|
||||
struct StorageType {
|
||||
using Type = typename StorageType<NumBits + 1>::Type;
|
||||
};
|
||||
|
||||
template <uint8_t NumBits>
|
||||
using StorageTypeT = typename StorageType<NumBits>::Type;
|
||||
|
||||
template <uint8_t IntegerBits, uint8_t FractionalBits, uint8_t TotalBits = IntegerBits + FractionalBits>
|
||||
struct UnsignedFixedPointValue {
|
||||
UnsignedFixedPointValue(float v) {
|
||||
fromFloatingPoint(v);
|
||||
}
|
||||
|
||||
StorageTypeT<TotalBits> &getRawAccess() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
static constexpr float getMaxRepresentableFloat() {
|
||||
return getMaxRepresentableFloatingPointValue<float>();
|
||||
}
|
||||
|
||||
float asFloat() {
|
||||
return asFloatPointType<float>();
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename FloatingType>
|
||||
static constexpr FloatingType getMaxRepresentableFloatingPointValue() {
|
||||
return static_cast<FloatingType>(
|
||||
static_cast<FloatingType>((1U << IntegerBits) - 1) + (static_cast<FloatingType>((1U << FractionalBits) - 1) / (1U << FractionalBits)));
|
||||
}
|
||||
|
||||
template <typename FloatingType>
|
||||
void fromFloatingPoint(FloatingType val) {
|
||||
auto maxFloatVal = getMaxRepresentableFloatingPointValue<FloatingType>();
|
||||
// clamp to [0, maxFloatVal]
|
||||
val = (val < FloatingType{0}) ? FloatingType{0} : val;
|
||||
val = (val > maxFloatVal) ? maxFloatVal : val;
|
||||
|
||||
// scale to fixed point representation
|
||||
this->storage = static_cast<StorageTypeT<TotalBits>>(val * (1U << FractionalBits));
|
||||
}
|
||||
|
||||
template <typename FloatingType>
|
||||
FloatingType asFloatPointType() {
|
||||
return static_cast<FloatingType>(storage) / (1U << FractionalBits);
|
||||
}
|
||||
|
||||
StorageTypeT<TotalBits> storage = 0;
|
||||
};
|
||||
|
||||
using FixedU4D8 = UnsignedFixedPointValue<4, 8>;
|
||||
}
|
||||
@@ -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"),
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "cl_api_tests.h"
|
||||
#include "runtime/context/context.h"
|
||||
#include "runtime/sampler/sampler.h"
|
||||
#include "CL/cl_ext.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
@@ -212,4 +213,34 @@ INSTANTIATE_TEST_CASE_P(api,
|
||||
::testing::ValuesIn(NormalizdProperties),
|
||||
::testing::ValuesIn(AddressingProperties),
|
||||
::testing::ValuesIn(FilterProperties)));
|
||||
|
||||
TEST_F(clCreateSamplerWithPropertiesTests, whenCreatedWithMipMapDataThenSamplerIsProperlyPopulated) {
|
||||
SamplerLodProperty minLodProperty;
|
||||
SamplerLodProperty maxLodProperty;
|
||||
minLodProperty.lod = 2.0f;
|
||||
maxLodProperty.lod = 3.0f;
|
||||
cl_sampler_properties mipMapFilteringMode = CL_FILTER_LINEAR;
|
||||
cl_sampler_properties properties[] =
|
||||
{
|
||||
CL_SAMPLER_NORMALIZED_COORDS, 0,
|
||||
CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
|
||||
CL_SAMPLER_FILTER_MODE, CL_FILTER_LINEAR,
|
||||
CL_SAMPLER_MIP_FILTER_MODE, mipMapFilteringMode,
|
||||
CL_SAMPLER_LOD_MIN, minLodProperty.data,
|
||||
CL_SAMPLER_LOD_MAX, maxLodProperty.data,
|
||||
0};
|
||||
|
||||
cl_sampler clSampler = clCreateSamplerWithProperties(
|
||||
pContext,
|
||||
properties,
|
||||
&retVal);
|
||||
|
||||
auto sampler = castToObject<Sampler>(clSampler);
|
||||
ASSERT_NE(nullptr, sampler);
|
||||
EXPECT_EQ(mipMapFilteringMode, sampler->mipFilterMode);
|
||||
EXPECT_EQ(minLodProperty.lod, sampler->lodMin);
|
||||
EXPECT_EQ(maxLodProperty.lod, sampler->lodMax);
|
||||
clReleaseSampler(sampler);
|
||||
}
|
||||
|
||||
} // namespace ULT
|
||||
|
||||
@@ -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"),
|
||||
@@ -30,7 +30,11 @@ struct MockSampler : public Sampler {
|
||||
MockSampler(Context *context,
|
||||
cl_bool normalizedCoordinates,
|
||||
cl_addressing_mode addressingMode,
|
||||
cl_filter_mode filterMode) : Sampler(context, normalizedCoordinates, addressingMode, filterMode) {
|
||||
cl_filter_mode filterMode,
|
||||
cl_filter_mode mipFilterMode = CL_FILTER_NEAREST,
|
||||
float lodMin = 0.0f,
|
||||
float lodMax = 0.0f) : Sampler(context, normalizedCoordinates, addressingMode, filterMode,
|
||||
mipFilterMode, lodMin, lodMax) {
|
||||
}
|
||||
|
||||
cl_context getContext() const {
|
||||
|
||||
@@ -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"),
|
||||
@@ -57,7 +57,7 @@ TEST_P(GetSamplerInfo, valid_returnsSuccess) {
|
||||
auto addressingMode = CL_ADDRESS_MIRRORED_REPEAT;
|
||||
auto filterMode = CL_FILTER_NEAREST;
|
||||
auto sampler = Sampler::create(&context, normalizedCoords, addressingMode,
|
||||
filterMode, retVal);
|
||||
filterMode, CL_FILTER_NEAREST, 2.0f, 3.0f, retVal);
|
||||
|
||||
size_t sizeReturned = 0;
|
||||
retVal = sampler->getInfo(param, 0, nullptr, &sizeReturned);
|
||||
@@ -78,7 +78,10 @@ cl_sampler_info samplerInfoParams[] = {
|
||||
CL_SAMPLER_CONTEXT,
|
||||
CL_SAMPLER_NORMALIZED_COORDS,
|
||||
CL_SAMPLER_ADDRESSING_MODE,
|
||||
CL_SAMPLER_FILTER_MODE};
|
||||
CL_SAMPLER_FILTER_MODE,
|
||||
CL_SAMPLER_MIP_FILTER_MODE,
|
||||
CL_SAMPLER_LOD_MIN,
|
||||
CL_SAMPLER_LOD_MAX};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
Sampler_,
|
||||
|
||||
@@ -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"),
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "runtime/kernel/kernel.h"
|
||||
#include "runtime/sampler/sampler.h"
|
||||
#include "runtime/helpers/sampler_helpers.h"
|
||||
#include "runtime/utilities/numeric.h"
|
||||
#include "unit_tests/fixtures/device_fixture.h"
|
||||
#include "test.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
@@ -377,6 +378,38 @@ INSTANTIATE_TEST_CASE_P(SamplerSetArg,
|
||||
AddressingModeTest,
|
||||
::testing::ValuesIn(addressingModeCases));
|
||||
|
||||
HWTEST_F(SamplerSetArgTest, setKernelArgSamplerWithMipMaps) {
|
||||
typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE;
|
||||
|
||||
FixedU4D8 minLod = 2.0f;
|
||||
FixedU4D8 maxLod = 3.0f;
|
||||
|
||||
sampler = Sampler::create(
|
||||
context,
|
||||
CL_TRUE,
|
||||
CL_ADDRESS_NONE,
|
||||
CL_FILTER_NEAREST,
|
||||
CL_FILTER_LINEAR,
|
||||
minLod.asFloat(), maxLod.asFloat(),
|
||||
retVal);
|
||||
|
||||
cl_sampler samplerObj = sampler;
|
||||
|
||||
retVal = pKernel->setArg(
|
||||
0,
|
||||
sizeof(samplerObj),
|
||||
&samplerObj);
|
||||
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
auto samplerState = reinterpret_cast<const SAMPLER_STATE *>(
|
||||
ptrOffset(pKernel->getDynamicStateHeap(),
|
||||
pKernelInfo->kernelArgInfo[0].offsetHeap));
|
||||
|
||||
EXPECT_EQ(FamilyType::SAMPLER_STATE::MIP_MODE_FILTER_LINEAR, samplerState->getMipModeFilter());
|
||||
EXPECT_EQ(minLod.getRawAccess(), samplerState->getMinLod());
|
||||
EXPECT_EQ(maxLod.getRawAccess(), samplerState->getMaxLod());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
struct FilterModeTest
|
||||
: public SamplerSetArgFixture,
|
||||
@@ -418,7 +451,7 @@ HWTEST_P(FilterModeTest, setKernelArgSampler) {
|
||||
} else {
|
||||
EXPECT_EQ(SAMPLER_STATE::MIN_MODE_FILTER_LINEAR, samplerState->getMinModeFilter());
|
||||
EXPECT_EQ(SAMPLER_STATE::MAG_MODE_FILTER_LINEAR, samplerState->getMagModeFilter());
|
||||
EXPECT_EQ(SAMPLER_STATE::MIP_MODE_FILTER_LINEAR, samplerState->getMipModeFilter());
|
||||
EXPECT_EQ(SAMPLER_STATE::MIP_MODE_FILTER_NEAREST, samplerState->getMipModeFilter());
|
||||
EXPECT_TRUE(samplerState->getUAddressMinFilterRoundingEnable());
|
||||
EXPECT_TRUE(samplerState->getUAddressMagFilterRoundingEnable());
|
||||
EXPECT_TRUE(samplerState->getVAddressMinFilterRoundingEnable());
|
||||
|
||||
@@ -42,6 +42,7 @@ TEST(SkuInfoTransferTest, givenWaTableWhenFillingStructureForGmmThenCopyOnlySele
|
||||
_WA_TABLE requestedWaTable = {};
|
||||
_WA_TABLE refWaTable = {};
|
||||
WorkaroundTable waTable;
|
||||
refWaTable = {};
|
||||
memset(&waTable, 1, sizeof(WorkaroundTable));
|
||||
SkuInfoTransfer::transferWaTableForGmm(&requestedWaTable, &waTable);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ set(IGDRCL_SRCS_tests_utilities
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_reader_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/directory_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/heap_allocator_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/numeric_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/reference_tracked_object_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spinlock_tests.cpp
|
||||
|
||||
72
unit_tests/utilities/numeric_tests.cpp
Normal file
72
unit_tests/utilities/numeric_tests.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 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"),
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
#include "runtime/utilities/numeric.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
TEST(StorageTypeTest, whenGivenNumberOfBitsThenPicksIntegerTypeThatIsLargeEnough) {
|
||||
static_assert(std::is_same<uint8_t, StorageTypeT<0>>::value, "");
|
||||
static_assert(std::is_same<uint8_t, StorageTypeT<1>>::value, "");
|
||||
static_assert(std::is_same<uint8_t, StorageTypeT<8>>::value, "");
|
||||
|
||||
static_assert(std::is_same<uint16_t, StorageTypeT<9>>::value, "");
|
||||
static_assert(std::is_same<uint16_t, StorageTypeT<16>>::value, "");
|
||||
|
||||
static_assert(std::is_same<uint32_t, StorageTypeT<17>>::value, "");
|
||||
static_assert(std::is_same<uint32_t, StorageTypeT<32>>::value, "");
|
||||
|
||||
static_assert(std::is_same<uint64_t, StorageTypeT<33>>::value, "");
|
||||
static_assert(std::is_same<uint64_t, StorageTypeT<60>>::value, "");
|
||||
static_assert(std::is_same<uint64_t, StorageTypeT<64>>::value, "");
|
||||
}
|
||||
|
||||
TEST(FixedU4D8, whenGetMaxRepresentableFloatingPointValueIsCalledThenProperValueIsReturned) {
|
||||
constexpr float maxU4D8 = 15.99609375f;
|
||||
static_assert(maxU4D8 == FixedU4D8::getMaxRepresentableFloat(), "");
|
||||
}
|
||||
|
||||
TEST(FixedU4D8, whenCreatingFromTooBigFloatThenValueIsClamped) {
|
||||
constexpr float maxU4D8 = FixedU4D8::getMaxRepresentableFloat();
|
||||
FixedU4D8 u4d8Max{maxU4D8};
|
||||
FixedU4D8 u4d8MaxPlus1{maxU4D8 + 1};
|
||||
EXPECT_EQ(u4d8Max.getRawAccess(), u4d8MaxPlus1.getRawAccess());
|
||||
EXPECT_EQ((1U << (4 + 8)) - 1, u4d8Max.getRawAccess()); // all 12 bits should be set
|
||||
EXPECT_EQ(maxU4D8, u4d8Max.asFloat());
|
||||
}
|
||||
|
||||
TEST(FixedU4D8, whenCreatingFromNegativeFloatThenValueIsClamped) {
|
||||
FixedU4D8 u4d8Zero{0.0f};
|
||||
FixedU4D8 u4d8Minus1{-1.0f};
|
||||
EXPECT_EQ(u4d8Zero.getRawAccess(), u4d8Minus1.getRawAccess());
|
||||
EXPECT_EQ(0U, u4d8Zero.getRawAccess()); // all bits should be cleaned
|
||||
EXPECT_EQ(0.0f, u4d8Zero.asFloat());
|
||||
}
|
||||
|
||||
TEST(FixedU4D8, whenCreatingFromRepresentableFloatThenCorrectValueIsPreserved) {
|
||||
constexpr float someValue = 3.5f;
|
||||
FixedU4D8 u4d8{someValue};
|
||||
EXPECT_EQ(someValue, u4d8.asFloat());
|
||||
}
|
||||
Reference in New Issue
Block a user