Skip to content

Commit c2459bb

Browse files
author
devsh
committed
actually test using concepts
1 parent e0ed1ae commit c2459bb

File tree

9 files changed

+306
-23
lines changed

9 files changed

+306
-23
lines changed

include/nbl/builtin/hlsl/blit/common.hlsl

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ RWTexture3D<float4> outAs3D[ConstevalParameters::output_binding_t::Count];
4343

4444

4545
groupshared uint32_t sMem[ConstevalParameters::SharedMemoryDWORDs];
46+
47+
48+
#include <nbl/builtin/hlsl/concepts.hlsl>
4649
/*
4750
struct HistogramAccessor
4851
{
@@ -62,19 +65,34 @@ struct SharedAccessor
6265
sMem[idx] = val;
6366
}
6467
};
65-
struct InCSAccessor
66-
{
67-
float32_t4 get(float32_t3 c, uint32_t l)
68-
{
69-
return inCS.SampleLevel(inSamp, blit::impl::dim_to_image_properties<ConstevalParameters::BlitDimCount>::getIndexCoord<float32_t>(c, l), 0);
70-
}
71-
};
68+
*/
69+
7270
struct OutImgAccessor
7371
{
74-
void set(int32_t3 c, uint32_t l, float32_t4 v)
72+
template<typename T, int32_t Dims NBL_FUNC_REQUIRES(is_same_v<T,float>)
73+
void set(const vector<uint16_t,Dims> uv, uint16_t layer, const vector<T,4> data)
7574
{
76-
outImg[blit::impl::dim_to_image_properties<ConstevalParameters::BlitDimCount>::getIndexCoord<int32_t>(c, l)] = v;
75+
return __set_impl<Dims>(uv,layer,data);
7776
}
77+
78+
template<int32_t Dims>
79+
void __set_impl(const vector<uint16_t,Dims> uv, uint16_t layer, const float32_t4 data);
80+
81+
uint32_t descIx;
7882
};
79-
*/
83+
template<>
84+
void OutImgAccessor::__set_impl<1>(const uint16_t1 uv, uint16_t layer, const float32_t4 data)
85+
{
86+
outAs1DArray[descIx][uint32_t2(uv,layer)] = data;
87+
}
88+
template<>
89+
void OutImgAccessor::__set_impl<2>(const uint16_t2 uv, uint16_t layer, const float32_t4 data)
90+
{
91+
outAs2DArray[descIx][uint32_t3(uv,layer)] = data;
92+
}
93+
template<>
94+
void OutImgAccessor::__set_impl<3>(const uint16_t3 uv, uint16_t layer, const float32_t4 data)
95+
{
96+
outAs3D[descIx][uv] = data;
97+
}
8098
#endif

include/nbl/builtin/hlsl/blit/default_blit.comp.hlsl

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,38 @@ struct KernelWeightsAccessor
2121
return kernelWeights[idx];
2222
}
2323
};
24-
struct InCSAccessor
24+
25+
inCS.SampleLevel(inSamp, blit::impl::dim_to_image_properties<ConstevalParameters::BlitDimCount>::getIndexCoord<float32_t>(c, l), 0);
26+
*/
27+
struct InImgAccessor
2528
{
26-
float32_t4 get(float32_t3 c, uint32_t l)
29+
template<typename T, int32_t Dims NBL_FUNC_REQUIRES(is_same_v<T,float>)
30+
vector<T,4> data get(const vector<uint16_t,Dims> uv, uint16_t layer, uint16_t level)
2731
{
28-
return inCS.SampleLevel(inSamp, blit::impl::dim_to_image_properties<ConstevalParameters::BlitDimCount>::getIndexCoord<float32_t>(c, l), 0);
32+
return __get_impl<Dims>(uv,_static_cast<float>(layer),_static_cast<float>(level),data);
2933
}
34+
35+
template<int32_t Dims>
36+
float32_t4 __get_impl(const vector<float32_t,Dims> uv, float layer, float level);
37+
38+
uint32_t descIx : 20;
39+
uint32_t samplerIx : 12;
3040
};
31-
struct OutImgAccessor
41+
template<>
42+
float32_t4 InImgAccessor::__get_impl<1>(const float32_t1 uv, float layer, float level)
3243
{
33-
void set(int32_t3 c, uint32_t l, float32_t4 v)
34-
{
35-
outImg[blit::impl::dim_to_image_properties<ConstevalParameters::BlitDimCount>::getIndexCoord<int32_t>(c, l)] = v;
36-
}
37-
};
38-
*/
44+
return inAs1DArray[descIx].SampleLevel(inSamp[samplerIx],float32_t2(uv,layer),level);
45+
}
46+
template<>
47+
float32_t4 InImgAccessor::__get_impl<2>(const float32_t2 uv, float layer, float level)
48+
{
49+
return inAs2DArray[descIx].SampleLevel(inSamp[samplerIx],float32_t3(uv,layer),level);
50+
}
51+
template<>
52+
float32_t4 InImgAccessor::__get_impl<3>(const float32_t3 uv, float layer, float level)
53+
{
54+
return inAs3D[descIx].SampleLevel(inSamp[samplerIx],uv,level);
55+
}
3956

4057
using namespace nbl::hlsl::blit;
4158

@@ -44,6 +61,8 @@ using namespace nbl::hlsl::blit;
4461
[numthreads(ConstevalParameters::WorkGroupSize,1,1)]
4562
void main()
4663
{
64+
InImgAccessor inImgA;
65+
OutImgAccessor outImgA;
4766
/*
4867
blit::compute_blit_t<ConstevalParameters> blit = blit::compute_blit_t<ConstevalParameters>::create(params);
4968
InCSAccessor inCSA;

include/nbl/builtin/hlsl/concepts.hlsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace hlsl
1717
namespace concepts
1818
{
1919
// common implementation juice
20+
#define NBL_CONCEPT_MAX_PARAM_COUNT 32
2021
#include <boost/preprocessor/seq/elem.hpp>
2122
#define NBL_IMPL_CONCEPT_FULL_TPLT(z, n, unused) BOOST_PP_SEQ_ELEM(n,NBL_CONCEPT_TPLT_PRM_KINDS) BOOST_PP_SEQ_ELEM(n,NBL_CONCEPT_TPLT_PRM_NAMES)
2223
#include <boost/preprocessor/repetition/enum.hpp>
@@ -34,7 +35,7 @@ namespace concepts
3435

3536

3637
//! Now diverge
37-
#ifndef __cpp_concepts
38+
#ifdef __cpp_concepts
3839

3940

4041
// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
@@ -138,10 +139,10 @@ concept matricial = is_matrix<T>::value;
138139
// put just after the closing `>` on the partial template specialization `template` declaration e.g. `template<typename U, typename V, typename T> NBL_PARTIAL_REQ_TOP(SomeCond<U>)
139140
#define NBL_PARTIAL_REQ_TOP(...)
140141
// put just before closing `>` on the partial template specialization Type args, e.g. `MyStruct<U,V,T NBL_PARTIAL_REQ_BOT(SomeCond<U>)>
141-
#define NBL_PARTIAL_REQ_BOT(...) ,std::enable_if_t<(__VA_ARGS__),void>
142+
#define NBL_PARTIAL_REQ_BOT(...) ,::nbl::hlsl::enable_if_t<(__VA_ARGS__),void>
142143

143144
// condition, use instead of the closing `>` of a function template
144-
#define NBL_FUNC_REQUIRES(...) ,std::enable_if_t<(__VA_ARGS__),bool> = true>
145+
#define NBL_FUNC_REQUIRES(...) ,::nbl::hlsl::enable_if_t<(__VA_ARGS__),bool> = true>
145146

146147

147148
//
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2023-2024 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#undef NBL_CONCEPT_PARAM_31
5+
#undef NBL_CONCEPT_PARAM_30
6+
#undef NBL_CONCEPT_PARAM_29
7+
#undef NBL_CONCEPT_PARAM_28
8+
#undef NBL_CONCEPT_PARAM_27
9+
#undef NBL_CONCEPT_PARAM_26
10+
#undef NBL_CONCEPT_PARAM_25
11+
#undef NBL_CONCEPT_PARAM_24
12+
#undef NBL_CONCEPT_PARAM_23
13+
#undef NBL_CONCEPT_PARAM_22
14+
#undef NBL_CONCEPT_PARAM_21
15+
#undef NBL_CONCEPT_PARAM_20
16+
#undef NBL_CONCEPT_PARAM_19
17+
#undef NBL_CONCEPT_PARAM_18
18+
#undef NBL_CONCEPT_PARAM_17
19+
#undef NBL_CONCEPT_PARAM_16
20+
#undef NBL_CONCEPT_PARAM_15
21+
#undef NBL_CONCEPT_PARAM_14
22+
#undef NBL_CONCEPT_PARAM_13
23+
#undef NBL_CONCEPT_PARAM_12
24+
#undef NBL_CONCEPT_PARAM_11
25+
#undef NBL_CONCEPT_PARAM_10
26+
#undef NBL_CONCEPT_PARAM_9
27+
#undef NBL_CONCEPT_PARAM_8
28+
#undef NBL_CONCEPT_PARAM_7
29+
#undef NBL_CONCEPT_PARAM_6
30+
#undef NBL_CONCEPT_PARAM_5
31+
#undef NBL_CONCEPT_PARAM_4
32+
#undef NBL_CONCEPT_PARAM_3
33+
#undef NBL_CONCEPT_PARAM_2
34+
#undef NBL_CONCEPT_PARAM_1
35+
#undef NBL_CONCEPT_PARAM_0
36+
#undef NBL_CONCEPT_TPLT_PRM_NAMES
37+
#undef NBL_CONCEPT_TPLT_PRM_KINDS
38+
#undef NBL_CONCEPT_NAME
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_ANISOTROPICALLY_SAMPLED_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_ANISOTROPICALLY_SAMPLED_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
10+
11+
namespace nbl
12+
{
13+
namespace hlsl
14+
{
15+
namespace concepts
16+
{
17+
// declare concept
18+
#define NBL_CONCEPT_NAME AnisotropicallySampled
19+
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(int32_t)
20+
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(Dims)
21+
// not the greatest syntax but works
22+
#define NBL_CONCEPT_PARAM_0 (a,U)
23+
#define NBL_CONCEPT_PARAM_1 (uv,vector<float32_t,Dims>)
24+
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
25+
#define NBL_CONCEPT_PARAM_3 (dU,vector<float32_t,Dims>)
26+
#define NBL_CONCEPT_PARAM_4 (dV,vector<float32_t,Dims>)
27+
// start concept
28+
NBL_CONCEPT_BEGIN(5)
29+
// need to be defined AFTER the cocnept begins
30+
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
31+
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
32+
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
33+
#define dU NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
34+
#define dV NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
35+
NBL_CONCEPT_END(
36+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<Dims>(uv,layer,dU,dV)) , ::nbl::hlsl::is_same_v, float32_t4>))
37+
);
38+
#undef dV
39+
#undef dU
40+
#undef layer
41+
#undef uv
42+
#undef a
43+
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
44+
}
45+
}
46+
}
47+
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_LOADABLE_IMAGE_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_LOADABLE_IMAGE_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
10+
11+
namespace nbl
12+
{
13+
namespace hlsl
14+
{
15+
namespace concepts
16+
{
17+
// declare concept
18+
#define NBL_CONCEPT_NAME StorableImage
19+
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)
20+
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)
21+
// not the greatest syntax but works
22+
#define NBL_CONCEPT_PARAM_0 (a,U)
23+
#define NBL_CONCEPT_PARAM_1 (uv,vector<uint16_t,Dims>)
24+
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
25+
// start concept
26+
NBL_CONCEPT_BEGIN(3)
27+
// need to be defined AFTER the cocnept begins
28+
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
29+
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
30+
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
31+
NBL_CONCEPT_END(
32+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(uv,layer)) , ::nbl::hlsl::is_same_v, vector<T,4>))
33+
);
34+
#undef layer
35+
#undef uv
36+
#undef a
37+
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
38+
39+
// declare concept
40+
#define NBL_CONCEPT_NAME MipmappedStorableImage
41+
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)
42+
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)
43+
// not the greatest syntax but works
44+
#define NBL_CONCEPT_PARAM_0 (a,U)
45+
#define NBL_CONCEPT_PARAM_1 (uv,vector<uint16_t,Dims>)
46+
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
47+
#define NBL_CONCEPT_PARAM_3 (level,uint16_t)
48+
// start concept
49+
NBL_CONCEPT_BEGIN(4)
50+
// need to be defined AFTER the cocnept begins
51+
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
52+
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
53+
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
54+
#define level NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
55+
NBL_CONCEPT_END(
56+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(uv,layer,level)) , ::nbl::hlsl::is_same_v, vector<T,4>))
57+
);
58+
#undef level
59+
#undef layer
60+
#undef uv
61+
#undef a
62+
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
63+
}
64+
}
65+
}
66+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_MIP_MAPPED_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_MIP_MAPPED_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
10+
11+
namespace nbl
12+
{
13+
namespace hlsl
14+
{
15+
namespace concepts
16+
{
17+
// declare concept
18+
#define NBL_CONCEPT_NAME MipMapped
19+
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(int32_t)
20+
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(Dims)
21+
// not the greatest syntax but works
22+
#define NBL_CONCEPT_PARAM_0 (a,U)
23+
#define NBL_CONCEPT_PARAM_1 (uv,vector<float32_t,Dims>)
24+
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
25+
#define NBL_CONCEPT_PARAM_3 (level,float)
26+
// start concept
27+
NBL_CONCEPT_BEGIN(4)
28+
// need to be defined AFTER the cocnept begins
29+
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
30+
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
31+
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
32+
#define level NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
33+
NBL_CONCEPT_END(
34+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<Dims>(uv,layer,level)) , ::nbl::hlsl::is_same_v, float32_t4>))
35+
);
36+
#undef level
37+
#undef layer
38+
#undef uv
39+
#undef a
40+
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
41+
}
42+
}
43+
}
44+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_STORABLE_IMAGE_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_STORABLE_IMAGE_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
10+
11+
namespace nbl
12+
{
13+
namespace hlsl
14+
{
15+
namespace concepts
16+
{
17+
// declare concept
18+
#define NBL_CONCEPT_NAME StorableImage
19+
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)
20+
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)
21+
// not the greatest syntax but works
22+
#define NBL_CONCEPT_PARAM_0 (a,U)
23+
#define NBL_CONCEPT_PARAM_1 (uv,vector<uint16_t,Dims>)
24+
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
25+
#define NBL_CONCEPT_PARAM_3 (data,vector<T,4>)
26+
// start concept
27+
NBL_CONCEPT_BEGIN(4)
28+
// need to be defined AFTER the cocnept begins
29+
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
30+
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
31+
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
32+
#define data NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
33+
NBL_CONCEPT_END(
34+
((NBL_CONCEPT_REQ_EXPR)(a.template set<T,Dims>(uv,layer,data)))
35+
);
36+
#undef data
37+
#undef layer
38+
#undef uv
39+
#undef a
40+
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
41+
}
42+
}
43+
}
44+
#endif

0 commit comments

Comments
 (0)