Skip to content
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 @@ -25,8 +25,8 @@ namespace accessors

// declare concept
#define NBL_CONCEPT_NAME LoadableImage
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)(Components)
Comment on lines +28 to +29

Choose a reason for hiding this comment

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

do a similar change for StorableImage and friends

// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (a,U)
#define NBL_CONCEPT_PARAM_1 (uv,vector<uint16_t,Dims>)
Expand All @@ -38,7 +38,7 @@ NBL_CONCEPT_BEGIN(3)
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(uv,layer)), ::nbl::hlsl::is_same_v, vector<T,4>))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(uv,layer)), ::nbl::hlsl::is_same_v, vector<T,Components>))
);
#undef layer
#undef uv
Expand Down
47 changes: 23 additions & 24 deletions include/nbl/builtin/hlsl/rwmc/resolve.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,37 @@ namespace rwmc
{
// declare concept
#define NBL_CONCEPT_NAME ResolveAccessorBase
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)(VectorScalarType)(Dims)
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)(VectorScalarType)(Dims)(Components)
// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (a,T)
#define NBL_CONCEPT_PARAM_1 (scalar,VectorScalarType)
#define NBL_CONCEPT_PARAM_1 (vec,vector<VectorScalarType, Components>)
// start concept
NBL_CONCEPT_BEGIN(2)
NBL_CONCEPT_BEGIN(2)
// need to be defined AFTER the concept begins
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define scalar NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define vec NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_EXPR)((a.calcLuma(vector<VectorScalarType, 3>(scalar, scalar, scalar)))))
((NBL_CONCEPT_REQ_EXPR)((a.calcLuma(vec))))

Choose a reason for hiding this comment

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

maybe require that the expression returns a scalar ?

);
#undef a
#undef scalar
#undef vec
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

/* ResolveAccessor is required to:
* - satisfy `LoadableImage` concept requirements
* - implement function called `calcLuma` which calculates luma from a 3 component pixel value
*/

template<typename T, typename VectorScalarType, int32_t Dims>
NBL_BOOL_CONCEPT ResolveAccessor = ResolveAccessorBase<T, VectorScalarType, Dims> && concepts::accessors::LoadableImage<T, VectorScalarType, Dims>;
template<typename T, typename VectorScalarType, int32_t Dims, int32_t Components>
NBL_BOOL_CONCEPT ResolveAccessor = ResolveAccessorBase<T, VectorScalarType, Dims, Components> && concepts::accessors::LoadableImage<T, VectorScalarType, Dims, Components>;

template<typename OutputScalar>
struct ResolveAccessorAdaptor
{
using output_scalar_type = OutputScalar;
using output_type = vector<OutputScalar, 4>;
NBL_CONSTEXPR int32_t Components = 3;
using output_type = vector<OutputScalar, Components>;
NBL_CONSTEXPR int32_t image_dimension = 2;

RWTexture2DArray<float32_t4> cascade;
Expand All @@ -63,13 +64,13 @@ struct ResolveAccessorAdaptor
int16_t2 cascadeImageDimension = int16_t2(imgWidth, imgHeight);

if (any(uv < int16_t2(0, 0)) || any(uv > cascadeImageDimension))
return vector<OutputScalar, 4>(0, 0, 0, 0);
return promote<output_type, output_scalar_type>(0);

return cascade.Load(int32_t3(uv, int32_t(layer)));
}
};

template<typename CascadeAccessor, typename OutputColorTypeVec NBL_PRIMARY_REQUIRES(concepts::Vector<OutputColorTypeVec> && ResolveAccessor<CascadeAccessor, typename CascadeAccessor::output_scalar_type, CascadeAccessor::image_dimension>)
template<typename CascadeAccessor, typename OutputColorTypeVec NBL_PRIMARY_REQUIRES(concepts::Vector<OutputColorTypeVec> && ResolveAccessor<CascadeAccessor, typename CascadeAccessor::output_scalar_type, CascadeAccessor::image_dimension, CascadeAccessor::Components>)
struct Resolver
{
using output_type = OutputColorTypeVec;
Expand All @@ -92,12 +93,10 @@ struct Resolver

output_type operator()(NBL_REF_ARG(CascadeAccessor) acc, const int16_t2 coord)
{
using scalar_t = typename vector_traits<output_type>::scalar_type;

scalar_t reciprocalBaseI = 1.f;
CascadeSample curr = __sampleCascade(acc, coord, 0u, reciprocalBaseI);

output_type accumulation = output_type(0.0f, 0.0f, 0.0f);
output_type accumulation = promote<output_type, scalar_t>(0.0f);
scalar_t Emin = params.initialEmin;

scalar_t prevNormalizedCenterLuma, prevNormalizedNeighbourhoodAverageLuma;
Expand Down Expand Up @@ -162,15 +161,15 @@ struct Resolver
CascadeSample __sampleCascade(NBL_REF_ARG(CascadeAccessor) acc, int16_t2 coord, uint16_t cascadeIndex, scalar_t reciprocalBaseI)
{
output_type neighbourhood[9];
neighbourhood[0] = acc.template get<scalar_t, 2>(coord + int16_t2(-1, -1), cascadeIndex).xyz;
neighbourhood[1] = acc.template get<scalar_t, 2>(coord + int16_t2(0, -1), cascadeIndex).xyz;
neighbourhood[2] = acc.template get<scalar_t, 2>(coord + int16_t2(1, -1), cascadeIndex).xyz;
neighbourhood[3] = acc.template get<scalar_t, 2>(coord + int16_t2(-1, 0), cascadeIndex).xyz;
neighbourhood[4] = acc.template get<scalar_t, 2>(coord + int16_t2(0, 0), cascadeIndex).xyz;
neighbourhood[5] = acc.template get<scalar_t, 2>(coord + int16_t2(1, 0), cascadeIndex).xyz;
neighbourhood[6] = acc.template get<scalar_t, 2>(coord + int16_t2(-1, 1), cascadeIndex).xyz;
neighbourhood[7] = acc.template get<scalar_t, 2>(coord + int16_t2(0, 1), cascadeIndex).xyz;
neighbourhood[8] = acc.template get<scalar_t, 2>(coord + int16_t2(1, 1), cascadeIndex).xyz;
neighbourhood[0] = acc.template get<scalar_t, 2>(coord + int16_t2(-1, -1), cascadeIndex);
neighbourhood[1] = acc.template get<scalar_t, 2>(coord + int16_t2(0, -1), cascadeIndex);
neighbourhood[2] = acc.template get<scalar_t, 2>(coord + int16_t2(1, -1), cascadeIndex);
neighbourhood[3] = acc.template get<scalar_t, 2>(coord + int16_t2(-1, 0), cascadeIndex);
neighbourhood[4] = acc.template get<scalar_t, 2>(coord + int16_t2(0, 0), cascadeIndex);
neighbourhood[5] = acc.template get<scalar_t, 2>(coord + int16_t2(1, 0), cascadeIndex);
neighbourhood[6] = acc.template get<scalar_t, 2>(coord + int16_t2(-1, 1), cascadeIndex);
neighbourhood[7] = acc.template get<scalar_t, 2>(coord + int16_t2(0, 1), cascadeIndex);
neighbourhood[8] = acc.template get<scalar_t, 2>(coord + int16_t2(1, 1), cascadeIndex);

// numerical robustness
float32_t3 excl_hood_sum = ((neighbourhood[0] + neighbourhood[1]) + (neighbourhood[2] + neighbourhood[3])) +
Expand Down
Loading