Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HLSL generator #3

Open
wants to merge 18 commits into
base: header_4_hlsl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions tools/hlsl_generator/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@
namespace spirv
{

//! General Decls
template<class T>
NBL_CONSTEXPR_STATIC_INLINE bool is_pointer_v = is_spirv_type<T>::value;

template<uint32_t StorageClass, typename T>
struct pointer
{
using type = vk::SpirvOpaqueType<spv::OpTypePointer, vk::Literal< vk::integral_constant<uint32_t, StorageClass> >, T>;
};
// partial spec for BDA
template<typename T>
struct pointer<spv::StorageClassPhysicalStorageBuffer, T>
{
using type = vk::SpirvType<spv::OpTypePointer, sizeof(uint64_t), sizeof(uint64_t), vk::Literal<vk::integral_constant<uint32_t, spv::StorageClassPhysicalStorageBuffer> >, T>;
};

template<uint32_t StorageClass, typename T>
using pointer_t = typename pointer<StorageClass, T>::type;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only is_ should be implemented via structs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym? it's from the snippet you sent here #3 (comment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I'm dumb.

Still the is_pointer_v is wrong cause you're checking for being a spir-v type, not OpTypePointer

// The holy operation that makes addrof possible
template<uint32_t StorageClass, typename T>
[[vk::ext_instruction(spv::OpCopyObject)]]
Expand All @@ -36,7 +55,7 @@
// TODO: Generate extended instructions
//! Std 450 Extended set instructions
template<typename SquareMatrix>
[[vk::ext_instruction(34, /* GLSLstd450MatrixInverse */, "GLSL.std.450")]]
[[vk::ext_instruction(34 /* GLSLstd450MatrixInverse */, "GLSL.std.450")]]
SquareMatrix matrixInverse(NBL_CONST_REF_ARG(SquareMatrix) mat);

// Add specializations if you need to emit a `ext_capability` (this means that the instruction needs to forward through an `impl::` struct and so on)
Expand Down Expand Up @@ -275,7 +294,7 @@ def processInst(writer: io.TextIOWrapper,

if "Vector" in cap:
rt = "vector<" + rt + ", N> "
final_templates.append("typename N")
final_templates.append("uint32_t N")

op_ty = "T"
if prefered_op_ty != None:
Expand Down
33 changes: 26 additions & 7 deletions tools/hlsl_generator/out.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ namespace hlsl
namespace spirv
{

//! General Decls
template<class T>
NBL_CONSTEXPR_STATIC_INLINE bool is_pointer_v = is_spirv_type<T>::value;

template<uint32_t StorageClass, typename T>
struct pointer
{
using type = vk::SpirvOpaqueType<spv::OpTypePointer, vk::Literal< vk::integral_constant<uint32_t, StorageClass> >, T>;
};
// partial spec for BDA
template<typename T>
struct pointer<spv::StorageClassPhysicalStorageBuffer, T>
{
using type = vk::SpirvType<spv::OpTypePointer, sizeof(uint64_t), sizeof(uint64_t), vk::Literal<vk::integral_constant<uint32_t, spv::StorageClassPhysicalStorageBuffer> >, T>;
};

template<uint32_t StorageClass, typename T>
using pointer_t = typename pointer<StorageClass, T>::type;

// The holy operation that makes addrof possible
template<uint32_t StorageClass, typename T>
[[vk::ext_instruction(spv::OpCopyObject)]]
Expand All @@ -27,7 +46,7 @@ pointer_t<StorageClass, T> copyObject([[vk::ext_reference]] T value);
// TODO: Generate extended instructions
//! Std 450 Extended set instructions
template<typename SquareMatrix>
[[vk::ext_instruction(34, /* GLSLstd450MatrixInverse */, "GLSL.std.450")]]
[[vk::ext_instruction(34 /* GLSLstd450MatrixInverse */, "GLSL.std.450")]]
SquareMatrix matrixInverse(NBL_CONST_REF_ARG(SquareMatrix) mat);

// Add specializations if you need to emit a `ext_capability` (this means that the instruction needs to forward through an `impl::` struct and so on)
Expand Down Expand Up @@ -1426,7 +1445,7 @@ void endInvocationInterlockEXT_FragmentShaderShadingRateInterlockEXT();
[[vk::ext_instruction(spv::OpAtomicFMinEXT)]]
float16_t atomicMinEXT_AtomicFloat16MinMaxEXT([[vk::ext_reference]] float16_t pointer, uint32_t memoryScope, uint32_t semantics, float16_t value);

template<typename N>
template<uint32_t N>
[[vk::ext_capability(spv::CapabilityAtomicFloat16VectorNV)]]
[[vk::ext_instruction(spv::OpAtomicFMinEXT)]]
vector<float16_t, N> atomicMinEXT_AtomicFloat16VectorNV([[vk::ext_reference]] vector<float16_t, N> pointer, uint32_t memoryScope, uint32_t semantics, vector<float16_t, N> value);
Expand All @@ -1448,7 +1467,7 @@ template<typename P>
[[vk::ext_instruction(spv::OpAtomicFMinEXT)]]
enable_if_t<is_spirv_type_v<P>, float16_t> atomicMinEXT_AtomicFloat16MinMaxEXT(P pointer, uint32_t memoryScope, uint32_t semantics, float16_t value);

template<typename P, typename N>
template<typename P, uint32_t N>
[[vk::ext_capability(spv::CapabilityAtomicFloat16VectorNV)]]
[[vk::ext_instruction(spv::OpAtomicFMinEXT)]]
enable_if_t<is_spirv_type_v<P>, vector<float16_t, N> > atomicMinEXT_AtomicFloat16VectorNV(P pointer, uint32_t memoryScope, uint32_t semantics, vector<float16_t, N> value);
Expand All @@ -1472,7 +1491,7 @@ enable_if_t<is_spirv_type_v<P>, float64_t> atomicMinEXT_Float64(P pointer, uint3
[[vk::ext_instruction(spv::OpAtomicFMaxEXT)]]
float16_t atomicMaxEXT_AtomicFloat16MinMaxEXT([[vk::ext_reference]] float16_t pointer, uint32_t memoryScope, uint32_t semantics, float16_t value);

template<typename N>
template<uint32_t N>
[[vk::ext_capability(spv::CapabilityAtomicFloat16VectorNV)]]
[[vk::ext_instruction(spv::OpAtomicFMaxEXT)]]
vector<float16_t, N> atomicMaxEXT_AtomicFloat16VectorNV([[vk::ext_reference]] vector<float16_t, N> pointer, uint32_t memoryScope, uint32_t semantics, vector<float16_t, N> value);
Expand All @@ -1494,7 +1513,7 @@ template<typename P>
[[vk::ext_instruction(spv::OpAtomicFMaxEXT)]]
enable_if_t<is_spirv_type_v<P>, float16_t> atomicMaxEXT_AtomicFloat16MinMaxEXT(P pointer, uint32_t memoryScope, uint32_t semantics, float16_t value);

template<typename P, typename N>
template<typename P, uint32_t N>
[[vk::ext_capability(spv::CapabilityAtomicFloat16VectorNV)]]
[[vk::ext_instruction(spv::OpAtomicFMaxEXT)]]
enable_if_t<is_spirv_type_v<P>, vector<float16_t, N> > atomicMaxEXT_AtomicFloat16VectorNV(P pointer, uint32_t memoryScope, uint32_t semantics, vector<float16_t, N> value);
Expand All @@ -1519,7 +1538,7 @@ enable_if_t<is_spirv_type_v<P>, float64_t> atomicMaxEXT_Float64(P pointer, uint3
[[vk::ext_instruction(spv::OpAtomicFAddEXT)]]
float16_t atomicAddEXT_AtomicFloat16AddEXT([[vk::ext_reference]] float16_t pointer, uint32_t memoryScope, uint32_t semantics, float16_t value);

template<typename N>
template<uint32_t N>
[[vk::ext_capability(spv::CapabilityAtomicFloat16VectorNV)]]
[[vk::ext_extension("SPV_EXT_shader_atomic_float_add")]]
[[vk::ext_instruction(spv::OpAtomicFAddEXT)]]
Expand All @@ -1546,7 +1565,7 @@ template<typename P>
[[vk::ext_instruction(spv::OpAtomicFAddEXT)]]
enable_if_t<is_spirv_type_v<P>, float16_t> atomicAddEXT_AtomicFloat16AddEXT(P pointer, uint32_t memoryScope, uint32_t semantics, float16_t value);

template<typename P, typename N>
template<typename P, uint32_t N>
[[vk::ext_capability(spv::CapabilityAtomicFloat16VectorNV)]]
[[vk::ext_extension("SPV_EXT_shader_atomic_float_add")]]
[[vk::ext_instruction(spv::OpAtomicFAddEXT)]]
Expand Down