1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "opencl/source/api/cl_types.h"
#include "opencl/source/helpers/base_object.h"
#include <vector>
namespace NEO {
class Context;
struct HardwareInfo;
template <>
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;
static const uint32_t samplerStateArrayAlignment = 64;
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);
cl_int getInfo(cl_sampler_info paramName, size_t paramValueSize,
void *paramValue, size_t *paramValueSizeRet);
virtual void setArg(void *memory) = 0;
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,
cl_filter_mode filterMode);
unsigned int getSnapWaValue() const;
cl_context context;
cl_bool normalizedCoordinates;
cl_addressing_mode addressingMode;
cl_filter_mode filterMode;
cl_filter_mode mipFilterMode;
float lodMin;
float lodMax;
protected:
void storeProperties(const cl_sampler_properties *properties);
std::vector<uint64_t> propertiesVector;
};
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,
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 mipFilterMode,
float lodMin,
float lodMax) {
return new SamplerHw<GfxFamily>(context,
normalizedCoordinates,
addressingMode,
filterMode,
mipFilterMode,
lodMin,
lodMax);
}
static size_t getSamplerStateSize();
};
typedef Sampler *(*SamplerCreateFunc)(Context *context,
cl_bool normalizedCoordinates,
cl_addressing_mode addressingMode,
cl_filter_mode filterMode,
cl_filter_mode mipFilterMode,
float lodMin,
float lodMax);
typedef size_t (*getSamplerStateSizeHwFunc)();
template <>
inline Sampler *castToObject<Sampler>(const void *object) {
auto clSamplerObj = reinterpret_cast<const _cl_sampler *>(object);
return castToObject<Sampler>(const_cast<cl_sampler>(clSamplerObj));
}
} // namespace NEO
|