Skip to content

Commit

Permalink
style: Reformat with clang-format 17 (modified PR 1761)
Browse files Browse the repository at this point in the history
Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Feb 1, 2024
1 parent 5da8e8c commit 90d94ca
Show file tree
Hide file tree
Showing 23 changed files with 182 additions and 547 deletions.
25 changes: 5 additions & 20 deletions src/include/OSL/device_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,21 @@ template<class T> class device_ptr {
#ifdef __CUDA_ARCH__
/// On device, act as a pointer. None of these things are allowed on the
/// host.
T* operator->() const
{
return m_ptr;
}
T& operator*() const
{
return *m_ptr;
}
T* operator->() const { return m_ptr; }
T& operator*() const { return *m_ptr; }
#endif

/// Extract the raw device-side pointer. Use with caution! On the host,
/// this will not point to valid memory.
T* d_get() const
{
return m_ptr;
}
T* d_get() const { return m_ptr; }

/// Evaluate as bool is a null pointer check.
operator bool() const noexcept
{
return m_ptr != nullptr;
}
operator bool() const noexcept { return m_ptr != nullptr; }

/// Reset the pointer to `dptr`, which must be a device-side raw pointer,
/// or null. Since this device_ptr is non-owning, any previous value is
/// simply overwritten.
void reset(T* dptr = nullptr)
{
m_ptr = dptr;
}
void reset(T* dptr = nullptr) { m_ptr = dptr; }

private:
T* m_ptr = nullptr; // underlying pointer, initializes to null
Expand Down
10 changes: 2 additions & 8 deletions src/include/OSL/device_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ struct DeviceString {
// In OptiX 7 we can't return the string's contents. Make this a compile
// time error.
#ifndef __CUDA_ARCH__
OSL_HOSTDEVICE const char* c_str() const
{
return m_chars;
}
OSL_HOSTDEVICE const char* c_str() const { return m_chars; }
#endif

OSL_HOSTDEVICE bool operator==(const DeviceString& other) const
Expand All @@ -81,10 +78,7 @@ struct DeviceString {
return hash() != other;
}

OSL_HOSTDEVICE operator size_t() const
{
return hash();
}
OSL_HOSTDEVICE operator size_t() const { return hash(); }

#endif
};
Expand Down
45 changes: 9 additions & 36 deletions src/include/OSL/mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,13 @@ template<int WidthT> class Mask {
}


OSL_FORCEINLINE ValueType value() const
{
return m_value;
}
OSL_FORCEINLINE ValueType value() const { return m_value; }

// count number of active bits
OSL_FORCEINLINE int count() const
{
return OSL::popcount(m_value);
}
OSL_FORCEINLINE int count() const { return OSL::popcount(m_value); }

// NOTE: undefined result if no bits are on
OSL_FORCEINLINE int first_on() const
{
return OSL::countr_zero(m_value);
}
OSL_FORCEINLINE int first_on() const { return OSL::countr_zero(m_value); }

OSL_FORCEINLINE Mask invert() const
{
Expand Down Expand Up @@ -239,10 +230,7 @@ template<int WidthT> class Mask {
return (m_value != static_cast<ValueType>(0));
}

OSL_FORCEINLINE bool any_off() const
{
return (m_value < valid_bits);
}
OSL_FORCEINLINE bool any_off() const { return (m_value < valid_bits); }

OSL_FORCEINLINE bool any_off(const Mask& mask) const
{
Expand All @@ -257,39 +245,27 @@ template<int WidthT> class Mask {
// So really only set_on or set_off is required
// Choose to not provide a generic set(int lane, bool flag)

OSL_FORCEINLINE void set_on(int lane)
{
m_value |= (1 << lane);
}
OSL_FORCEINLINE void set_on(int lane) { m_value |= (1 << lane); }

OSL_FORCEINLINE void set_on_if(int lane, bool cond)
{
m_value |= (cond << lane);
}

OSL_FORCEINLINE void set_all_on()
{
m_value = valid_bits;
}
OSL_FORCEINLINE void set_all_on() { m_value = valid_bits; }
OSL_FORCEINLINE void set_count_on(int count)
{
m_value = valid_bits >> (width - count);
}

OSL_FORCEINLINE void set_off(int lane)
{
m_value &= (~(1 << lane));
}
OSL_FORCEINLINE void set_off(int lane) { m_value &= (~(1 << lane)); }

OSL_FORCEINLINE void set_off_if(int lane, bool cond)
{
m_value &= (~(cond << lane));
}

OSL_FORCEINLINE void set_all_off()
{
m_value = static_cast<ValueType>(0);
}
OSL_FORCEINLINE void set_all_off() { m_value = static_cast<ValueType>(0); }

OSL_FORCEINLINE bool operator==(const Mask& other) const
{
Expand Down Expand Up @@ -323,10 +299,7 @@ template<int WidthT> class Mask {
return Mask(m_value | other.m_value);
}

OSL_FORCEINLINE Mask operator~() const
{
return invert();
}
OSL_FORCEINLINE Mask operator~() const { return invert(); }


template<int MinOccupancyT, int MaxOccupancyT = width, typename FunctorT>
Expand Down
10 changes: 2 additions & 8 deletions src/include/OSL/oslclosure.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,8 @@ OSL_ALIGNAS(16) ClosureComponent : public ClosureColor
Vec3 w; ///< Weight of this component

/// Handy method for getting the parameter memory as a void*.
OSL_HOSTDEVICE void* data()
{
return (char*)(this + 1);
}
OSL_HOSTDEVICE const void* data() const
{
return (const char*)(this + 1);
}
OSL_HOSTDEVICE void* data() { return (char*)(this + 1); }
OSL_HOSTDEVICE const void* data() const { return (const char*)(this + 1); }

/// Handy methods for extracting the underlying parameters as a struct
template<typename T> OSL_HOSTDEVICE const T* as() const
Expand Down
3 changes: 1 addition & 2 deletions src/include/OSL/rendererservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ struct ShaderGlobals;
class ShaderGroup;

// Tags for polymorphic dispatch
template<int SimdWidthT> class WidthOf {
};
template<int SimdWidthT> class WidthOf {};


/// Opaque pointer to whatever the renderer uses to represent a
Expand Down
38 changes: 13 additions & 25 deletions src/include/OSL/wide.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,13 @@ struct alignas(VecReg<WidthT>) BlockOfBuiltin {

// Specializations
template<int WidthT>
struct Block<float, WidthT> : public BlockOfBuiltin<float, WidthT> {
};
struct Block<float, WidthT> : public BlockOfBuiltin<float, WidthT> {};

template<int WidthT>
struct Block<int, WidthT> : public BlockOfBuiltin<int, WidthT> {
};
struct Block<int, WidthT> : public BlockOfBuiltin<int, WidthT> {};

template<typename DataT, int WidthT>
struct Block<DataT*, WidthT> : public BlockOfBuiltin<DataT*, WidthT> {
};
struct Block<DataT*, WidthT> : public BlockOfBuiltin<DataT*, WidthT> {};


// Vec4 isn't used by external interfaces, but some internal
Expand Down Expand Up @@ -2283,15 +2280,9 @@ template<typename DataT, int WidthT> struct MaskedLaneProxy {
// visibility to end user whose IDE
// might display these methods vs. free
// functions
OSL_FORCEINLINE bool is_on() const
{
return m_mask.is_on(m_lane);
}
OSL_FORCEINLINE bool is_on() const { return m_mask.is_on(m_lane); }

OSL_FORCEINLINE bool is_off() const
{
return m_mask.is_off(m_lane);
}
OSL_FORCEINLINE bool is_off() const { return m_mask.is_off(m_lane); }

private:
Block<DataT, WidthT>& m_ref_wide_data;
Expand Down Expand Up @@ -2353,15 +2344,9 @@ struct MaskedArrayLaneProxy {
// visibility to end user whose IDE
// might display these methods vs. free
// functions
OSL_FORCEINLINE bool is_on() const
{
return m_mask.is_on(m_lane);
}
OSL_FORCEINLINE bool is_on() const { return m_mask.is_on(m_lane); }

OSL_FORCEINLINE bool is_off() const
{
return m_mask.is_off(m_lane);
}
OSL_FORCEINLINE bool is_off() const { return m_mask.is_off(m_lane); }

OSL_FORCEINLINE MaskedLaneProxy<DataT, WidthT>
operator[](int array_index) const
Expand Down Expand Up @@ -2726,7 +2711,8 @@ struct MaskedDeriv : public Masked<DataT, WidthT> {
template<typename FirstT, typename... ListT,
std::enable_if_t<std::is_same<typename std::decay<FirstT>::type,
MaskedDeriv>::value,
bool> = true>
bool>
= true>
OSL_FORCEINLINE MaskedDeriv(FirstT&& first, ListT&&... argList)
: Masked<DataT, WidthT>(std::forward<FirstT>(first),
std::forward<ListT>(argList)...)
Expand All @@ -2737,7 +2723,8 @@ struct MaskedDeriv : public Masked<DataT, WidthT> {
template<typename FirstT, typename... ListT,
std::enable_if_t<!std::is_same<typename std::decay<FirstT>::type,
MaskedDeriv>::value,
bool> = true>
bool>
= true>
OSL_FORCEINLINE MaskedDeriv(FirstT&& first, ListT&&... argList)
: Masked<DataT, WidthT>(std::forward<FirstT>(first),
std::forward<ListT>(argList)...,
Expand Down Expand Up @@ -3188,7 +3175,8 @@ template<typename DataT, int DerivIndexT> struct RefDeriv : public Ref<DataT> {
template<typename FirstT, typename... ListT,
std::enable_if_t<!std::is_same<typename std::decay<FirstT>::type,
RefDeriv>::value,
bool> = true>
bool>
= true>
explicit OSL_FORCEINLINE RefDeriv(FirstT&& first, ListT&&... argList)
: Ref<DataT>(std::forward<FirstT>(first),
std::forward<ListT>(argList)...,
Expand Down
Loading

0 comments on commit 90d94ca

Please sign in to comment.