-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: header_4_hlsl
Are you sure you want to change the base?
Add HLSL generator #3
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will go into type_traits.hlsl
. right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some of the builtins also need caps or extensions
tools/hlsl_generator/gen.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use sized floats
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
tools/hlsl_generator/gen.py
Outdated
//! 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.
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
There was a problem hiding this comment.
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)
There was a problem hiding this 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
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
Signed-off-by: Ali Cheraghi <[email protected]>
76253c2
to
5b9371a
Compare
out.hlsl
is basically the output of running this:cd tools/hlsl_generator/ python3 gen.py out.hlsl