Rework API graphique Vulkan - EnTT pour ECS + Chargement modèle 3D assimp + SDL3 pour events input et fenetre + mesh texture camera transform ok + attention tous les assets nouveaus ne sont pas commités et il y a du code test en dur dans scene addentity + restructuration globale
This commit is contained in:
191
lib/All/slang/include/slang-com-helper.h
Normal file
191
lib/All/slang/include/slang-com-helper.h
Normal file
@@ -0,0 +1,191 @@
|
||||
#ifndef SLANG_COM_HELPER_H
|
||||
#define SLANG_COM_HELPER_H
|
||||
|
||||
/** \file slang-com-helper.h
|
||||
*/
|
||||
|
||||
#include "slang.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <iterator>
|
||||
|
||||
/* !!!!!!!!!!!!!!!!!!!!! Macros to help checking SlangResult !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
|
||||
/*! Set SLANG_HANDLE_RESULT_FAIL(x) to code to be executed whenever an error occurs, and is detected
|
||||
* by one of the macros */
|
||||
#ifndef SLANG_HANDLE_RESULT_FAIL
|
||||
#define SLANG_HANDLE_RESULT_FAIL(x)
|
||||
#endif
|
||||
|
||||
//! Helper macro, that makes it easy to add result checking to calls in functions/methods that
|
||||
//! themselves return Result.
|
||||
#define SLANG_RETURN_ON_FAIL(x) \
|
||||
{ \
|
||||
SlangResult _res = (x); \
|
||||
if (SLANG_FAILED(_res)) \
|
||||
{ \
|
||||
SLANG_HANDLE_RESULT_FAIL(_res); \
|
||||
return _res; \
|
||||
} \
|
||||
}
|
||||
//! Helper macro that can be used to test the return value from a call, and will return in a void
|
||||
//! method/function
|
||||
#define SLANG_RETURN_VOID_ON_FAIL(x) \
|
||||
{ \
|
||||
SlangResult _res = (x); \
|
||||
if (SLANG_FAILED(_res)) \
|
||||
{ \
|
||||
SLANG_HANDLE_RESULT_FAIL(_res); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
//! Helper macro that will return false on failure.
|
||||
#define SLANG_RETURN_FALSE_ON_FAIL(x) \
|
||||
{ \
|
||||
SlangResult _res = (x); \
|
||||
if (SLANG_FAILED(_res)) \
|
||||
{ \
|
||||
SLANG_HANDLE_RESULT_FAIL(_res); \
|
||||
return false; \
|
||||
} \
|
||||
}
|
||||
//! Helper macro that will return nullptr on failure.
|
||||
#define SLANG_RETURN_NULL_ON_FAIL(x) \
|
||||
{ \
|
||||
SlangResult _res = (x); \
|
||||
if (SLANG_FAILED(_res)) \
|
||||
{ \
|
||||
SLANG_HANDLE_RESULT_FAIL(_res); \
|
||||
return nullptr; \
|
||||
} \
|
||||
}
|
||||
|
||||
//! Helper macro that will assert if the return code from a call is failure, also returns the
|
||||
//! failure.
|
||||
#define SLANG_ASSERT_ON_FAIL(x) \
|
||||
{ \
|
||||
SlangResult _res = (x); \
|
||||
if (SLANG_FAILED(_res)) \
|
||||
{ \
|
||||
assert(false); \
|
||||
return _res; \
|
||||
} \
|
||||
}
|
||||
//! Helper macro that will assert if the result from a call is a failure, also returns.
|
||||
#define SLANG_ASSERT_VOID_ON_FAIL(x) \
|
||||
{ \
|
||||
SlangResult _res = (x); \
|
||||
if (SLANG_FAILED(_res)) \
|
||||
{ \
|
||||
assert(false); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* !!!!!!!!!!!!!!!!!!!!!!! C++ helpers !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
namespace Slang
|
||||
{
|
||||
|
||||
// Alias SlangResult to Slang::Result
|
||||
typedef SlangResult Result;
|
||||
// Alias SlangUUID to Slang::Guid
|
||||
typedef SlangUUID Guid;
|
||||
|
||||
} // namespace Slang
|
||||
|
||||
// Operator == and != for Guid/SlangUUID
|
||||
|
||||
SLANG_FORCE_INLINE bool operator==(const Slang::Guid& aIn, const Slang::Guid& bIn)
|
||||
{
|
||||
return aIn.data1 == bIn.data1 && aIn.data2 == bIn.data2 && aIn.data3 == bIn.data3 &&
|
||||
std::equal(aIn.data4, aIn.data4 + std::size(aIn.data4), bIn.data4);
|
||||
}
|
||||
|
||||
SLANG_FORCE_INLINE bool operator!=(const Slang::Guid& a, const Slang::Guid& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
/* !!!!!!!! Macros to simplify implementing COM interfaces !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
|
||||
|
||||
/* Assumes underlying implementation has a member m_refCount that is initialized to 0 and can
|
||||
have ++ and -- operate on it. For SLANG_IUNKNOWN_QUERY_INTERFACE to work - must have a method
|
||||
'getInterface' that returns valid pointers for the Guid, or nullptr if not found. */
|
||||
|
||||
#define SLANG_IUNKNOWN_QUERY_INTERFACE \
|
||||
SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface( \
|
||||
SlangUUID const& uuid, \
|
||||
void** outObject) SLANG_OVERRIDE \
|
||||
{ \
|
||||
ISlangUnknown* intf = getInterface(uuid); \
|
||||
if (intf) \
|
||||
{ \
|
||||
addRef(); \
|
||||
*outObject = intf; \
|
||||
return SLANG_OK; \
|
||||
} \
|
||||
return SLANG_E_NO_INTERFACE; \
|
||||
}
|
||||
|
||||
#define SLANG_IUNKNOWN_ADD_REF \
|
||||
SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE \
|
||||
{ \
|
||||
return ++m_refCount; \
|
||||
}
|
||||
|
||||
#define SLANG_IUNKNOWN_RELEASE \
|
||||
SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE \
|
||||
{ \
|
||||
--m_refCount; \
|
||||
if (m_refCount == 0) \
|
||||
{ \
|
||||
delete this; \
|
||||
return 0; \
|
||||
} \
|
||||
return m_refCount; \
|
||||
}
|
||||
|
||||
#define SLANG_IUNKNOWN_ALL \
|
||||
SLANG_IUNKNOWN_QUERY_INTERFACE \
|
||||
SLANG_IUNKNOWN_ADD_REF \
|
||||
SLANG_IUNKNOWN_RELEASE
|
||||
|
||||
// ------------------------ RefObject IUnknown -----------------------------
|
||||
|
||||
#define SLANG_REF_OBJECT_IUNKNOWN_QUERY_INTERFACE \
|
||||
SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface( \
|
||||
SlangUUID const& uuid, \
|
||||
void** outObject) SLANG_OVERRIDE \
|
||||
{ \
|
||||
void* intf = getInterface(uuid); \
|
||||
if (intf) \
|
||||
{ \
|
||||
addReference(); \
|
||||
*outObject = intf; \
|
||||
return SLANG_OK; \
|
||||
} \
|
||||
return SLANG_E_NO_INTERFACE; \
|
||||
}
|
||||
|
||||
#define SLANG_REF_OBJECT_IUNKNOWN_ADD_REF \
|
||||
SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE \
|
||||
{ \
|
||||
return (uint32_t)addReference(); \
|
||||
}
|
||||
#define SLANG_REF_OBJECT_IUNKNOWN_RELEASE \
|
||||
SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE \
|
||||
{ \
|
||||
return (uint32_t)releaseReference(); \
|
||||
}
|
||||
|
||||
#define SLANG_REF_OBJECT_IUNKNOWN_ALL \
|
||||
SLANG_REF_OBJECT_IUNKNOWN_QUERY_INTERFACE \
|
||||
SLANG_REF_OBJECT_IUNKNOWN_ADD_REF \
|
||||
SLANG_REF_OBJECT_IUNKNOWN_RELEASE
|
||||
|
||||
#endif // defined(__cplusplus)
|
||||
|
||||
#endif
|
||||
210
lib/All/slang/include/slang-com-ptr.h
Normal file
210
lib/All/slang/include/slang-com-ptr.h
Normal file
@@ -0,0 +1,210 @@
|
||||
#ifndef SLANG_COM_PTR_H
|
||||
#define SLANG_COM_PTR_H
|
||||
|
||||
#include "slang-com-helper.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <cstddef>
|
||||
|
||||
namespace Slang
|
||||
{
|
||||
|
||||
/*! \brief ComPtr is a simple smart pointer that manages types which implement COM based interfaces.
|
||||
\details A class that implements a COM, must derive from the IUnknown interface or a type that
|
||||
matches it's layout exactly (such as ISlangUnknown). Trying to use this template with a class that
|
||||
doesn't follow these rules, will lead to undefined behavior. This is a 'strong' pointer type, and
|
||||
will AddRef when a non null pointer is set and Release when the pointer leaves scope. Using 'detach'
|
||||
allows a pointer to be removed from the management of the ComPtr. To set the smart pointer to null,
|
||||
there is the method setNull, or alternatively just assign SLANG_NULL/nullptr.
|
||||
|
||||
One edge case using the template is that sometimes you want access as a pointer to a pointer.
|
||||
Sometimes this is to write into the smart pointer, other times to pass as an array. To handle these
|
||||
different behaviors there are the methods readRef and writeRef, which are used instead of the &
|
||||
(ref) operator. For example
|
||||
|
||||
\code
|
||||
Void doSomething(ID3D12Resource** resources, IndexT numResources);
|
||||
// ...
|
||||
ComPtr<ID3D12Resource> resources[3];
|
||||
doSomething(resources[0].readRef(), SLANG_COUNT_OF(resource));
|
||||
\endcode
|
||||
|
||||
A more common scenario writing to the pointer
|
||||
|
||||
\code
|
||||
IUnknown* unk = ...;
|
||||
|
||||
ComPtr<ID3D12Resource> resource;
|
||||
Result res = unk->QueryInterface(resource.writeRef());
|
||||
\endcode
|
||||
*/
|
||||
|
||||
// Enum to force initializing as an attach (without adding a reference)
|
||||
enum InitAttach
|
||||
{
|
||||
INIT_ATTACH
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class ComPtr
|
||||
{
|
||||
public:
|
||||
typedef T Type;
|
||||
typedef ComPtr ThisType;
|
||||
typedef ISlangUnknown* Ptr;
|
||||
|
||||
/// Constructors
|
||||
/// Default Ctor. Sets to nullptr
|
||||
SLANG_FORCE_INLINE ComPtr()
|
||||
: m_ptr(nullptr)
|
||||
{
|
||||
}
|
||||
SLANG_FORCE_INLINE ComPtr(std::nullptr_t)
|
||||
: m_ptr(nullptr)
|
||||
{
|
||||
}
|
||||
/// Sets, and ref counts.
|
||||
SLANG_FORCE_INLINE explicit ComPtr(T* ptr)
|
||||
: m_ptr(ptr)
|
||||
{
|
||||
if (ptr)
|
||||
((Ptr)ptr)->addRef();
|
||||
}
|
||||
/// The copy ctor
|
||||
SLANG_FORCE_INLINE ComPtr(const ThisType& rhs)
|
||||
: m_ptr(rhs.m_ptr)
|
||||
{
|
||||
if (m_ptr)
|
||||
((Ptr)m_ptr)->addRef();
|
||||
}
|
||||
|
||||
/// Ctor without adding to ref count.
|
||||
SLANG_FORCE_INLINE explicit ComPtr(InitAttach, T* ptr)
|
||||
: m_ptr(ptr)
|
||||
{
|
||||
}
|
||||
/// Ctor without adding to ref count
|
||||
SLANG_FORCE_INLINE ComPtr(InitAttach, const ThisType& rhs)
|
||||
: m_ptr(rhs.m_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef SLANG_HAS_MOVE_SEMANTICS
|
||||
/// Move Ctor
|
||||
SLANG_FORCE_INLINE ComPtr(ThisType&& rhs)
|
||||
: m_ptr(rhs.m_ptr)
|
||||
{
|
||||
rhs.m_ptr = nullptr;
|
||||
}
|
||||
/// Move assign
|
||||
SLANG_FORCE_INLINE ComPtr& operator=(ThisType&& rhs)
|
||||
{
|
||||
T* swap = m_ptr;
|
||||
m_ptr = rhs.m_ptr;
|
||||
rhs.m_ptr = swap;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Destructor releases the pointer, assuming it is set
|
||||
SLANG_FORCE_INLINE ~ComPtr()
|
||||
{
|
||||
if (m_ptr)
|
||||
((Ptr)m_ptr)->release();
|
||||
}
|
||||
|
||||
// !!! Operators !!!
|
||||
|
||||
/// Returns the dumb pointer
|
||||
SLANG_FORCE_INLINE operator T*() const { return m_ptr; }
|
||||
|
||||
SLANG_FORCE_INLINE T& operator*() { return *m_ptr; }
|
||||
/// For making method invocations through the smart pointer work through the dumb pointer
|
||||
SLANG_FORCE_INLINE T* operator->() const { return m_ptr; }
|
||||
|
||||
/// Assign
|
||||
SLANG_FORCE_INLINE const ThisType& operator=(const ThisType& rhs);
|
||||
/// Assign from dumb ptr
|
||||
SLANG_FORCE_INLINE T* operator=(T* in);
|
||||
|
||||
/// Get the pointer and don't ref
|
||||
SLANG_FORCE_INLINE T* get() const { return m_ptr; }
|
||||
/// Release a contained nullptr pointer if set
|
||||
SLANG_FORCE_INLINE void setNull();
|
||||
|
||||
/// Detach
|
||||
SLANG_FORCE_INLINE T* detach()
|
||||
{
|
||||
T* ptr = m_ptr;
|
||||
m_ptr = nullptr;
|
||||
return ptr;
|
||||
}
|
||||
/// Set to a pointer without changing the ref count
|
||||
SLANG_FORCE_INLINE void attach(T* in) { m_ptr = in; }
|
||||
|
||||
/// Get ready for writing (nulls contents)
|
||||
SLANG_FORCE_INLINE T** writeRef()
|
||||
{
|
||||
setNull();
|
||||
return &m_ptr;
|
||||
}
|
||||
/// Get for read access
|
||||
SLANG_FORCE_INLINE T* const* readRef() const { return &m_ptr; }
|
||||
|
||||
/// Swap
|
||||
void swap(ThisType& rhs);
|
||||
|
||||
protected:
|
||||
/// Gets the address of the dumb pointer.
|
||||
// Disabled: use writeRef and readRef to get a reference based on usage.
|
||||
#ifndef SLANG_COM_PTR_ENABLE_REF_OPERATOR
|
||||
SLANG_FORCE_INLINE T** operator&() = delete;
|
||||
#endif
|
||||
|
||||
T* m_ptr;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void ComPtr<T>::setNull()
|
||||
{
|
||||
if (m_ptr)
|
||||
{
|
||||
((Ptr)m_ptr)->release();
|
||||
m_ptr = nullptr;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
const ComPtr<T>& ComPtr<T>::operator=(const ThisType& rhs)
|
||||
{
|
||||
if (rhs.m_ptr)
|
||||
((Ptr)rhs.m_ptr)->addRef();
|
||||
if (m_ptr)
|
||||
((Ptr)m_ptr)->release();
|
||||
m_ptr = rhs.m_ptr;
|
||||
return *this;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
T* ComPtr<T>::operator=(T* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
((Ptr)ptr)->addRef();
|
||||
if (m_ptr)
|
||||
((Ptr)m_ptr)->release();
|
||||
m_ptr = ptr;
|
||||
return m_ptr;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void ComPtr<T>::swap(ThisType& rhs)
|
||||
{
|
||||
T* tmp = m_ptr;
|
||||
m_ptr = rhs.m_ptr;
|
||||
rhs.m_ptr = tmp;
|
||||
}
|
||||
|
||||
} // namespace Slang
|
||||
|
||||
#endif // SLANG_COM_PTR_H
|
||||
65
lib/All/slang/include/slang-cpp-host-prelude.h
Normal file
65
lib/All/slang/include/slang-cpp-host-prelude.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef SLANG_CPP_HOST_PRELUDE_H
|
||||
#define SLANG_CPP_HOST_PRELUDE_H
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#define SLANG_COM_PTR_ENABLE_REF_OPERATOR 1
|
||||
|
||||
#include "../source/slang-rt/slang-rt.h"
|
||||
#include "slang-com-ptr.h"
|
||||
#include "slang-cpp-types.h"
|
||||
|
||||
#ifdef SLANG_LLVM
|
||||
#include "slang-llvm.h"
|
||||
#else // SLANG_LLVM
|
||||
#if SLANG_GCC_FAMILY && __GNUC__ < 6
|
||||
#include <cmath>
|
||||
#define SLANG_PRELUDE_STD std::
|
||||
#else
|
||||
#include <math.h>
|
||||
#define SLANG_PRELUDE_STD
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif // SLANG_LLVM
|
||||
|
||||
// Is intptr_t not equal to equal-width sized integer type?
|
||||
#if defined(__APPLE__)
|
||||
#define SLANG_INTPTR_TYPE_IS_DISTINCT 1
|
||||
#else
|
||||
#define SLANG_INTPTR_TYPE_IS_DISTINCT 0
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define SLANG_PRELUDE_SHARED_LIB_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__((__visibility__("default")))
|
||||
// # define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__ ((dllexport))
|
||||
// __attribute__((__visibility__("default")))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define SLANG_PRELUDE_EXTERN_C extern "C"
|
||||
#define SLANG_PRELUDE_EXTERN_C_START \
|
||||
extern "C" \
|
||||
{
|
||||
#define SLANG_PRELUDE_EXTERN_C_END }
|
||||
#else
|
||||
#define SLANG_PRELUDE_EXTERN_C
|
||||
#define SLANG_PRELUDE_EXTERN_C_START
|
||||
#define SLANG_PRELUDE_EXTERN_C_END
|
||||
#endif
|
||||
|
||||
#include "slang-cpp-scalar-intrinsics.h"
|
||||
|
||||
using namespace Slang;
|
||||
|
||||
template<typename TResult, typename... Args>
|
||||
using Slang_FuncType = TResult(SLANG_MCALL*)(Args...);
|
||||
|
||||
#endif
|
||||
333
lib/All/slang/include/slang-cpp-prelude.h
Normal file
333
lib/All/slang/include/slang-cpp-prelude.h
Normal file
@@ -0,0 +1,333 @@
|
||||
#ifndef SLANG_CPP_PRELUDE_H
|
||||
#define SLANG_CPP_PRELUDE_H
|
||||
|
||||
// Because the signature of isnan, isfinite, and is isinf changed in C++, we use the macro
|
||||
// to use the version in the std namespace.
|
||||
// https://stackoverflow.com/questions/39130040/cmath-hides-isnan-in-math-h-in-c14-c11
|
||||
|
||||
#ifdef SLANG_LLVM
|
||||
#include "slang-llvm.h"
|
||||
#else // SLANG_LLVM
|
||||
#if SLANG_GCC_FAMILY && __GNUC__ < 6
|
||||
#include <cmath>
|
||||
#define SLANG_PRELUDE_STD std::
|
||||
#else
|
||||
#include <math.h>
|
||||
#define SLANG_PRELUDE_STD
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif // SLANG_LLVM
|
||||
|
||||
// Is intptr_t not equal to equal-width sized integer type?
|
||||
#if defined(__APPLE__)
|
||||
#define SLANG_INTPTR_TYPE_IS_DISTINCT 1
|
||||
#else
|
||||
#define SLANG_INTPTR_TYPE_IS_DISTINCT 0
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define SLANG_PRELUDE_SHARED_LIB_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__((__visibility__("default")))
|
||||
// # define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__ ((dllexport))
|
||||
// __attribute__((__visibility__("default")))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define SLANG_PRELUDE_EXTERN_C extern "C"
|
||||
#define SLANG_PRELUDE_EXTERN_C_START \
|
||||
extern "C" \
|
||||
{
|
||||
#define SLANG_PRELUDE_EXTERN_C_END }
|
||||
#else
|
||||
#define SLANG_PRELUDE_EXTERN_C
|
||||
#define SLANG_PRELUDE_EXTERN_C_START
|
||||
#define SLANG_PRELUDE_EXTERN_C_END
|
||||
#endif
|
||||
|
||||
#define SLANG_PRELUDE_EXPORT SLANG_PRELUDE_EXTERN_C SLANG_PRELUDE_SHARED_LIB_EXPORT
|
||||
#define SLANG_PRELUDE_EXPORT_START SLANG_PRELUDE_EXTERN_C_START SLANG_PRELUDE_SHARED_LIB_EXPORT
|
||||
#define SLANG_PRELUDE_EXPORT_END SLANG_PRELUDE_EXTERN_C_END
|
||||
|
||||
#ifndef INFINITY
|
||||
// Must overflow for double
|
||||
#define INFINITY float(1e+300 * 1e+300)
|
||||
#endif
|
||||
|
||||
#ifndef SLANG_INFINITY
|
||||
#define SLANG_INFINITY INFINITY
|
||||
#endif
|
||||
|
||||
// Detect the compiler type
|
||||
|
||||
#ifndef SLANG_COMPILER
|
||||
#define SLANG_COMPILER
|
||||
|
||||
/*
|
||||
Compiler defines, see http://sourceforge.net/p/predef/wiki/Compilers/
|
||||
NOTE that SLANG_VC holds the compiler version - not just 1 or 0
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
#if _MSC_VER >= 1900
|
||||
#define SLANG_VC 14
|
||||
#elif _MSC_VER >= 1800
|
||||
#define SLANG_VC 12
|
||||
#elif _MSC_VER >= 1700
|
||||
#define SLANG_VC 11
|
||||
#elif _MSC_VER >= 1600
|
||||
#define SLANG_VC 10
|
||||
#elif _MSC_VER >= 1500
|
||||
#define SLANG_VC 9
|
||||
#else
|
||||
#error "unknown version of Visual C++ compiler"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#define SLANG_CLANG 1
|
||||
#elif defined(__SNC__)
|
||||
#define SLANG_SNC 1
|
||||
#elif defined(__ghs__)
|
||||
#define SLANG_GHS 1
|
||||
#elif defined(__GNUC__) /* note: __clang__, __SNC__, or __ghs__ imply __GNUC__ */
|
||||
#define SLANG_GCC 1
|
||||
#else
|
||||
#error "unknown compiler"
|
||||
#endif
|
||||
/*
|
||||
Any compilers not detected by the above logic are now now explicitly zeroed out.
|
||||
*/
|
||||
#ifndef SLANG_VC
|
||||
#define SLANG_VC 0
|
||||
#endif
|
||||
#ifndef SLANG_CLANG
|
||||
#define SLANG_CLANG 0
|
||||
#endif
|
||||
#ifndef SLANG_SNC
|
||||
#define SLANG_SNC 0
|
||||
#endif
|
||||
#ifndef SLANG_GHS
|
||||
#define SLANG_GHS 0
|
||||
#endif
|
||||
#ifndef SLANG_GCC
|
||||
#define SLANG_GCC 0
|
||||
#endif
|
||||
#endif /* SLANG_COMPILER */
|
||||
|
||||
/*
|
||||
The following section attempts to detect the target platform being compiled for.
|
||||
|
||||
If an application defines `SLANG_PLATFORM` before including this header,
|
||||
they take responsibility for setting any compiler-dependent macros
|
||||
used later in the file.
|
||||
|
||||
Most applications should not need to touch this section.
|
||||
*/
|
||||
#ifndef SLANG_PLATFORM
|
||||
#define SLANG_PLATFORM
|
||||
/**
|
||||
Operating system defines, see http://sourceforge.net/p/predef/wiki/OperatingSystems/
|
||||
*/
|
||||
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_PARTITION_APP
|
||||
#define SLANG_WINRT 1 /* Windows Runtime, either on Windows RT or Windows 8 */
|
||||
#elif defined(XBOXONE)
|
||||
#define SLANG_XBOXONE 1
|
||||
#elif defined(_WIN64) /* note: XBOXONE implies _WIN64 */
|
||||
#define SLANG_WIN64 1
|
||||
#elif defined(_M_PPC)
|
||||
#define SLANG_X360 1
|
||||
#elif defined(_WIN32) /* note: _M_PPC implies _WIN32 */
|
||||
#define SLANG_WIN32 1
|
||||
#elif defined(__ANDROID__)
|
||||
#define SLANG_ANDROID 1
|
||||
#elif defined(__linux__) || defined(__CYGWIN__) /* note: __ANDROID__ implies __linux__ */
|
||||
#define SLANG_LINUX 1
|
||||
#elif defined(__APPLE__) && !defined(SLANG_LLVM)
|
||||
#include "TargetConditionals.h"
|
||||
#if TARGET_OS_MAC
|
||||
#define SLANG_OSX 1
|
||||
#else
|
||||
#define SLANG_IOS 1
|
||||
#endif
|
||||
#elif defined(__APPLE__)
|
||||
// On `slang-llvm` we can't inclue "TargetConditionals.h" in general, so for now assume its
|
||||
// OSX.
|
||||
#define SLANG_OSX 1
|
||||
#elif defined(__CELLOS_LV2__)
|
||||
#define SLANG_PS3 1
|
||||
#elif defined(__ORBIS__)
|
||||
#define SLANG_PS4 1
|
||||
#elif defined(__SNC__) && defined(__arm__)
|
||||
#define SLANG_PSP2 1
|
||||
#elif defined(__ghs__)
|
||||
#define SLANG_WIIU 1
|
||||
#else
|
||||
#error "unknown target platform"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Any platforms not detected by the above logic are now now explicitly zeroed out.
|
||||
*/
|
||||
#ifndef SLANG_WINRT
|
||||
#define SLANG_WINRT 0
|
||||
#endif
|
||||
#ifndef SLANG_XBOXONE
|
||||
#define SLANG_XBOXONE 0
|
||||
#endif
|
||||
#ifndef SLANG_WIN64
|
||||
#define SLANG_WIN64 0
|
||||
#endif
|
||||
#ifndef SLANG_X360
|
||||
#define SLANG_X360 0
|
||||
#endif
|
||||
#ifndef SLANG_WIN32
|
||||
#define SLANG_WIN32 0
|
||||
#endif
|
||||
#ifndef SLANG_ANDROID
|
||||
#define SLANG_ANDROID 0
|
||||
#endif
|
||||
#ifndef SLANG_LINUX
|
||||
#define SLANG_LINUX 0
|
||||
#endif
|
||||
#ifndef SLANG_IOS
|
||||
#define SLANG_IOS 0
|
||||
#endif
|
||||
#ifndef SLANG_OSX
|
||||
#define SLANG_OSX 0
|
||||
#endif
|
||||
#ifndef SLANG_PS3
|
||||
#define SLANG_PS3 0
|
||||
#endif
|
||||
#ifndef SLANG_PS4
|
||||
#define SLANG_PS4 0
|
||||
#endif
|
||||
#ifndef SLANG_PSP2
|
||||
#define SLANG_PSP2 0
|
||||
#endif
|
||||
#ifndef SLANG_WIIU
|
||||
#define SLANG_WIIU 0
|
||||
#endif
|
||||
#endif /* SLANG_PLATFORM */
|
||||
|
||||
/* Shorthands for "families" of compilers/platforms */
|
||||
#define SLANG_GCC_FAMILY (SLANG_CLANG || SLANG_SNC || SLANG_GHS || SLANG_GCC)
|
||||
#define SLANG_WINDOWS_FAMILY (SLANG_WINRT || SLANG_WIN32 || SLANG_WIN64)
|
||||
#define SLANG_MICROSOFT_FAMILY (SLANG_XBOXONE || SLANG_X360 || SLANG_WINDOWS_FAMILY)
|
||||
#define SLANG_LINUX_FAMILY (SLANG_LINUX || SLANG_ANDROID)
|
||||
#define SLANG_APPLE_FAMILY (SLANG_IOS || SLANG_OSX) /* equivalent to #if __APPLE__ */
|
||||
#define SLANG_UNIX_FAMILY \
|
||||
(SLANG_LINUX_FAMILY || SLANG_APPLE_FAMILY) /* shortcut for unix/posix platforms */
|
||||
|
||||
// GCC Specific
|
||||
#if SLANG_GCC_FAMILY
|
||||
|
||||
#if INTPTR_MAX == INT64_MAX
|
||||
#define SLANG_64BIT 1
|
||||
#else
|
||||
#define SLANG_64BIT 0
|
||||
#endif
|
||||
|
||||
#define SLANG_BREAKPOINT(id) __builtin_trap()
|
||||
|
||||
// Use this macro instead of offsetof, because gcc produces warning if offsetof is used on a
|
||||
// non POD type, even though it produces the correct result
|
||||
#define SLANG_OFFSET_OF(T, ELEMENT) (size_t(&((T*)1)->ELEMENT) - 1)
|
||||
#endif // SLANG_GCC_FAMILY
|
||||
|
||||
// Microsoft VC specific
|
||||
#if SLANG_VC
|
||||
|
||||
#define SLANG_BREAKPOINT(id) __debugbreak();
|
||||
|
||||
#endif // SLANG_VC
|
||||
|
||||
// Default impls
|
||||
|
||||
#ifndef SLANG_OFFSET_OF
|
||||
#define SLANG_OFFSET_OF(X, Y) offsetof(X, Y)
|
||||
#endif
|
||||
|
||||
#ifndef SLANG_BREAKPOINT
|
||||
// Make it crash with a write to 0!
|
||||
#define SLANG_BREAKPOINT(id) (*((int*)0) = int(id));
|
||||
#endif
|
||||
|
||||
// If slang.h has been included we don't need any of these definitions
|
||||
#ifndef SLANG_H
|
||||
|
||||
/* Macro for declaring if a method is no throw. Should be set before the return parameter. */
|
||||
#ifndef SLANG_NO_THROW
|
||||
#if SLANG_WINDOWS_FAMILY && !defined(SLANG_DISABLE_EXCEPTIONS)
|
||||
#define SLANG_NO_THROW __declspec(nothrow)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SLANG_NO_THROW
|
||||
#define SLANG_NO_THROW
|
||||
#endif
|
||||
|
||||
/* The `SLANG_STDCALL` and `SLANG_MCALL` defines are used to set the calling
|
||||
convention for interface methods.
|
||||
*/
|
||||
#ifndef SLANG_STDCALL
|
||||
#if SLANG_MICROSOFT_FAMILY
|
||||
#define SLANG_STDCALL __stdcall
|
||||
#else
|
||||
#define SLANG_STDCALL
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SLANG_MCALL
|
||||
#define SLANG_MCALL SLANG_STDCALL
|
||||
#endif
|
||||
|
||||
#ifndef SLANG_FORCE_INLINE
|
||||
#define SLANG_FORCE_INLINE inline
|
||||
#endif
|
||||
|
||||
// TODO(JS): Should these be in slang-cpp-types.h?
|
||||
// They are more likely to clash with slang.h
|
||||
|
||||
struct SlangUUID
|
||||
{
|
||||
uint32_t data1;
|
||||
uint16_t data2;
|
||||
uint16_t data3;
|
||||
uint8_t data4[8];
|
||||
};
|
||||
|
||||
typedef int32_t SlangResult;
|
||||
|
||||
struct ISlangUnknown
|
||||
{
|
||||
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
|
||||
queryInterface(SlangUUID const& uuid, void** outObject) = 0;
|
||||
virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() = 0;
|
||||
virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() = 0;
|
||||
};
|
||||
|
||||
#define SLANG_COM_INTERFACE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
|
||||
public: \
|
||||
SLANG_FORCE_INLINE static const SlangUUID& getTypeGuid() \
|
||||
{ \
|
||||
static const SlangUUID guid = {a, b, c, d0, d1, d2, d3, d4, d5, d6, d7}; \
|
||||
return guid; \
|
||||
}
|
||||
#endif // SLANG_H
|
||||
|
||||
// Includes
|
||||
|
||||
#include "slang-cpp-scalar-intrinsics.h"
|
||||
#include "slang-cpp-types.h"
|
||||
|
||||
// TODO(JS): Hack! Output C++ code from slang can copy uninitialized variables.
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4700)
|
||||
#endif
|
||||
|
||||
#ifndef SLANG_UNROLL
|
||||
#define SLANG_UNROLL
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1354
lib/All/slang/include/slang-cpp-scalar-intrinsics.h
Normal file
1354
lib/All/slang/include/slang-cpp-scalar-intrinsics.h
Normal file
File diff suppressed because it is too large
Load Diff
712
lib/All/slang/include/slang-cpp-types-core.h
Normal file
712
lib/All/slang/include/slang-cpp-types-core.h
Normal file
@@ -0,0 +1,712 @@
|
||||
#ifndef SLANG_PRELUDE_CPP_TYPES_CORE_H
|
||||
#define SLANG_PRELUDE_CPP_TYPES_CORE_H
|
||||
|
||||
#ifndef SLANG_PRELUDE_ASSERT
|
||||
#ifdef SLANG_PRELUDE_ENABLE_ASSERT
|
||||
#define SLANG_PRELUDE_ASSERT(VALUE) assert(VALUE)
|
||||
#else
|
||||
#define SLANG_PRELUDE_ASSERT(VALUE)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Since we are using unsigned arithmatic care is need in this comparison.
|
||||
// It is *assumed* that sizeInBytes >= elemSize. Which means (sizeInBytes >= elemSize) >= 0
|
||||
// Which means only a single test is needed
|
||||
|
||||
// Asserts for bounds checking.
|
||||
// It is assumed index/count are unsigned types.
|
||||
#define SLANG_BOUND_ASSERT(index, count) SLANG_PRELUDE_ASSERT(index < count);
|
||||
#define SLANG_BOUND_ASSERT_BYTE_ADDRESS(index, elemSize, sizeInBytes) \
|
||||
SLANG_PRELUDE_ASSERT(index <= (sizeInBytes - elemSize) && (index & 3) == 0);
|
||||
|
||||
// Macros to zero index if an access is out of range
|
||||
#define SLANG_BOUND_ZERO_INDEX(index, count) index = (index < count) ? index : 0;
|
||||
#define SLANG_BOUND_ZERO_INDEX_BYTE_ADDRESS(index, elemSize, sizeInBytes) \
|
||||
index = (index <= (sizeInBytes - elemSize)) ? index : 0;
|
||||
|
||||
// The 'FIX' macro define how the index is fixed. The default is to do nothing. If
|
||||
// SLANG_ENABLE_BOUND_ZERO_INDEX the fix macro will zero the index, if out of range
|
||||
#ifdef SLANG_ENABLE_BOUND_ZERO_INDEX
|
||||
#define SLANG_BOUND_FIX(index, count) SLANG_BOUND_ZERO_INDEX(index, count)
|
||||
#define SLANG_BOUND_FIX_BYTE_ADDRESS(index, elemSize, sizeInBytes) \
|
||||
SLANG_BOUND_ZERO_INDEX_BYTE_ADDRESS(index, elemSize, sizeInBytes)
|
||||
#define SLANG_BOUND_FIX_FIXED_ARRAY(index, count) SLANG_BOUND_ZERO_INDEX(index, count)
|
||||
#else
|
||||
#define SLANG_BOUND_FIX(index, count)
|
||||
#define SLANG_BOUND_FIX_BYTE_ADDRESS(index, elemSize, sizeInBytes)
|
||||
#define SLANG_BOUND_FIX_FIXED_ARRAY(index, count)
|
||||
#endif
|
||||
|
||||
#ifndef SLANG_BOUND_CHECK
|
||||
#define SLANG_BOUND_CHECK(index, count) \
|
||||
SLANG_BOUND_ASSERT(index, count) SLANG_BOUND_FIX(index, count)
|
||||
#endif
|
||||
|
||||
#ifndef SLANG_BOUND_CHECK_BYTE_ADDRESS
|
||||
#define SLANG_BOUND_CHECK_BYTE_ADDRESS(index, elemSize, sizeInBytes) \
|
||||
SLANG_BOUND_ASSERT_BYTE_ADDRESS(index, elemSize, sizeInBytes) \
|
||||
SLANG_BOUND_FIX_BYTE_ADDRESS(index, elemSize, sizeInBytes)
|
||||
#endif
|
||||
|
||||
#ifndef SLANG_BOUND_CHECK_FIXED_ARRAY
|
||||
#define SLANG_BOUND_CHECK_FIXED_ARRAY(index, count) \
|
||||
SLANG_BOUND_ASSERT(index, count) SLANG_BOUND_FIX_FIXED_ARRAY(index, count)
|
||||
#endif
|
||||
|
||||
struct TypeInfo
|
||||
{
|
||||
size_t typeSize;
|
||||
};
|
||||
|
||||
template<typename T, size_t SIZE>
|
||||
struct FixedArray
|
||||
{
|
||||
const T& operator[](size_t index) const
|
||||
{
|
||||
SLANG_BOUND_CHECK_FIXED_ARRAY(index, SIZE);
|
||||
return m_data[index];
|
||||
}
|
||||
T& operator[](size_t index)
|
||||
{
|
||||
SLANG_BOUND_CHECK_FIXED_ARRAY(index, SIZE);
|
||||
return m_data[index];
|
||||
}
|
||||
|
||||
T m_data[SIZE];
|
||||
};
|
||||
|
||||
// An array that has no specified size, becomes a 'Array'. This stores the size so it can
|
||||
// potentially do bounds checking.
|
||||
template<typename T>
|
||||
struct Array
|
||||
{
|
||||
const T& operator[](size_t index) const
|
||||
{
|
||||
SLANG_BOUND_CHECK(index, count);
|
||||
return data[index];
|
||||
}
|
||||
T& operator[](size_t index)
|
||||
{
|
||||
SLANG_BOUND_CHECK(index, count);
|
||||
return data[index];
|
||||
}
|
||||
|
||||
T* data;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
/* Constant buffers become a pointer to the contained type, so ConstantBuffer<T> becomes T* in C++
|
||||
* code.
|
||||
*/
|
||||
|
||||
template<typename T, int COUNT>
|
||||
struct Vector;
|
||||
|
||||
template<typename T>
|
||||
struct Vector<T, 1>
|
||||
{
|
||||
T x;
|
||||
const T& operator[](size_t /*index*/) const { return x; }
|
||||
T& operator[](size_t /*index*/) { return x; }
|
||||
operator T() const { return x; }
|
||||
Vector() = default;
|
||||
Vector(T scalar) { x = scalar; }
|
||||
template<typename U>
|
||||
Vector(Vector<U, 1> other)
|
||||
{
|
||||
x = (T)other.x;
|
||||
}
|
||||
template<typename U, int otherSize>
|
||||
Vector(Vector<U, otherSize> other)
|
||||
{
|
||||
int minSize = 1;
|
||||
if (otherSize < minSize)
|
||||
minSize = otherSize;
|
||||
for (int i = 0; i < minSize; i++)
|
||||
(*this)[i] = (T)other[i];
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Vector<T, 2>
|
||||
{
|
||||
T x, y;
|
||||
const T& operator[](size_t index) const { return index == 0 ? x : y; }
|
||||
T& operator[](size_t index) { return index == 0 ? x : y; }
|
||||
Vector() = default;
|
||||
Vector(T scalar) { x = y = scalar; }
|
||||
Vector(T _x, T _y)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
}
|
||||
template<typename U>
|
||||
Vector(Vector<U, 2> other)
|
||||
{
|
||||
x = (T)other.x;
|
||||
y = (T)other.y;
|
||||
}
|
||||
template<typename U, int otherSize>
|
||||
Vector(Vector<U, otherSize> other)
|
||||
{
|
||||
int minSize = 2;
|
||||
if (otherSize < minSize)
|
||||
minSize = otherSize;
|
||||
for (int i = 0; i < minSize; i++)
|
||||
(*this)[i] = (T)other[i];
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Vector<T, 3>
|
||||
{
|
||||
T x, y, z;
|
||||
const T& operator[](size_t index) const { return *((T*)(this) + index); }
|
||||
T& operator[](size_t index) { return *((T*)(this) + index); }
|
||||
|
||||
Vector() = default;
|
||||
Vector(T scalar) { x = y = z = scalar; }
|
||||
Vector(T _x, T _y, T _z)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
}
|
||||
template<typename U>
|
||||
Vector(Vector<U, 3> other)
|
||||
{
|
||||
x = (T)other.x;
|
||||
y = (T)other.y;
|
||||
z = (T)other.z;
|
||||
}
|
||||
template<typename U, int otherSize>
|
||||
Vector(Vector<U, otherSize> other)
|
||||
{
|
||||
int minSize = 3;
|
||||
if (otherSize < minSize)
|
||||
minSize = otherSize;
|
||||
for (int i = 0; i < minSize; i++)
|
||||
(*this)[i] = (T)other[i];
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Vector<T, 4>
|
||||
{
|
||||
T x, y, z, w;
|
||||
|
||||
const T& operator[](size_t index) const { return *((T*)(this) + index); }
|
||||
T& operator[](size_t index) { return *((T*)(this) + index); }
|
||||
Vector() = default;
|
||||
Vector(T scalar) { x = y = z = w = scalar; }
|
||||
Vector(T _x, T _y, T _z, T _w)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
w = _w;
|
||||
}
|
||||
template<typename U, int otherSize>
|
||||
Vector(Vector<U, otherSize> other)
|
||||
{
|
||||
int minSize = 4;
|
||||
if (otherSize < minSize)
|
||||
minSize = otherSize;
|
||||
for (int i = 0; i < minSize; i++)
|
||||
(*this)[i] = (T)other[i];
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, int N>
|
||||
SLANG_FORCE_INLINE Vector<T, N> _slang_select(
|
||||
Vector<bool, N> condition,
|
||||
Vector<T, N> v0,
|
||||
Vector<T, N> v1)
|
||||
{
|
||||
Vector<T, N> result;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
result[i] = condition[i] ? v0[i] : v1[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
SLANG_FORCE_INLINE T _slang_select(bool condition, T v0, T v1)
|
||||
{
|
||||
return condition ? v0 : v1;
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
SLANG_FORCE_INLINE T _slang_vector_get_element(Vector<T, N> x, int index)
|
||||
{
|
||||
return x[index];
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
SLANG_FORCE_INLINE const T* _slang_vector_get_element_ptr(const Vector<T, N>* x, int index)
|
||||
{
|
||||
return &((*const_cast<Vector<T, N>*>(x))[index]);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
SLANG_FORCE_INLINE T* _slang_vector_get_element_ptr(Vector<T, N>* x, int index)
|
||||
{
|
||||
return &((*x)[index]);
|
||||
}
|
||||
|
||||
template<typename T, int n, typename OtherT, int m>
|
||||
SLANG_FORCE_INLINE Vector<T, n> _slang_vector_reshape(const Vector<OtherT, m> other)
|
||||
{
|
||||
Vector<T, n> result;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
OtherT otherElement = T(0);
|
||||
if (i < m)
|
||||
otherElement = _slang_vector_get_element(other, i);
|
||||
*_slang_vector_get_element_ptr(&result, i) = (T)otherElement;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef uint32_t uint;
|
||||
|
||||
#define SLANG_VECTOR_BINARY_OP(T, op) \
|
||||
template<int n> \
|
||||
SLANG_FORCE_INLINE Vector<T, n> operator op( \
|
||||
const Vector<T, n>& thisVal, \
|
||||
const Vector<T, n>& other) \
|
||||
{ \
|
||||
Vector<T, n> result; \
|
||||
for (int i = 0; i < n; i++) \
|
||||
result[i] = thisVal[i] op other[i]; \
|
||||
return result; \
|
||||
}
|
||||
#define SLANG_VECTOR_BINARY_COMPARE_OP(T, op) \
|
||||
template<int n> \
|
||||
SLANG_FORCE_INLINE Vector<bool, n> operator op( \
|
||||
const Vector<T, n>& thisVal, \
|
||||
const Vector<T, n>& other) \
|
||||
{ \
|
||||
Vector<bool, n> result; \
|
||||
for (int i = 0; i < n; i++) \
|
||||
result[i] = thisVal[i] op other[i]; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define SLANG_VECTOR_UNARY_OP(T, op) \
|
||||
template<int n> \
|
||||
SLANG_FORCE_INLINE Vector<T, n> operator op(const Vector<T, n>& thisVal) \
|
||||
{ \
|
||||
Vector<T, n> result; \
|
||||
for (int i = 0; i < n; i++) \
|
||||
result[i] = op thisVal[i]; \
|
||||
return result; \
|
||||
}
|
||||
#define SLANG_INT_VECTOR_OPS(T) \
|
||||
SLANG_VECTOR_BINARY_OP(T, +) \
|
||||
SLANG_VECTOR_BINARY_OP(T, -) \
|
||||
SLANG_VECTOR_BINARY_OP(T, *) \
|
||||
SLANG_VECTOR_BINARY_OP(T, /) \
|
||||
SLANG_VECTOR_BINARY_OP(T, &) \
|
||||
SLANG_VECTOR_BINARY_OP(T, |) \
|
||||
SLANG_VECTOR_BINARY_OP(T, &&) \
|
||||
SLANG_VECTOR_BINARY_OP(T, ||) \
|
||||
SLANG_VECTOR_BINARY_OP(T, ^) \
|
||||
SLANG_VECTOR_BINARY_OP(T, %) \
|
||||
SLANG_VECTOR_BINARY_OP(T, >>) \
|
||||
SLANG_VECTOR_BINARY_OP(T, <<) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, >) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, <) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, >=) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, <=) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, ==) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, !=) \
|
||||
SLANG_VECTOR_UNARY_OP(T, !) \
|
||||
SLANG_VECTOR_UNARY_OP(T, ~)
|
||||
#define SLANG_FLOAT_VECTOR_OPS(T) \
|
||||
SLANG_VECTOR_BINARY_OP(T, +) \
|
||||
SLANG_VECTOR_BINARY_OP(T, -) \
|
||||
SLANG_VECTOR_BINARY_OP(T, *) \
|
||||
SLANG_VECTOR_BINARY_OP(T, /) \
|
||||
SLANG_VECTOR_UNARY_OP(T, -) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, >) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, <) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, >=) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, <=) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, ==) \
|
||||
SLANG_VECTOR_BINARY_COMPARE_OP(T, !=)
|
||||
|
||||
SLANG_INT_VECTOR_OPS(bool)
|
||||
SLANG_INT_VECTOR_OPS(int)
|
||||
SLANG_INT_VECTOR_OPS(int8_t)
|
||||
SLANG_INT_VECTOR_OPS(int16_t)
|
||||
SLANG_INT_VECTOR_OPS(int64_t)
|
||||
SLANG_INT_VECTOR_OPS(uint)
|
||||
SLANG_INT_VECTOR_OPS(uint8_t)
|
||||
SLANG_INT_VECTOR_OPS(uint16_t)
|
||||
SLANG_INT_VECTOR_OPS(uint64_t)
|
||||
#if SLANG_INTPTR_TYPE_IS_DISTINCT
|
||||
SLANG_INT_VECTOR_OPS(intptr_t)
|
||||
SLANG_INT_VECTOR_OPS(uintptr_t)
|
||||
#endif
|
||||
|
||||
SLANG_FLOAT_VECTOR_OPS(float)
|
||||
SLANG_FLOAT_VECTOR_OPS(double)
|
||||
|
||||
#define SLANG_VECTOR_INT_NEG_OP(T) \
|
||||
template<int N> \
|
||||
Vector<T, N> operator-(const Vector<T, N>& thisVal) \
|
||||
{ \
|
||||
Vector<T, N> result; \
|
||||
for (int i = 0; i < N; i++) \
|
||||
result[i] = 0 - thisVal[i]; \
|
||||
return result; \
|
||||
}
|
||||
SLANG_VECTOR_INT_NEG_OP(int)
|
||||
SLANG_VECTOR_INT_NEG_OP(int8_t)
|
||||
SLANG_VECTOR_INT_NEG_OP(int16_t)
|
||||
SLANG_VECTOR_INT_NEG_OP(int64_t)
|
||||
SLANG_VECTOR_INT_NEG_OP(uint)
|
||||
SLANG_VECTOR_INT_NEG_OP(uint8_t)
|
||||
SLANG_VECTOR_INT_NEG_OP(uint16_t)
|
||||
SLANG_VECTOR_INT_NEG_OP(uint64_t)
|
||||
#if SLANG_INTPTR_TYPE_IS_DISTINCT
|
||||
SLANG_VECTOR_INT_NEG_OP(intptr_t)
|
||||
SLANG_VECTOR_INT_NEG_OP(uintptr_t)
|
||||
#endif
|
||||
|
||||
#define SLANG_FLOAT_VECTOR_MOD(T) \
|
||||
template<int N> \
|
||||
Vector<T, N> operator%(const Vector<T, N>& left, const Vector<T, N>& right) \
|
||||
{ \
|
||||
Vector<T, N> result; \
|
||||
for (int i = 0; i < N; i++) \
|
||||
result[i] = _slang_fmod(left[i], right[i]); \
|
||||
return result; \
|
||||
}
|
||||
|
||||
SLANG_FLOAT_VECTOR_MOD(float)
|
||||
SLANG_FLOAT_VECTOR_MOD(double)
|
||||
#undef SLANG_FLOAT_VECTOR_MOD
|
||||
#undef SLANG_VECTOR_BINARY_OP
|
||||
#undef SLANG_VECTOR_UNARY_OP
|
||||
#undef SLANG_INT_VECTOR_OPS
|
||||
#undef SLANG_FLOAT_VECTOR_OPS
|
||||
#undef SLANG_VECTOR_INT_NEG_OP
|
||||
#undef SLANG_FLOAT_VECTOR_MOD
|
||||
|
||||
template<typename T, int ROWS, int COLS>
|
||||
struct Matrix
|
||||
{
|
||||
Vector<T, COLS> rows[ROWS];
|
||||
const Vector<T, COLS>& operator[](size_t index) const { return rows[index]; }
|
||||
Vector<T, COLS>& operator[](size_t index) { return rows[index]; }
|
||||
Matrix() = default;
|
||||
Matrix(T scalar)
|
||||
{
|
||||
for (int i = 0; i < ROWS; i++)
|
||||
rows[i] = Vector<T, COLS>(scalar);
|
||||
}
|
||||
Matrix(const Vector<T, COLS>& row0) { rows[0] = row0; }
|
||||
Matrix(const Vector<T, COLS>& row0, const Vector<T, COLS>& row1)
|
||||
{
|
||||
rows[0] = row0;
|
||||
rows[1] = row1;
|
||||
}
|
||||
Matrix(const Vector<T, COLS>& row0, const Vector<T, COLS>& row1, const Vector<T, COLS>& row2)
|
||||
{
|
||||
rows[0] = row0;
|
||||
rows[1] = row1;
|
||||
rows[2] = row2;
|
||||
}
|
||||
Matrix(
|
||||
const Vector<T, COLS>& row0,
|
||||
const Vector<T, COLS>& row1,
|
||||
const Vector<T, COLS>& row2,
|
||||
const Vector<T, COLS>& row3)
|
||||
{
|
||||
rows[0] = row0;
|
||||
rows[1] = row1;
|
||||
rows[2] = row2;
|
||||
rows[3] = row3;
|
||||
}
|
||||
template<typename U, int otherRow, int otherCol>
|
||||
Matrix(const Matrix<U, otherRow, otherCol>& other)
|
||||
{
|
||||
int minRow = ROWS;
|
||||
int minCol = COLS;
|
||||
if (minRow > otherRow)
|
||||
minRow = otherRow;
|
||||
if (minCol > otherCol)
|
||||
minCol = otherCol;
|
||||
for (int i = 0; i < minRow; i++)
|
||||
for (int j = 0; j < minCol; j++)
|
||||
rows[i][j] = (T)other.rows[i][j];
|
||||
}
|
||||
Matrix(T v0, T v1, T v2, T v3)
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[1][0] = v2;
|
||||
rows[1][1] = v3;
|
||||
}
|
||||
Matrix(T v0, T v1, T v2, T v3, T v4, T v5)
|
||||
{
|
||||
if (COLS == 3)
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[0][2] = v2;
|
||||
rows[1][0] = v3;
|
||||
rows[1][1] = v4;
|
||||
rows[1][2] = v5;
|
||||
}
|
||||
else
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[1][0] = v2;
|
||||
rows[1][1] = v3;
|
||||
rows[2][0] = v4;
|
||||
rows[2][1] = v5;
|
||||
}
|
||||
}
|
||||
Matrix(T v0, T v1, T v2, T v3, T v4, T v5, T v6, T v7)
|
||||
{
|
||||
if (COLS == 4)
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[0][2] = v2;
|
||||
rows[0][3] = v3;
|
||||
rows[1][0] = v4;
|
||||
rows[1][1] = v5;
|
||||
rows[1][2] = v6;
|
||||
rows[1][3] = v7;
|
||||
}
|
||||
else
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[1][0] = v2;
|
||||
rows[1][1] = v3;
|
||||
rows[2][0] = v4;
|
||||
rows[2][1] = v5;
|
||||
rows[3][0] = v6;
|
||||
rows[3][1] = v7;
|
||||
}
|
||||
}
|
||||
Matrix(T v0, T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8)
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[0][2] = v2;
|
||||
rows[1][0] = v3;
|
||||
rows[1][1] = v4;
|
||||
rows[1][2] = v5;
|
||||
rows[2][0] = v6;
|
||||
rows[2][1] = v7;
|
||||
rows[2][2] = v8;
|
||||
}
|
||||
Matrix(T v0, T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8, T v9, T v10, T v11)
|
||||
{
|
||||
if (COLS == 4)
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[0][2] = v2;
|
||||
rows[0][3] = v3;
|
||||
rows[1][0] = v4;
|
||||
rows[1][1] = v5;
|
||||
rows[1][2] = v6;
|
||||
rows[1][3] = v7;
|
||||
rows[2][0] = v8;
|
||||
rows[2][1] = v9;
|
||||
rows[2][2] = v10;
|
||||
rows[2][3] = v11;
|
||||
}
|
||||
else
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[0][2] = v2;
|
||||
rows[1][0] = v3;
|
||||
rows[1][1] = v4;
|
||||
rows[1][2] = v5;
|
||||
rows[2][0] = v6;
|
||||
rows[2][1] = v7;
|
||||
rows[2][2] = v8;
|
||||
rows[3][0] = v9;
|
||||
rows[3][1] = v10;
|
||||
rows[3][2] = v11;
|
||||
}
|
||||
}
|
||||
Matrix(
|
||||
T v0,
|
||||
T v1,
|
||||
T v2,
|
||||
T v3,
|
||||
T v4,
|
||||
T v5,
|
||||
T v6,
|
||||
T v7,
|
||||
T v8,
|
||||
T v9,
|
||||
T v10,
|
||||
T v11,
|
||||
T v12,
|
||||
T v13,
|
||||
T v14,
|
||||
T v15)
|
||||
{
|
||||
rows[0][0] = v0;
|
||||
rows[0][1] = v1;
|
||||
rows[0][2] = v2;
|
||||
rows[0][3] = v3;
|
||||
rows[1][0] = v4;
|
||||
rows[1][1] = v5;
|
||||
rows[1][2] = v6;
|
||||
rows[1][3] = v7;
|
||||
rows[2][0] = v8;
|
||||
rows[2][1] = v9;
|
||||
rows[2][2] = v10;
|
||||
rows[2][3] = v11;
|
||||
rows[3][0] = v12;
|
||||
rows[3][1] = v13;
|
||||
rows[3][2] = v14;
|
||||
rows[3][3] = v15;
|
||||
}
|
||||
};
|
||||
|
||||
#define SLANG_MATRIX_BINARY_OP(T, op) \
|
||||
template<int R, int C> \
|
||||
Matrix<T, R, C> operator op(const Matrix<T, R, C>& thisVal, const Matrix<T, R, C>& other) \
|
||||
{ \
|
||||
Matrix<T, R, C> result; \
|
||||
for (int i = 0; i < R; i++) \
|
||||
for (int j = 0; j < C; j++) \
|
||||
result.rows[i][j] = thisVal.rows[i][j] op other.rows[i][j]; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define SLANG_MATRIX_BINARY_COMPARE_OP(T, op) \
|
||||
template<int R, int C> \
|
||||
Matrix<bool, R, C> operator op(const Matrix<T, R, C>& thisVal, const Matrix<T, R, C>& other) \
|
||||
{ \
|
||||
Matrix<bool, R, C> result; \
|
||||
for (int i = 0; i < R; i++) \
|
||||
for (int j = 0; j < C; j++) \
|
||||
result.rows[i][j] = thisVal.rows[i][j] op other.rows[i][j]; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define SLANG_MATRIX_UNARY_OP(T, op) \
|
||||
template<int R, int C> \
|
||||
Matrix<T, R, C> operator op(const Matrix<T, R, C>& thisVal) \
|
||||
{ \
|
||||
Matrix<T, R, C> result; \
|
||||
for (int i = 0; i < R; i++) \
|
||||
for (int j = 0; j < C; j++) \
|
||||
result[i].rows[i][j] = op thisVal.rows[i][j]; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define SLANG_INT_MATRIX_OPS(T) \
|
||||
SLANG_MATRIX_BINARY_OP(T, +) \
|
||||
SLANG_MATRIX_BINARY_OP(T, -) \
|
||||
SLANG_MATRIX_BINARY_OP(T, *) \
|
||||
SLANG_MATRIX_BINARY_OP(T, /) \
|
||||
SLANG_MATRIX_BINARY_OP(T, &) \
|
||||
SLANG_MATRIX_BINARY_OP(T, |) \
|
||||
SLANG_MATRIX_BINARY_OP(T, &&) \
|
||||
SLANG_MATRIX_BINARY_OP(T, ||) \
|
||||
SLANG_MATRIX_BINARY_OP(T, ^) \
|
||||
SLANG_MATRIX_BINARY_OP(T, %) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, >) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, <) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, >=) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, <=) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, ==) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, !=) \
|
||||
SLANG_MATRIX_UNARY_OP(T, !) \
|
||||
SLANG_MATRIX_UNARY_OP(T, ~)
|
||||
#define SLANG_FLOAT_MATRIX_OPS(T) \
|
||||
SLANG_MATRIX_BINARY_OP(T, +) \
|
||||
SLANG_MATRIX_BINARY_OP(T, -) \
|
||||
SLANG_MATRIX_BINARY_OP(T, *) \
|
||||
SLANG_MATRIX_BINARY_OP(T, /) \
|
||||
SLANG_MATRIX_UNARY_OP(T, -) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, >) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, <) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, >=) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, <=) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, ==) \
|
||||
SLANG_MATRIX_BINARY_COMPARE_OP(T, !=)
|
||||
SLANG_INT_MATRIX_OPS(int)
|
||||
SLANG_INT_MATRIX_OPS(int8_t)
|
||||
SLANG_INT_MATRIX_OPS(int16_t)
|
||||
SLANG_INT_MATRIX_OPS(int64_t)
|
||||
SLANG_INT_MATRIX_OPS(uint)
|
||||
SLANG_INT_MATRIX_OPS(uint8_t)
|
||||
SLANG_INT_MATRIX_OPS(uint16_t)
|
||||
SLANG_INT_MATRIX_OPS(uint64_t)
|
||||
#if SLANG_INTPTR_TYPE_IS_DISTINCT
|
||||
SLANG_INT_MATRIX_OPS(intptr_t)
|
||||
SLANG_INT_MATRIX_OPS(uintptr_t)
|
||||
#endif
|
||||
|
||||
SLANG_FLOAT_MATRIX_OPS(float)
|
||||
SLANG_FLOAT_MATRIX_OPS(double)
|
||||
|
||||
#define SLANG_MATRIX_INT_NEG_OP(T) \
|
||||
template<int R, int C> \
|
||||
SLANG_FORCE_INLINE Matrix<T, R, C> operator-(Matrix<T, R, C> thisVal) \
|
||||
{ \
|
||||
Matrix<T, R, C> result; \
|
||||
for (int i = 0; i < R; i++) \
|
||||
for (int j = 0; j < C; j++) \
|
||||
result.rows[i][j] = 0 - thisVal.rows[i][j]; \
|
||||
return result; \
|
||||
}
|
||||
SLANG_MATRIX_INT_NEG_OP(int)
|
||||
SLANG_MATRIX_INT_NEG_OP(int8_t)
|
||||
SLANG_MATRIX_INT_NEG_OP(int16_t)
|
||||
SLANG_MATRIX_INT_NEG_OP(int64_t)
|
||||
SLANG_MATRIX_INT_NEG_OP(uint)
|
||||
SLANG_MATRIX_INT_NEG_OP(uint8_t)
|
||||
SLANG_MATRIX_INT_NEG_OP(uint16_t)
|
||||
SLANG_MATRIX_INT_NEG_OP(uint64_t)
|
||||
#if SLANG_INTPTR_TYPE_IS_DISTINCT
|
||||
SLANG_MATRIX_INT_NEG_OP(intptr_t)
|
||||
SLANG_MATRIX_INT_NEG_OP(uintptr_t)
|
||||
#endif
|
||||
|
||||
#define SLANG_FLOAT_MATRIX_MOD(T) \
|
||||
template<int R, int C> \
|
||||
SLANG_FORCE_INLINE Matrix<T, R, C> operator%(Matrix<T, R, C> left, Matrix<T, R, C> right) \
|
||||
{ \
|
||||
Matrix<T, R, C> result; \
|
||||
for (int i = 0; i < R; i++) \
|
||||
for (int j = 0; j < C; j++) \
|
||||
result.rows[i][j] = _slang_fmod(left.rows[i][j], right.rows[i][j]); \
|
||||
return result; \
|
||||
}
|
||||
|
||||
SLANG_FLOAT_MATRIX_MOD(float)
|
||||
SLANG_FLOAT_MATRIX_MOD(double)
|
||||
#undef SLANG_FLOAT_MATRIX_MOD
|
||||
#undef SLANG_MATRIX_BINARY_OP
|
||||
#undef SLANG_MATRIX_UNARY_OP
|
||||
#undef SLANG_INT_MATRIX_OPS
|
||||
#undef SLANG_FLOAT_MATRIX_OPS
|
||||
#undef SLANG_MATRIX_INT_NEG_OP
|
||||
#undef SLANG_FLOAT_MATRIX_MOD
|
||||
|
||||
template<typename TResult, typename TInput>
|
||||
TResult slang_bit_cast(TInput val)
|
||||
{
|
||||
return *(TResult*)(&val);
|
||||
}
|
||||
|
||||
#endif
|
||||
1364
lib/All/slang/include/slang-cpp-types.h
Normal file
1364
lib/All/slang/include/slang-cpp-types.h
Normal file
File diff suppressed because it is too large
Load Diff
7926
lib/All/slang/include/slang-cuda-prelude.h
Normal file
7926
lib/All/slang/include/slang-cuda-prelude.h
Normal file
File diff suppressed because it is too large
Load Diff
1704
lib/All/slang/include/slang-deprecated.h
Normal file
1704
lib/All/slang/include/slang-deprecated.h
Normal file
File diff suppressed because it is too large
Load Diff
2982
lib/All/slang/include/slang-gfx.h
Normal file
2982
lib/All/slang/include/slang-gfx.h
Normal file
File diff suppressed because it is too large
Load Diff
8
lib/All/slang/include/slang-hlsl-prelude.h
Normal file
8
lib/All/slang/include/slang-hlsl-prelude.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifdef SLANG_HLSL_ENABLE_NVAPI
|
||||
#include "nvHLSLExtns.h"
|
||||
#endif
|
||||
|
||||
#ifndef __DXC_VERSION_MAJOR
|
||||
// warning X3557: loop doesn't seem to do anything, forcing loop to unroll
|
||||
#pragma warning(disable : 3557)
|
||||
#endif
|
||||
50
lib/All/slang/include/slang-image-format-defs.h
Normal file
50
lib/All/slang/include/slang-image-format-defs.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// slang-image-format-defs.h
|
||||
#ifndef SLANG_FORMAT
|
||||
#error Must define SLANG_FORMAT macro before including image-format-defs.h
|
||||
#endif
|
||||
|
||||
SLANG_FORMAT(unknown, (NONE, 0, 0))
|
||||
SLANG_FORMAT(rgba32f, (FLOAT32, 4, sizeof(float) * 4))
|
||||
SLANG_FORMAT(rgba16f, (FLOAT16, 4, sizeof(uint16_t) * 4))
|
||||
SLANG_FORMAT(rg32f, (FLOAT32, 2, sizeof(float) * 2))
|
||||
SLANG_FORMAT(rg16f, (FLOAT16, 2, sizeof(uint16_t) * 2))
|
||||
SLANG_FORMAT(r11f_g11f_b10f, (NONE, 3, sizeof(uint32_t)))
|
||||
SLANG_FORMAT(r32f, (FLOAT32, 1, sizeof(float)))
|
||||
SLANG_FORMAT(r16f, (FLOAT16, 1, sizeof(uint16_t)))
|
||||
SLANG_FORMAT(rgba16, (UINT16, 4, sizeof(uint16_t) * 4))
|
||||
SLANG_FORMAT(rgb10_a2, (NONE, 4, sizeof(uint32_t)))
|
||||
SLANG_FORMAT(rgba8, (UINT8, 4, sizeof(uint32_t)))
|
||||
SLANG_FORMAT(rg16, (UINT16, 2, sizeof(uint16_t) * 2))
|
||||
SLANG_FORMAT(rg8, (UINT8, 2, sizeof(char) * 2))
|
||||
SLANG_FORMAT(r16, (UINT16, 1, sizeof(uint16_t)))
|
||||
SLANG_FORMAT(r8, (UINT8, 1, sizeof(uint8_t)))
|
||||
SLANG_FORMAT(rgba16_snorm, (UINT16, 4, sizeof(uint16_t) * 4))
|
||||
SLANG_FORMAT(rgba8_snorm, (UINT8, 4, sizeof(uint8_t) * 4))
|
||||
SLANG_FORMAT(rg16_snorm, (UINT16, 2, sizeof(uint16_t) * 2))
|
||||
SLANG_FORMAT(rg8_snorm, (UINT8, 2, sizeof(uint8_t) * 2))
|
||||
SLANG_FORMAT(r16_snorm, (UINT16, 1, sizeof(uint16_t)))
|
||||
SLANG_FORMAT(r8_snorm, (UINT8, 1, sizeof(uint8_t)))
|
||||
SLANG_FORMAT(rgba32i, (INT32, 4, sizeof(int32_t) * 4))
|
||||
SLANG_FORMAT(rgba16i, (INT16, 4, sizeof(int16_t) * 4))
|
||||
SLANG_FORMAT(rgba8i, (INT8, 4, sizeof(int8_t) * 4))
|
||||
SLANG_FORMAT(rg32i, (INT32, 2, sizeof(int32_t) * 2))
|
||||
SLANG_FORMAT(rg16i, (INT16, 2, sizeof(int16_t) * 2))
|
||||
SLANG_FORMAT(rg8i, (INT8, 2, sizeof(int8_t) * 2))
|
||||
SLANG_FORMAT(r32i, (INT32, 1, sizeof(int32_t)))
|
||||
SLANG_FORMAT(r16i, (INT16, 1, sizeof(int16_t)))
|
||||
SLANG_FORMAT(r8i, (INT8, 1, sizeof(int8_t)))
|
||||
SLANG_FORMAT(rgba32ui, (UINT32, 4, sizeof(uint32_t) * 4))
|
||||
SLANG_FORMAT(rgba16ui, (UINT16, 4, sizeof(uint16_t) * 4))
|
||||
SLANG_FORMAT(rgb10_a2ui, (NONE, 4, sizeof(uint32_t)))
|
||||
SLANG_FORMAT(rgba8ui, (UINT8, 4, sizeof(uint8_t) * 4))
|
||||
SLANG_FORMAT(rg32ui, (UINT32, 2, sizeof(uint32_t) * 2))
|
||||
SLANG_FORMAT(rg16ui, (UINT16, 2, sizeof(uint16_t) * 2))
|
||||
SLANG_FORMAT(rg8ui, (UINT8, 2, sizeof(uint8_t) * 2))
|
||||
SLANG_FORMAT(r32ui, (UINT32, 1, sizeof(uint32_t)))
|
||||
SLANG_FORMAT(r16ui, (UINT16, 1, sizeof(uint16_t)))
|
||||
SLANG_FORMAT(r8ui, (UINT8, 1, sizeof(uint8_t)))
|
||||
SLANG_FORMAT(r64ui, (UINT64, 1, sizeof(uint64_t)))
|
||||
SLANG_FORMAT(r64i, (INT64, 1, sizeof(int64_t)))
|
||||
SLANG_FORMAT(bgra8, (UINT8, 4, sizeof(uint32_t)))
|
||||
|
||||
#undef SLANG_FORMAT
|
||||
404
lib/All/slang/include/slang-llvm.h
Normal file
404
lib/All/slang/include/slang-llvm.h
Normal file
@@ -0,0 +1,404 @@
|
||||
#ifndef SLANG_LLVM_H
|
||||
#define SLANG_LLVM_H
|
||||
|
||||
// TODO(JS):
|
||||
// Disable exception declspecs, as not supported on LLVM without some extra options.
|
||||
// We could enable with `-fms-extensions`
|
||||
#define SLANG_DISABLE_EXCEPTIONS 1
|
||||
|
||||
#ifndef SLANG_PRELUDE_ASSERT
|
||||
#ifdef SLANG_PRELUDE_ENABLE_ASSERT
|
||||
extern "C" void assertFailure(const char* msg);
|
||||
#define SLANG_PRELUDE_EXPECT(VALUE, MSG) \
|
||||
if (VALUE) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
assertFailure("assertion failed: '" MSG "'")
|
||||
#define SLANG_PRELUDE_ASSERT(VALUE) SLANG_PRELUDE_EXPECT(VALUE, #VALUE)
|
||||
#else // SLANG_PRELUDE_ENABLE_ASSERT
|
||||
#define SLANG_PRELUDE_EXPECT(VALUE, MSG)
|
||||
#define SLANG_PRELUDE_ASSERT(x)
|
||||
#endif // SLANG_PRELUDE_ENABLE_ASSERT
|
||||
#endif
|
||||
|
||||
/*
|
||||
Taken from stddef.h
|
||||
*/
|
||||
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
typedef __SIZE_TYPE__ rsize_t;
|
||||
|
||||
// typedef __WCHAR_TYPE__ wchar_t;
|
||||
|
||||
#if defined(__need_NULL)
|
||||
#undef NULL
|
||||
#ifdef __cplusplus
|
||||
#if !defined(__MINGW32__) && !defined(_MSC_VER)
|
||||
#define NULL __null
|
||||
#else
|
||||
#define NULL 0
|
||||
#endif
|
||||
#else
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
|
||||
namespace std
|
||||
{
|
||||
typedef decltype(nullptr) nullptr_t;
|
||||
}
|
||||
using ::std::nullptr_t;
|
||||
#endif
|
||||
#endif
|
||||
#undef __need_NULL
|
||||
#endif /* defined(__need_NULL) */
|
||||
|
||||
|
||||
/*
|
||||
The following are taken verbatim from stdint.h from Clang in LLVM. Only 8/16/32/64 types are needed.
|
||||
*/
|
||||
|
||||
// LLVM/Clang types such that we can use LLVM/Clang without headers for C++ output from Slang
|
||||
|
||||
#ifdef __INT64_TYPE__
|
||||
#ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
|
||||
typedef __INT64_TYPE__ int64_t;
|
||||
#endif /* __int8_t_defined */
|
||||
typedef __UINT64_TYPE__ uint64_t;
|
||||
#define __int_least64_t int64_t
|
||||
#define __uint_least64_t uint64_t
|
||||
#endif /* __INT64_TYPE__ */
|
||||
|
||||
#ifdef __int_least64_t
|
||||
typedef __int_least64_t int_least64_t;
|
||||
typedef __uint_least64_t uint_least64_t;
|
||||
typedef __int_least64_t int_fast64_t;
|
||||
typedef __uint_least64_t uint_fast64_t;
|
||||
#endif /* __int_least64_t */
|
||||
|
||||
#ifdef __INT32_TYPE__
|
||||
|
||||
#ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/
|
||||
typedef __INT32_TYPE__ int32_t;
|
||||
#endif /* __int8_t_defined */
|
||||
|
||||
#ifndef __uint32_t_defined /* more glibc compatibility */
|
||||
#define __uint32_t_defined
|
||||
typedef __UINT32_TYPE__ uint32_t;
|
||||
#endif /* __uint32_t_defined */
|
||||
|
||||
#define __int_least32_t int32_t
|
||||
#define __uint_least32_t uint32_t
|
||||
#endif /* __INT32_TYPE__ */
|
||||
|
||||
#ifdef __int_least32_t
|
||||
typedef __int_least32_t int_least32_t;
|
||||
typedef __uint_least32_t uint_least32_t;
|
||||
typedef __int_least32_t int_fast32_t;
|
||||
typedef __uint_least32_t uint_fast32_t;
|
||||
#endif /* __int_least32_t */
|
||||
|
||||
#ifdef __INT16_TYPE__
|
||||
#ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/
|
||||
typedef __INT16_TYPE__ int16_t;
|
||||
#endif /* __int8_t_defined */
|
||||
typedef __UINT16_TYPE__ uint16_t;
|
||||
#define __int_least16_t int16_t
|
||||
#define __uint_least16_t uint16_t
|
||||
#endif /* __INT16_TYPE__ */
|
||||
|
||||
#ifdef __int_least16_t
|
||||
typedef __int_least16_t int_least16_t;
|
||||
typedef __uint_least16_t uint_least16_t;
|
||||
typedef __int_least16_t int_fast16_t;
|
||||
typedef __uint_least16_t uint_fast16_t;
|
||||
#endif /* __int_least16_t */
|
||||
|
||||
#ifdef __INT8_TYPE__
|
||||
#ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/
|
||||
typedef __INT8_TYPE__ int8_t;
|
||||
#endif /* __int8_t_defined */
|
||||
typedef __UINT8_TYPE__ uint8_t;
|
||||
#define __int_least8_t int8_t
|
||||
#define __uint_least8_t uint8_t
|
||||
#endif /* __INT8_TYPE__ */
|
||||
|
||||
#ifdef __int_least8_t
|
||||
typedef __int_least8_t int_least8_t;
|
||||
typedef __uint_least8_t uint_least8_t;
|
||||
typedef __int_least8_t int_fast8_t;
|
||||
typedef __uint_least8_t uint_fast8_t;
|
||||
#endif /* __int_least8_t */
|
||||
|
||||
/* prevent glibc sys/types.h from defining conflicting types */
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
#endif /* __int8_t_defined */
|
||||
|
||||
/* C99 7.18.1.4 Integer types capable of holding object pointers.
|
||||
*/
|
||||
#define __stdint_join3(a, b, c) a##b##c
|
||||
|
||||
#ifndef _INTPTR_T
|
||||
#ifndef __intptr_t_defined
|
||||
typedef __INTPTR_TYPE__ intptr_t;
|
||||
#define __intptr_t_defined
|
||||
#define _INTPTR_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _UINTPTR_T
|
||||
typedef __UINTPTR_TYPE__ uintptr_t;
|
||||
#define _UINTPTR_T
|
||||
#endif
|
||||
|
||||
/* C99 7.18.1.5 Greatest-width integer types.
|
||||
*/
|
||||
typedef __INTMAX_TYPE__ intmax_t;
|
||||
typedef __UINTMAX_TYPE__ uintmax_t;
|
||||
|
||||
/* C99 7.18.4 Macros for minimum-width integer constants.
|
||||
*
|
||||
* The standard requires that integer constant macros be defined for all the
|
||||
* minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width
|
||||
* types are required, the corresponding integer constant macros are defined
|
||||
* here. This implementation also defines minimum-width types for every other
|
||||
* integer width that the target implements, so corresponding macros are
|
||||
* defined below, too.
|
||||
*
|
||||
* These macros are defined using the same successive-shrinking approach as
|
||||
* the type definitions above. It is likewise important that macros are defined
|
||||
* in order of decending width.
|
||||
*
|
||||
* Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the
|
||||
* claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
|
||||
*/
|
||||
|
||||
#define __int_c_join(a, b) a##b
|
||||
#define __int_c(v, suffix) __int_c_join(v, suffix)
|
||||
#define __uint_c(v, suffix) __int_c_join(v##U, suffix)
|
||||
|
||||
#ifdef __INT64_TYPE__
|
||||
#ifdef __INT64_C_SUFFIX__
|
||||
#define __int64_c_suffix __INT64_C_SUFFIX__
|
||||
#else
|
||||
#undef __int64_c_suffix
|
||||
#endif /* __INT64_C_SUFFIX__ */
|
||||
#endif /* __INT64_TYPE__ */
|
||||
|
||||
#ifdef __int_least64_t
|
||||
#ifdef __int64_c_suffix
|
||||
#define INT64_C(v) __int_c(v, __int64_c_suffix)
|
||||
#define UINT64_C(v) __uint_c(v, __int64_c_suffix)
|
||||
#else
|
||||
#define INT64_C(v) v
|
||||
#define UINT64_C(v) v##U
|
||||
#endif /* __int64_c_suffix */
|
||||
#endif /* __int_least64_t */
|
||||
|
||||
|
||||
#ifdef __INT32_TYPE__
|
||||
#ifdef __INT32_C_SUFFIX__
|
||||
#define __int32_c_suffix __INT32_C_SUFFIX__
|
||||
#else
|
||||
#undef __int32_c_suffix
|
||||
#endif /* __INT32_C_SUFFIX__ */
|
||||
#endif /* __INT32_TYPE__ */
|
||||
|
||||
#ifdef __int_least32_t
|
||||
#ifdef __int32_c_suffix
|
||||
#define INT32_C(v) __int_c(v, __int32_c_suffix)
|
||||
#define UINT32_C(v) __uint_c(v, __int32_c_suffix)
|
||||
#else
|
||||
#define INT32_C(v) v
|
||||
#define UINT32_C(v) v##U
|
||||
#endif /* __int32_c_suffix */
|
||||
#endif /* __int_least32_t */
|
||||
|
||||
#ifdef __INT16_TYPE__
|
||||
#ifdef __INT16_C_SUFFIX__
|
||||
#define __int16_c_suffix __INT16_C_SUFFIX__
|
||||
#else
|
||||
#undef __int16_c_suffix
|
||||
#endif /* __INT16_C_SUFFIX__ */
|
||||
#endif /* __INT16_TYPE__ */
|
||||
|
||||
#ifdef __int_least16_t
|
||||
#ifdef __int16_c_suffix
|
||||
#define INT16_C(v) __int_c(v, __int16_c_suffix)
|
||||
#define UINT16_C(v) __uint_c(v, __int16_c_suffix)
|
||||
#else
|
||||
#define INT16_C(v) v
|
||||
#define UINT16_C(v) v##U
|
||||
#endif /* __int16_c_suffix */
|
||||
#endif /* __int_least16_t */
|
||||
|
||||
|
||||
#ifdef __INT8_TYPE__
|
||||
#ifdef __INT8_C_SUFFIX__
|
||||
#define __int8_c_suffix __INT8_C_SUFFIX__
|
||||
#else
|
||||
#undef __int8_c_suffix
|
||||
#endif /* __INT8_C_SUFFIX__ */
|
||||
#endif /* __INT8_TYPE__ */
|
||||
|
||||
#ifdef __int_least8_t
|
||||
#ifdef __int8_c_suffix
|
||||
#define INT8_C(v) __int_c(v, __int8_c_suffix)
|
||||
#define UINT8_C(v) __uint_c(v, __int8_c_suffix)
|
||||
#else
|
||||
#define INT8_C(v) v
|
||||
#define UINT8_C(v) v##U
|
||||
#endif /* __int8_c_suffix */
|
||||
#endif /* __int_least8_t */
|
||||
|
||||
/* C99 7.18.2.1 Limits of exact-width integer types.
|
||||
* C99 7.18.2.2 Limits of minimum-width integer types.
|
||||
* C99 7.18.2.3 Limits of fastest minimum-width integer types.
|
||||
*
|
||||
* The presence of limit macros are completely optional in C99. This
|
||||
* implementation defines limits for all of the types (exact- and
|
||||
* minimum-width) that it defines above, using the limits of the minimum-width
|
||||
* type for any types that do not have exact-width representations.
|
||||
*
|
||||
* As in the type definitions, this section takes an approach of
|
||||
* successive-shrinking to determine which limits to use for the standard (8,
|
||||
* 16, 32, 64) bit widths when they don't have exact representations. It is
|
||||
* therefore important that the definitions be kept in order of decending
|
||||
* widths.
|
||||
*
|
||||
* Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the
|
||||
* claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
|
||||
*/
|
||||
|
||||
#ifdef __INT64_TYPE__
|
||||
#define INT64_MAX INT64_C(9223372036854775807)
|
||||
#define INT64_MIN (-INT64_C(9223372036854775807) - 1)
|
||||
#define UINT64_MAX UINT64_C(18446744073709551615)
|
||||
#define __INT_LEAST64_MIN INT64_MIN
|
||||
#define __INT_LEAST64_MAX INT64_MAX
|
||||
#define __UINT_LEAST64_MAX UINT64_MAX
|
||||
#endif /* __INT64_TYPE__ */
|
||||
|
||||
#ifdef __INT_LEAST64_MIN
|
||||
#define INT_LEAST64_MIN __INT_LEAST64_MIN
|
||||
#define INT_LEAST64_MAX __INT_LEAST64_MAX
|
||||
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX
|
||||
#define INT_FAST64_MIN __INT_LEAST64_MIN
|
||||
#define INT_FAST64_MAX __INT_LEAST64_MAX
|
||||
#define UINT_FAST64_MAX __UINT_LEAST64_MAX
|
||||
#endif /* __INT_LEAST64_MIN */
|
||||
|
||||
#ifdef __INT32_TYPE__
|
||||
#define INT32_MAX INT32_C(2147483647)
|
||||
#define INT32_MIN (-INT32_C(2147483647) - 1)
|
||||
#define UINT32_MAX UINT32_C(4294967295)
|
||||
#define __INT_LEAST32_MIN INT32_MIN
|
||||
#define __INT_LEAST32_MAX INT32_MAX
|
||||
#define __UINT_LEAST32_MAX UINT32_MAX
|
||||
#endif /* __INT32_TYPE__ */
|
||||
|
||||
#ifdef __INT_LEAST32_MIN
|
||||
#define INT_LEAST32_MIN __INT_LEAST32_MIN
|
||||
#define INT_LEAST32_MAX __INT_LEAST32_MAX
|
||||
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX
|
||||
#define INT_FAST32_MIN __INT_LEAST32_MIN
|
||||
#define INT_FAST32_MAX __INT_LEAST32_MAX
|
||||
#define UINT_FAST32_MAX __UINT_LEAST32_MAX
|
||||
#endif /* __INT_LEAST32_MIN */
|
||||
|
||||
#ifdef __INT16_TYPE__
|
||||
#define INT16_MAX INT16_C(32767)
|
||||
#define INT16_MIN (-INT16_C(32767) - 1)
|
||||
#define UINT16_MAX UINT16_C(65535)
|
||||
#define __INT_LEAST16_MIN INT16_MIN
|
||||
#define __INT_LEAST16_MAX INT16_MAX
|
||||
#define __UINT_LEAST16_MAX UINT16_MAX
|
||||
#endif /* __INT16_TYPE__ */
|
||||
|
||||
#ifdef __INT_LEAST16_MIN
|
||||
#define INT_LEAST16_MIN __INT_LEAST16_MIN
|
||||
#define INT_LEAST16_MAX __INT_LEAST16_MAX
|
||||
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX
|
||||
#define INT_FAST16_MIN __INT_LEAST16_MIN
|
||||
#define INT_FAST16_MAX __INT_LEAST16_MAX
|
||||
#define UINT_FAST16_MAX __UINT_LEAST16_MAX
|
||||
#endif /* __INT_LEAST16_MIN */
|
||||
|
||||
|
||||
#ifdef __INT8_TYPE__
|
||||
#define INT8_MAX INT8_C(127)
|
||||
#define INT8_MIN (-INT8_C(127) - 1)
|
||||
#define UINT8_MAX UINT8_C(255)
|
||||
#define __INT_LEAST8_MIN INT8_MIN
|
||||
#define __INT_LEAST8_MAX INT8_MAX
|
||||
#define __UINT_LEAST8_MAX UINT8_MAX
|
||||
#endif /* __INT8_TYPE__ */
|
||||
|
||||
#ifdef __INT_LEAST8_MIN
|
||||
#define INT_LEAST8_MIN __INT_LEAST8_MIN
|
||||
#define INT_LEAST8_MAX __INT_LEAST8_MAX
|
||||
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX
|
||||
#define INT_FAST8_MIN __INT_LEAST8_MIN
|
||||
#define INT_FAST8_MAX __INT_LEAST8_MAX
|
||||
#define UINT_FAST8_MAX __UINT_LEAST8_MAX
|
||||
#endif /* __INT_LEAST8_MIN */
|
||||
|
||||
/* Some utility macros */
|
||||
#define __INTN_MIN(n) __stdint_join3(INT, n, _MIN)
|
||||
#define __INTN_MAX(n) __stdint_join3(INT, n, _MAX)
|
||||
#define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX)
|
||||
#define __INTN_C(n, v) __stdint_join3(INT, n, _C(v))
|
||||
#define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v))
|
||||
|
||||
/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
|
||||
/* C99 7.18.3 Limits of other integer types. */
|
||||
|
||||
#define INTPTR_MIN (-__INTPTR_MAX__ - 1)
|
||||
#define INTPTR_MAX __INTPTR_MAX__
|
||||
#define UINTPTR_MAX __UINTPTR_MAX__
|
||||
#define PTRDIFF_MIN (-__PTRDIFF_MAX__ - 1)
|
||||
#define PTRDIFF_MAX __PTRDIFF_MAX__
|
||||
#define SIZE_MAX __SIZE_MAX__
|
||||
|
||||
/* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
|
||||
* is enabled. */
|
||||
#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
|
||||
#define RSIZE_MAX (SIZE_MAX >> 1)
|
||||
#endif
|
||||
|
||||
/* C99 7.18.2.5 Limits of greatest-width integer types. */
|
||||
#define INTMAX_MIN (-__INTMAX_MAX__ - 1)
|
||||
#define INTMAX_MAX __INTMAX_MAX__
|
||||
#define UINTMAX_MAX __UINTMAX_MAX__
|
||||
|
||||
/* C99 7.18.3 Limits of other integer types. */
|
||||
#define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__)
|
||||
#define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__)
|
||||
#ifdef __WINT_UNSIGNED__
|
||||
#define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0)
|
||||
#define WINT_MAX __UINTN_MAX(__WINT_WIDTH__)
|
||||
#else
|
||||
#define WINT_MIN __INTN_MIN(__WINT_WIDTH__)
|
||||
#define WINT_MAX __INTN_MAX(__WINT_WIDTH__)
|
||||
#endif
|
||||
|
||||
#ifndef WCHAR_MAX
|
||||
#define WCHAR_MAX __WCHAR_MAX__
|
||||
#endif
|
||||
#ifndef WCHAR_MIN
|
||||
#if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__)
|
||||
#define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__)
|
||||
#else
|
||||
#define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 7.18.4.2 Macros for greatest-width integer constants. */
|
||||
#define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__)
|
||||
#define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__)
|
||||
|
||||
|
||||
#endif // SLANG_LLVM_H
|
||||
2
lib/All/slang/include/slang-tag-version.h
Normal file
2
lib/All/slang/include/slang-tag-version.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SLANG_TAG_VERSION "2026.3.1"
|
||||
#define SLANG_VERSION_NUMERIC "2026.3.1"
|
||||
183
lib/All/slang/include/slang-torch-prelude.h
Normal file
183
lib/All/slang/include/slang-torch-prelude.h
Normal file
@@ -0,0 +1,183 @@
|
||||
// Prelude for PyTorch cpp binding.
|
||||
|
||||
// clang-format off
|
||||
#include <torch/extension.h>
|
||||
// clang-format on
|
||||
|
||||
#include <ATen/cuda/CUDAContext.h>
|
||||
#include <ATen/cuda/CUDAUtils.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef SLANG_LLVM
|
||||
#include "slang-llvm.h"
|
||||
#else // SLANG_LLVM
|
||||
#if SLANG_GCC_FAMILY && __GNUC__ < 6
|
||||
#include <cmath>
|
||||
#define SLANG_PRELUDE_STD std::
|
||||
#else
|
||||
#include <math.h>
|
||||
#define SLANG_PRELUDE_STD
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif // SLANG_LLVM
|
||||
|
||||
#include "../source/core/slang-string.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define SLANG_PRELUDE_SHARED_LIB_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__((__visibility__("default")))
|
||||
// # define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__ ((dllexport))
|
||||
// __attribute__((__visibility__("default")))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define SLANG_PRELUDE_EXTERN_C extern "C"
|
||||
#define SLANG_PRELUDE_EXTERN_C_START \
|
||||
extern "C" \
|
||||
{
|
||||
#define SLANG_PRELUDE_EXTERN_C_END }
|
||||
#else
|
||||
#define SLANG_PRELUDE_EXTERN_C
|
||||
#define SLANG_PRELUDE_EXTERN_C_START
|
||||
#define SLANG_PRELUDE_EXTERN_C_END
|
||||
#endif
|
||||
|
||||
#define SLANG_PRELUDE_NAMESPACE
|
||||
|
||||
#ifndef SLANG_NO_THROW
|
||||
#define SLANG_NO_THROW
|
||||
#endif
|
||||
#ifndef SLANG_STDCALL
|
||||
#define SLANG_STDCALL
|
||||
#endif
|
||||
#ifndef SLANG_MCALL
|
||||
#define SLANG_MCALL SLANG_STDCALL
|
||||
#endif
|
||||
#ifndef SLANG_FORCE_INLINE
|
||||
#define SLANG_FORCE_INLINE inline
|
||||
#endif
|
||||
#include "slang-cpp-scalar-intrinsics.h"
|
||||
#include "slang-cpp-types-core.h"
|
||||
|
||||
|
||||
static const int kSlangTorchTensorMaxDim = 5;
|
||||
|
||||
// NOTE: If you change this struct's layout, also update the hard-coded size/alignment
|
||||
// in _createTypeLayout() in slang-type-layout.cpp.
|
||||
struct TensorView
|
||||
{
|
||||
uint8_t* data;
|
||||
uint32_t strides[kSlangTorchTensorMaxDim];
|
||||
uint32_t sizes[kSlangTorchTensorMaxDim];
|
||||
uint32_t dimensionCount;
|
||||
};
|
||||
|
||||
|
||||
TensorView make_tensor_view(
|
||||
torch::Tensor val,
|
||||
const char* name,
|
||||
torch::ScalarType targetScalarType,
|
||||
bool requireContiguous)
|
||||
{
|
||||
// We're currently not trying to implicitly cast or transfer to device for two reasons:
|
||||
// 1. There appears to be a bug with .to() where successive calls after the first one fail.
|
||||
// 2. Silent casts like this can cause large memory allocations & unexpected overheads.
|
||||
// It's better to be explicit.
|
||||
|
||||
// Expect tensors to be on CUDA device
|
||||
if (!val.device().is_cuda())
|
||||
throw std::runtime_error(
|
||||
std::string(name).append(": tensor is not on CUDA device.").c_str());
|
||||
|
||||
// Expect tensors to be the right type.
|
||||
if (val.dtype() != targetScalarType)
|
||||
throw std::runtime_error(
|
||||
std::string(name).append(": tensor is not of the expected type.").c_str());
|
||||
|
||||
// Check that the tensor is contiguous
|
||||
if (requireContiguous && !val.is_contiguous())
|
||||
throw std::runtime_error(std::string(name).append(": tensor is not contiguous.").c_str());
|
||||
|
||||
TensorView res = {};
|
||||
res.dimensionCount = val.dim();
|
||||
res.data = nullptr;
|
||||
size_t elementSize = 4;
|
||||
|
||||
switch (val.scalar_type())
|
||||
{
|
||||
case torch::kInt8:
|
||||
case torch::kUInt8:
|
||||
elementSize = 1;
|
||||
res.data = (uint8_t*)val.data_ptr<uint8_t>();
|
||||
break;
|
||||
case torch::kBFloat16:
|
||||
elementSize = 2;
|
||||
res.data = (uint8_t*)val.data_ptr<torch::BFloat16>();
|
||||
break;
|
||||
case torch::kFloat16:
|
||||
elementSize = 2;
|
||||
res.data = (uint8_t*)val.data_ptr<at::Half>();
|
||||
break;
|
||||
case torch::kInt16:
|
||||
elementSize = 2;
|
||||
res.data = (uint8_t*)val.data_ptr<int16_t>();
|
||||
break;
|
||||
case torch::kFloat32:
|
||||
elementSize = 4;
|
||||
res.data = (uint8_t*)val.data_ptr<float>();
|
||||
break;
|
||||
case torch::kInt32:
|
||||
elementSize = 4;
|
||||
res.data = (uint8_t*)val.data_ptr<int32_t>();
|
||||
break;
|
||||
case torch::kFloat64:
|
||||
elementSize = 8;
|
||||
res.data = (uint8_t*)val.data_ptr<double>();
|
||||
break;
|
||||
case torch::kInt64:
|
||||
elementSize = 8;
|
||||
res.data = (uint8_t*)val.data_ptr<int64_t>();
|
||||
break;
|
||||
case torch::kBool:
|
||||
elementSize = 1;
|
||||
res.data = (uint8_t*)val.data_ptr<bool>();
|
||||
break;
|
||||
}
|
||||
|
||||
if (val.dim() > kSlangTorchTensorMaxDim)
|
||||
throw std::runtime_error(std::string(name)
|
||||
.append(": number of dimensions exceeds limit (")
|
||||
.append(std::to_string(kSlangTorchTensorMaxDim))
|
||||
.append(")")
|
||||
.c_str());
|
||||
|
||||
bool isEmpty = true;
|
||||
for (int i = 0; i < val.dim(); ++i)
|
||||
{
|
||||
res.strides[i] = val.stride(i) * elementSize;
|
||||
if (res.strides[i] == 0)
|
||||
throw std::runtime_error(
|
||||
std::string(name)
|
||||
.append(": tensors with broadcasted dimensions are not supported (use "
|
||||
"tensor.contiguous() to make tensor whole)")
|
||||
.c_str());
|
||||
|
||||
res.sizes[i] = val.size(i);
|
||||
if (res.sizes[i] > 0)
|
||||
isEmpty = false;
|
||||
}
|
||||
|
||||
if (!res.data && !isEmpty)
|
||||
throw std::runtime_error(std::string(name).append(": data pointer is invalid.").c_str());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#define SLANG_PRELUDE_EXPORT
|
||||
5181
lib/All/slang/include/slang.h
Normal file
5181
lib/All/slang/include/slang.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user