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

builtin: update inline spirv hlsl #739

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ SVertexAttributes main()
{
using namespace ::nbl::hlsl::glsl;

spirv::Position.xy = SurfaceTransform::applyToNDC((SurfaceTransform::FLAG_BITS)SwapchainTransform,pos[gl_VertexIndex()]);
spirv::Position.z = 0.f;
spirv::Position.w = 1.f;
spirv::builtin::Position.xy = SurfaceTransform::applyToNDC((SurfaceTransform::FLAG_BITS)SwapchainTransform,pos[gl_VertexIndex()]);
spirv::builtin::Position.z = 0.f;
spirv::builtin::Position.w = 1.f;

SVertexAttributes retval;
retval.uv = tc[gl_VertexIndex()];
Expand Down
18 changes: 9 additions & 9 deletions include/nbl/builtin/hlsl/glsl_compat/core.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,21 @@ SquareMatrix inverse(NBL_CONST_REF_ARG(SquareMatrix) mat)
*/
// TODO: Extemely annoying that HLSL doesn't have references, so we can't transparently alias the variables as `&` :(
//void gl_Position() {spirv::}
uint32_t gl_VertexIndex() {return spirv::VertexIndex;}
uint32_t gl_InstanceIndex() {return spirv::InstanceIndex;}
uint32_t gl_VertexIndex() {return spirv::builtin::VertexIndex;}
uint32_t gl_InstanceIndex() {return spirv::builtin::InstanceIndex;}

/**
* For Compute Shaders
*/

// TODO: Extemely annoying that HLSL doesn't have references, so we can't transparently alias the variables as `const&` :(
uint32_t3 gl_NumWorkGroups() {return spirv::NumWorkGroups;}
uint32_t3 gl_NumWorkGroups() {return spirv::builtin::NumWorkgroups;}
// TODO: DXC BUG prevents us from defining this!
uint32_t3 gl_WorkGroupSize();
uint32_t3 gl_WorkGroupID() {return spirv::WorkgroupId;}
uint32_t3 gl_LocalInvocationID() {return spirv::LocalInvocationId;}
uint32_t3 gl_GlobalInvocationID() {return spirv::GlobalInvocationId;}
uint32_t gl_LocalInvocationIndex() {return spirv::LocalInvocationIndex;}
uint32_t3 gl_WorkGroupID() {return spirv::builtin::WorkgroupId;}
uint32_t3 gl_LocalInvocationID() {return spirv::builtin::LocalInvocationId;}
uint32_t3 gl_GlobalInvocationID() {return spirv::builtin::GlobalInvocationId;}
uint32_t gl_LocalInvocationIndex() {return spirv::builtin::LocalInvocationIndex;}

void barrier() {
spirv::controlBarrier(spv::ScopeWorkgroup, spv::ScopeWorkgroup, spv::MemorySemanticsAcquireReleaseMask | spv::MemorySemanticsWorkgroupMemoryMask);
Expand Down Expand Up @@ -187,7 +187,7 @@ struct bitfieldExtract<T, true, true>
{
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
{
return spirv::bitFieldSExtract<T>( val, offsetBits, numBits );
return spirv::bitFieldSExtract( val, offsetBits, numBits );
}
};

Expand All @@ -196,7 +196,7 @@ struct bitfieldExtract<T, false, true>
{
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
{
return spirv::bitFieldUExtract<T>( val, offsetBits, numBits );
return spirv::bitFieldUExtract( val, offsetBits, numBits );
}
};

Expand Down
187 changes: 159 additions & 28 deletions include/nbl/builtin/hlsl/glsl_compat/subgroup_arithmetic.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef _NBL_BUILTIN_HLSL_GLSL_COMPAT_SUBGROUP_ARITHMETIC_INCLUDED_
#define _NBL_BUILTIN_HLSL_GLSL_COMPAT_SUBGROUP_ARITHMETIC_INCLUDED_

#include "nbl/builtin/hlsl/spirv_intrinsics/subgroup_arithmetic.hlsl"
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"

namespace nbl
{
Expand All @@ -17,93 +17,224 @@ namespace glsl
// TODO: Furthermore you'll need `bitfieldExtract`-like struct dispatcher to choose between int/float add/mul and sint/uint/float min/max
template<typename T>
T subgroupAdd(T value) {
return spirv::groupAdd(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
return spirv::groupNonUniformIAdd_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
}
template<typename T>
T subgroupInclusiveAdd(T value) {
return spirv::groupAdd(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
return spirv::groupNonUniformIAdd_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
}
template<typename T>
T subgroupExclusiveAdd(T value) {
return spirv::groupAdd(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
return spirv::groupNonUniformIAdd_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
}

template<typename T>
T subgroupMul(T value) {
return spirv::groupMul(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
return spirv::groupNonUniformIMul_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
}
template<typename T>
T subgroupInclusiveMul(T value) {
return spirv::groupMul(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
return spirv::groupNonUniformIMul_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
}
template<typename T>
T subgroupExclusiveMul(T value) {
return spirv::groupMul(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
return spirv::groupNonUniformIMul_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
}

template<typename T>
T subgroupAnd(T value) {
return spirv::groupBitwiseAnd(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
return spirv::groupNonUniformBitwiseAnd_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
}
template<typename T>
T subgroupInclusiveAnd(T value) {
return spirv::groupBitwiseAnd(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
return spirv::groupNonUniformBitwiseAnd_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
}
template<typename T>
T subgroupExclusiveAnd(T value) {
return spirv::groupBitwiseAnd(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
return spirv::groupNonUniformBitwiseAnd_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
}

template<typename T>
T subgroupOr(T value) {
return spirv::groupBitwiseOr(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
return spirv::groupNonUniformBitwiseOr_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
}
template<typename T>
T subgroupInclusiveOr(T value) {
return spirv::groupBitwiseOr(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
return spirv::groupNonUniformBitwiseOr_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
}
template<typename T>
T subgroupExclusiveOr(T value) {
return spirv::groupBitwiseOr(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
return spirv::groupNonUniformBitwiseOr_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
}

template<typename T>
T subgroupXor(T value) {
return spirv::groupBitwiseXor(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
return spirv::groupNonUniformBitwiseXor_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
}
template<typename T>
T subgroupInclusiveXor(T value) {
return spirv::groupBitwiseXor(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
return spirv::groupNonUniformBitwiseXor_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
}
template<typename T>
T subgroupExclusiveXor(T value) {
return spirv::groupBitwiseXor(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
return spirv::groupNonUniformBitwiseXor_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
}

namespace impl
{

template<typename T, bool isSigned>
struct subgroupMin {};

template<typename T>
struct subgroupMin<T, true>
{
static T __call(T val)
{
return spirv::groupNonUniformSMin_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, val);
}
};

template<typename T>
struct subgroupMin<T, false>
{
static T __call(T val)
{
return spirv::groupNonUniformUMin_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, val);
}
};

template<typename T, bool isSigned>
struct subgroupInclusiveMin {};

template<typename T>
struct subgroupInclusiveMin<T, true>
{
static T __call(T val)
{
return spirv::groupNonUniformSMin_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, val);
}
};

template<typename T>
struct subgroupInclusiveMin<T, false>
{
static T __call(T val)
{
return spirv::groupNonUniformUMin_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, val);
}
};

template<typename T, bool isSigned>
struct subgroupExclusiveMin {};

template<typename T>
struct subgroupExclusiveMin<T, true>
{
static T __call(T val)
{
return spirv::groupNonUniformSMin_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, val);
}
};

template<typename T>
struct subgroupExclusiveMin<T, false>
{
static T __call(T val)
{
return spirv::groupNonUniformUMin_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, val);
}
};

template<typename T, bool isSigned>
struct subgroupMax {};

template<typename T>
struct subgroupMax<T, true>
{
static T __call(T val)
{
return spirv::groupNonUniformSMax_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, val);
}
};

template<typename T>
struct subgroupMax<T, false>
{
static T __call(T val)
{
return spirv::groupNonUniformUMax_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationReduce, val);
}
};

template<typename T, bool isSigned>
struct subgroupInclusiveMax {};

template<typename T>
struct subgroupInclusiveMax<T, true>
{
static T __call(T val)
{
return spirv::groupNonUniformSMax_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, val);
}
};

template<typename T>
struct subgroupInclusiveMax<T, false>
{
static T __call(T val)
{
return spirv::groupNonUniformUMax_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, val);
}
};

template<typename T, bool isSigned>
struct subgroupExclusiveMax {};

template<typename T>
struct subgroupExclusiveMax<T, true>
{
static T __call(T val)
{
return spirv::groupNonUniformSMax_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, val);
}
};

template<typename T>
struct subgroupExclusiveMax<T, false>
{
static T __call(T val)
{
return spirv::groupNonUniformUMax_GroupNonUniformArithmetic<T>(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, val);
}
};

}

template<typename T>
T subgroupMin(T value) {
return spirv::groupBitwiseMin(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
T subgroupMin(T val) {
return impl::subgroupMin<T, is_signed<T>::value>::__call(val);
}
template<typename T>
T subgroupInclusiveMin(T value) {
return spirv::groupBitwiseMin(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
T subgroupInclusiveMin(T val) {
return impl::subgroupInclusiveMin<T, is_signed<T>::value>::__call(val);
}
template<typename T>
T subgroupExclusiveMin(T value) {
return spirv::groupBitwiseMin(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
T subgroupExclusiveMin(T val) {
return impl::subgroupExclusiveMin<T, is_signed<T>::value>::__call(val);
}

template<typename T>
T subgroupMax(T value) {
return spirv::groupBitwiseMax(spv::ScopeSubgroup, spv::GroupOperationReduce, value);
T subgroupMax(T val) {
return impl::subgroupMax<T, is_signed<T>::value>::__call(val);
}
template<typename T>
T subgroupInclusiveMax(T value) {
return spirv::groupBitwiseMax(spv::ScopeSubgroup, spv::GroupOperationInclusiveScan, value);
T subgroupInclusiveMax(T val) {
return impl::subgroupInclusiveMax<T, is_signed<T>::value>::__call(val);
}
template<typename T>
T subgroupExclusiveMax(T value) {
return spirv::groupBitwiseMax(spv::ScopeSubgroup, spv::GroupOperationExclusiveScan, value);
T subgroupExclusiveMax(T val) {
return impl::subgroupExclusiveMax<T, is_signed<T>::value>::__call(val);
}

}
Expand Down
Loading