Files
TheRock/rocm-systems/projects/clr/rocclr/platform/sampler.hpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

136 lines
4.3 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#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),
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
uint addressMode_[3]; //!< address modes in X, Y and Z
public:
Sampler(Context& context, //!< context for OCL
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;
for (int i = 0; i < 3; i++) addressMode_[i] = addrMode;
// 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;
}
}
Sampler(Context& context, //!< context for Hip
bool normCoords, //!< normalized coordinates
const uint addrMode[3], //!< adressing modes in X, Y and Z directions
uint filterMode, //!< filter mode
uint mipFilterMode, //!< mip filter mode
float minLod, //!< min level of detail
float maxLod //!< max level of detail
)
: Sampler(context, normCoords, addrMode[0], filterMode, mipFilterMode, minLod, maxLod) {
addressMode_[1] = addrMode[1];
addressMode_[2] = addrMode[2];
}
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)) {
ClPrint(amd::LOG_DETAIL_DEBUG, amd::LOG_RESOURCE,
"Sampler creation failed for device: 0x%x \n", dev);
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_; }
const uint* addessMode() const { return addressMode_; }
bool normalizedCoords() const { return (state_ & StateNormalizedCoordsTrue) ? true : false; }
uint inline addressingMode(const int index = 0) const { return addressMode_[index]; }
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_*/