Add HLSL generator#3
Add HLSL generator#3alichraghi wants to merge 18 commits intoDevsh-Graphics-Programming:header_4_hlslfrom
Conversation
5577b4b to
8194a6a
Compare
8194a6a to
20034bb
Compare
tools/hlsl_generator/gen.py
Outdated
| //! General Decls | ||
| template<uint32_t StorageClass, typename T> | ||
| using pointer_t = vk::SpirvOpaqueType<spv::OpTypePointer, vk::Literal< vk::integral_constant<uint32_t, StorageClass> >, T>; |
There was a problem hiding this comment.
pointer_t should be done in terms of
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<StorageClassPhysicalStorageBuffer,T>
{
using type = vk::SpirvType<spv::OpTypePointer,sizeof(uint64_t),sizeof(uint64_t),vk::Literal< vk::integral_constant<uint32_t, StorageClass> >, T>;
};
template<uint32_t StorageClass, typename T>
using pointer_t = pointer::type;and also have a is_pointer::value tester + is_pointer_v
There was a problem hiding this comment.
this will go into type_traits.hlsl. right?
There was a problem hiding this comment.
no it will go here because its spirv specific, it can be built with type_traits though, such as is_same_v
tools/hlsl_generator/gen.py
Outdated
| //! Std 450 Extended set operations | ||
| template<typename SquareMatrix> | ||
| [[vk::ext_instruction(GLSLstd450MatrixInverse)]] | ||
| SquareMatrix matrixInverse(NBL_CONST_REF_ARG(SquareMatrix) mat); |
There was a problem hiding this comment.
you want to gen all the extended instruction set stuff
tools/hlsl_generator/gen.py
Outdated
| case "SubgroupEqMask": builtin_type = "uint32_t4" | ||
| case "SubgroupGeMask": builtin_type = "uint32_t4" | ||
| case "SubgroupGtMask": builtin_type = "uint32_t4" | ||
| case "SubgroupLeMask": builtin_type = "uint32_t4" | ||
| case "SubgroupLtMask": builtin_type = "uint32_t4" | ||
| case "SubgroupSize": builtin_type = "uint32_t" | ||
| case "NumSubgroups": builtin_type = "uint32_t" | ||
| case "SubgroupId": builtin_type = "uint32_t" | ||
| case "SubgroupLocalInvocationId": builtin_type = "uint32_t" |
There was a problem hiding this comment.
some of the builtins also need caps or extensions
| writer.write("\n//! Instructions\n") | ||
| for instruction in grammer["instructions"]: | ||
| match instruction["class"]: | ||
| case "Atomic": | ||
| processInst(writer, instruction, InstOptions()) | ||
| processInst(writer, instruction, InstOptions(shape=Shape.PTR_TEMPLATE)) | ||
| case "Memory": | ||
| processInst(writer, instruction, InstOptions(shape=Shape.PTR_TEMPLATE)) | ||
| processInst(writer, instruction, InstOptions(shape=Shape.PSB_RT)) | ||
| case "Barrier" | "Bit": | ||
| processInst(writer, instruction, InstOptions()) | ||
| case "Reserved": | ||
| match instruction["opname"]: | ||
| case "OpBeginInvocationInterlockEXT" | "OpEndInvocationInterlockEXT": | ||
| processInst(writer, instruction, InstOptions()) | ||
| case "Non-Uniform": | ||
| match instruction["opname"]: | ||
| case "OpGroupNonUniformElect" | "OpGroupNonUniformAll" | "OpGroupNonUniformAny" | "OpGroupNonUniformAllEqual": | ||
| processInst(writer, instruction, InstOptions(result_ty="bool")) | ||
| case "OpGroupNonUniformBallot": | ||
| processInst(writer, instruction, InstOptions(result_ty="uint32_t4",op_ty="bool")) | ||
| case "OpGroupNonUniformInverseBallot" | "OpGroupNonUniformBallotBitExtract": | ||
| processInst(writer, instruction, InstOptions(result_ty="bool",op_ty="uint32_t4")) | ||
| case "OpGroupNonUniformBallotBitCount" | "OpGroupNonUniformBallotFindLSB" | "OpGroupNonUniformBallotFindMSB": | ||
| processInst(writer, instruction, InstOptions(result_ty="uint32_t",op_ty="uint32_t4")) | ||
| case _: processInst(writer, instruction, InstOptions()) | ||
| case _: continue # TODO | ||
|
|
||
| writer.write(foot) |
There was a problem hiding this comment.
it would be good to print to a log anything to skipped
tools/hlsl_generator/gen.py
Outdated
| processInst(writer, instruction, InstOptions(shape=Shape.PTR_TEMPLATE)) | ||
| case "Memory": | ||
| processInst(writer, instruction, InstOptions(shape=Shape.PTR_TEMPLATE)) | ||
| processInst(writer, instruction, InstOptions(shape=Shape.PSB_RT)) |
There was a problem hiding this comment.
Load/Store for BDA pointers should probably be handwritten
| writer.write("\n//! Group Operations\nnamespace group_operation\n{\n") | ||
| for go in group_operations: | ||
| name = go["enumerant"] | ||
| value = go["value"] | ||
| writer.write("\tstatic const uint32_t " + name + " = " + str(value) + ";\n") | ||
| writer.write("}\n") |
There was a problem hiding this comment.
why not just emit an enum?
tools/hlsl_generator/gen.py
Outdated
| if cap == "Shader" or cap == "Kernel": continue | ||
| caps.append(cap) |
There was a problem hiding this comment.
anything with Kernel you need to skip emitting
tools/hlsl_generator/gen.py
Outdated
| case "U": | ||
| fn_name = fn_name[0:m[1][0]] + fn_name[m[1][1]:] | ||
| result_types = ["uint32_t", "uint64_t"] | ||
| break | ||
| case "S": | ||
| fn_name = fn_name[0:m[1][0]] + fn_name[m[1][1]:] | ||
| result_types = ["int32_t", "int64_t"] |
There was a problem hiding this comment.
need a condition about being signed or unsigner
Also result types can be 16 bit ints too!
tools/hlsl_generator/gen.py
Outdated
| break | ||
| case "F": | ||
| fn_name = fn_name[0:m[1][0]] + fn_name[m[1][1]:] | ||
| result_types = ["float"] |
There was a problem hiding this comment.
use sized floats
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
| //! 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; | ||
|
|
There was a problem hiding this comment.
only is_ should be implemented via structs
There was a problem hiding this comment.
wdym? it's from the snippet you sent here #3 (comment)
There was a problem hiding this comment.
sorry I'm dumb.
Still the is_pointer_v is wrong cause you're checking for being a spir-v type, not OpTypePointer
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
76253c2 to
5b9371a
Compare
out.hlslis basically the output of running this:cd tools/hlsl_generator/ python3 gen.py out.hlsl