d09ca72f74
SWDEV-79445 - OCL generic changes and code clean-up 1. This change replaces the use of std::map with std::unordered_map to improve lookup/insert time. 2. Replace the use of std::make_pair and std::pair constructor with uniform initialization for cleaner code. 3. Replace the use of std::Container::iterator type with the auto keyword for cleaner code. 4. Use range based for loops where needed. ReviewBoardURL = http://ocltc.amd.com/reviews/r/14517/diff/ Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#4 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#58 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10.cpp#16 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp#9 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#24 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp#13 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#34 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp#17 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl.cpp#57 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_pipe.cpp#7 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#46 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_svm.cpp#23 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/appprofile.hpp#14 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuprogram.cpp#72 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuvirtual.cpp#27 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#216 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#297 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuappprofile.cpp#13 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpubinary.cpp#59 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpucompiler.cpp#158 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#587 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.cpp#322 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprintf.cpp#46 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#237 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#70 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#242 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#415 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#143 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palappprofile.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#22 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#79 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprintf.cpp#9 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#59 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#60 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#84 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#46 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/CMakeLists.txt#11 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.cpp#4 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.hpp#5 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocbinary.hpp#6 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#42 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccounters.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprintf.cpp#10 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#81 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#81 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#89 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.cpp#24 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#49 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/context.hpp#29 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#129 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#102 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/perfctr.hpp#7 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#91 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.hpp#43 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/sampler.hpp#9 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.cpp#17 edit
169 linhas
4.8 KiB
C++
169 linhas
4.8 KiB
C++
//
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
|
|
#ifndef SAMPLER_HPP_
|
|
#define SAMPLER_HPP_
|
|
|
|
#include "top.hpp"
|
|
#include "platform/object.hpp"
|
|
#include "device/device.hpp"
|
|
|
|
namespace amd {
|
|
|
|
//! Abstraction layer sampler class
|
|
class Sampler : public RuntimeObject {
|
|
public:
|
|
typedef std::unordered_map<Device const*, device::Sampler*> DeviceSamplers;
|
|
|
|
//! \note the sampler states must match the compiler's defines.
|
|
//! See amd_ocl_sys_predef.c
|
|
enum State {
|
|
StateNormalizedCoordsFalse = 0x00,
|
|
StateNormalizedCoordsTrue = 0x01,
|
|
StateNormalizedCoordsMask = (StateNormalizedCoordsFalse | StateNormalizedCoordsTrue),
|
|
StateAddressNone = 0x00,
|
|
StateAddressRepeat = 0x02,
|
|
StateAddressClampToEdge = 0x04,
|
|
StateAddressClamp = 0x06,
|
|
StateAddressMirroredRepeat = 0x08,
|
|
StateAddressMask = (StateAddressNone | StateAddressRepeat | StateAddressMirroredRepeat |
|
|
StateAddressClampToEdge | StateAddressClamp),
|
|
StateFilterNearest = 0x10,
|
|
StateFilterLinear = 0x20,
|
|
StateFilterMask = (StateFilterNearest | StateFilterLinear)
|
|
};
|
|
|
|
private:
|
|
Context& context_; //!< OpenCL context associated with this sampler
|
|
uint32_t state_; //!< Sampler state
|
|
uint mipFilter_; //!< mip filter
|
|
float minLod_; //!< min level of detail
|
|
float maxLod_; //!< max level of detail
|
|
DeviceSamplers deviceSamplers_; //!< Container for the device samplers
|
|
|
|
public:
|
|
Sampler(Context& context, //!< OpenCL context
|
|
bool normCoords, //!< normalized coordinates
|
|
uint addrMode, //!< adressing mode
|
|
uint filterMode, //!< filter mode
|
|
uint mipFilterMode, //!< mip filter mode
|
|
float minLod, //!< min level of detail
|
|
float maxLod //!< max level of detail
|
|
)
|
|
: context_(context),
|
|
mipFilter_(mipFilterMode),
|
|
minLod_(minLod),
|
|
maxLod_(maxLod) { // Packs the sampler state into uint32_t for kernel execution
|
|
state_ = 0;
|
|
|
|
// Set normalized state
|
|
if (normCoords) {
|
|
state_ |= StateNormalizedCoordsTrue;
|
|
} else {
|
|
state_ |= StateNormalizedCoordsFalse;
|
|
}
|
|
|
|
// Program the sampler filter mode
|
|
if (filterMode == CL_FILTER_LINEAR) {
|
|
state_ |= StateFilterLinear;
|
|
} else {
|
|
state_ |= StateFilterNearest;
|
|
}
|
|
|
|
// Program the sampler address mode
|
|
switch (addrMode) {
|
|
case CL_ADDRESS_CLAMP_TO_EDGE:
|
|
state_ |= StateAddressClampToEdge;
|
|
break;
|
|
case CL_ADDRESS_REPEAT:
|
|
state_ |= StateAddressRepeat;
|
|
break;
|
|
case CL_ADDRESS_CLAMP:
|
|
state_ |= StateAddressClamp;
|
|
break;
|
|
case CL_ADDRESS_MIRRORED_REPEAT:
|
|
state_ |= StateAddressMirroredRepeat;
|
|
break;
|
|
case CL_ADDRESS_NONE:
|
|
state_ |= StateAddressNone;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
virtual ~Sampler() {
|
|
for (const auto& it : deviceSamplers_) {
|
|
delete it.second;
|
|
}
|
|
}
|
|
|
|
bool create() {
|
|
for (uint i = 0; i < context_.devices().size(); ++i) {
|
|
device::Sampler* sampler = NULL;
|
|
Device* dev = context_.devices()[i];
|
|
if (!dev->createSampler(*this, &sampler)) {
|
|
return false;
|
|
}
|
|
deviceSamplers_[dev] = sampler;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
device::Sampler* getDeviceSampler(const Device& dev) const {
|
|
auto it = deviceSamplers_.find(&dev);
|
|
if (it != deviceSamplers_.end()) {
|
|
return it->second;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
//! Accessor functions
|
|
Context& context() const { return context_; }
|
|
uint32_t state() const { return state_; }
|
|
uint mipFilter() const { return mipFilter_; }
|
|
float minLod() const { return minLod_; }
|
|
float maxLod() const { return maxLod_; }
|
|
|
|
bool normalizedCoords() const { return (state_ & StateNormalizedCoordsTrue) ? true : false; }
|
|
|
|
uint addressingMode() const {
|
|
uint adressing = 0;
|
|
|
|
// Program the sampler address mode
|
|
switch (state_ & StateAddressMask) {
|
|
case StateAddressRepeat:
|
|
adressing = CL_ADDRESS_REPEAT;
|
|
break;
|
|
case StateAddressClampToEdge:
|
|
adressing = CL_ADDRESS_CLAMP_TO_EDGE;
|
|
break;
|
|
case StateAddressClamp:
|
|
adressing = CL_ADDRESS_CLAMP;
|
|
break;
|
|
case StateAddressMirroredRepeat:
|
|
adressing = CL_ADDRESS_MIRRORED_REPEAT;
|
|
break;
|
|
case StateAddressNone:
|
|
adressing = CL_ADDRESS_NONE;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return adressing;
|
|
}
|
|
|
|
uint filterMode() const {
|
|
return ((state_ & StateFilterMask) == StateFilterNearest) ? CL_FILTER_NEAREST
|
|
: CL_FILTER_LINEAR;
|
|
}
|
|
|
|
//! RTTI internal implementation
|
|
virtual ObjectType objectType() const { return ObjectTypeSampler; }
|
|
};
|
|
|
|
} // namespace amd
|
|
|
|
#endif /*SAMPLER_HPP_*/
|