Skip to content

Commit 2cefc12

Browse files
try and fix some longstanding VT issues (but still need @Crisspl to look at the samplers for uint/int descriptors of VT)
1 parent 7d37e20 commit 2cefc12

File tree

2 files changed

+45
-72
lines changed

2 files changed

+45
-72
lines changed

include/nbl/asset/utils/IVirtualTexture.h

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
245245

246246
return params;
247247
}
248-
ISampler::SParams getPhysicalPageSamplerParams() const
248+
ISampler::SParams getPhysicalStorageFloatSamplerParams() const
249249
{
250250
ISampler::SParams params;
251251
params.AnisotropicFilter = m_tilePadding ? core::findMSB(m_tilePadding<<1) : 0u;
@@ -262,21 +262,44 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
262262

263263
return params;
264264
}
265+
ISampler::SParams getPhysicalStorageNonFloatSamplerParams() const
266+
{
267+
ISampler::SParams params;
268+
params.AnisotropicFilter = 0u; // TODO: don't apply padding to uint and int textures (is it even possible with all the view aliasing going on?)
269+
params.BorderColor = ISampler::ETBC_FLOAT_OPAQUE_WHITE;
270+
params.CompareEnable = false;
271+
params.CompareFunc = ISampler::ECO_NEVER;
272+
params.LodBias = 0.f;
273+
params.MaxLod = 0.f;
274+
params.MinLod = 0.f;
275+
params.MaxFilter = ISampler::ETF_NEAREST;
276+
params.MinFilter = ISampler::ETF_NEAREST;
277+
params.MipmapMode = ISampler::ESMM_NEAREST;
278+
params.TextureWrapU = params.TextureWrapV = params.TextureWrapW = ISampler::ETC_CLAMP_TO_EDGE;
279+
280+
return params;
281+
}
265282

266283
virtual core::smart_refctd_ptr<sampler_t> createSampler(const ISampler::SParams& _params) const = 0;
267284

268-
core::smart_refctd_ptr<sampler_t> getPhysicalPageSampler() const
269-
{
270-
if (!m_physicalPageSampler)
271-
m_physicalPageSampler = createSampler(getPhysicalPageSamplerParams());
272-
return m_physicalPageSampler;
273-
}
274285
core::smart_refctd_ptr<sampler_t> getPageTableSampler() const
275286
{
276287
if (!m_pageTableSampler)
277288
m_pageTableSampler = createSampler(getPageTableSamplerParams());
278289
return m_pageTableSampler;
279290
}
291+
core::smart_refctd_ptr<sampler_t> getPhysicalStorageFloatSampler() const
292+
{
293+
if (!m_physicalStorageFloatSampler)
294+
m_physicalStorageFloatSampler = createSampler(getPhysicalStorageFloatSamplerParams());
295+
return m_physicalStorageFloatSampler;
296+
}
297+
core::smart_refctd_ptr<sampler_t> getPhysicalStorageNonFloatSampler() const
298+
{
299+
if (!m_physicalStorageNonFloatSampler)
300+
m_physicalStorageNonFloatSampler = createSampler(getPhysicalStorageNonFloatSamplerParams());
301+
return m_physicalStorageNonFloatSampler;
302+
}
280303

281304
uint32_t getMaxAllocationPageCount() const
282305
{
@@ -384,7 +407,8 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
384407
core::smart_refctd_ptr<image_t> m_pageTable;
385408
mutable core::smart_refctd_ptr<image_view_t> m_pageTableView;
386409
mutable core::smart_refctd_ptr<sampler_t> m_pageTableSampler;
387-
mutable core::smart_refctd_ptr<sampler_t> m_physicalPageSampler;
410+
mutable core::smart_refctd_ptr<sampler_t> m_physicalStorageFloatSampler;
411+
mutable core::smart_refctd_ptr<sampler_t> m_physicalStorageNonFloatSampler;
388412

389413
using pg_tab_addr_alctr_t = core::GeneralpurposeAddressAllocator<uint32_t>;
390414
std::array<pg_tab_addr_alctr_t, MAX_PAGE_TABLE_LAYERS> m_pageTableLayerAllocators;
@@ -1012,7 +1036,8 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
10121036
auto* samplers = _outSamplers;
10131037

10141038
samplers[0] = getPageTableSampler();
1015-
std::fill(samplers+1, samplers+samplerCount, getPhysicalPageSampler());
1039+
std::fill(samplers+1, samplers+samplerCount, getPhysicalStorageFloatSampler());
1040+
//std::fill(samplers+1, samplers+samplerCount, getPhysicalStorageNonFloatSampler()); // TODO: @Crisspl fix issue #106 please
10161041

10171042
auto fillBinding = [](auto& bnd, uint32_t _binding, uint32_t _count, core::smart_refctd_ptr<sampler_t>* _samplers) {
10181043
bnd.binding = _binding;
@@ -1022,7 +1047,7 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
10221047
bnd.samplers = _samplers;
10231048
};
10241049

1025-
fillBinding(bindings[0], _pgtBinding, 1u, samplers); // @Crisspl why is the count hardcoded to 1 !?
1050+
fillBinding(bindings[0], _pgtBinding, 1u, samplers);
10261051

10271052
uint32_t i = 1u;
10281053
if (getFloatViews().size())
@@ -1032,12 +1057,12 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
10321057
}
10331058
if (getIntViews().size())
10341059
{
1035-
fillBinding(bindings[i], _isamplersBinding, getIntViews().size(), samplers+1); // @Crisspl this has to be wrong! Sampler state for an interpolated float texture is definitely wrong to use for a integer texture
1060+
fillBinding(bindings[i], _isamplersBinding, getIntViews().size(), samplers+1); // TODO: @Crisspl this has to be wrong! Sampler state for an interpolated float texture is definitely wrong to use for a integer texture
10361061
++i;
10371062
}
10381063
if (getUintViews().size())
10391064
{
1040-
fillBinding(bindings[i], _usamplersBinding, getUintViews().size(), samplers+1); // @Crisspl this has to be wrong! Sampler state for an interpolated float texture is definitely wrong to use for a integer texture
1065+
fillBinding(bindings[i], _usamplersBinding, getUintViews().size(), samplers+1); // TODO: @Crisspl this has to be wrong! Sampler state for an interpolated float texture is definitely wrong to use for a integer texture
10411066
}
10421067

10431068
return std::make_pair(bindingCount, samplerCount);

include/nbl/builtin/glsl/virtual_texturing/impl_functions.glsl

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ vec4 nbl_glsl_vTextureGrad_impl(in uint formatID, in vec3 virtualUV, in mat2 dOr
155155
// maybe unroll a few times manually
156156
while (outstandingSampleMask!=uvec2(0u))
157157
{
158-
uvec2 tmp = outstandingSampleMask;
159-
uint subgroupFormatID = subgroupBroadcast(formatID,tmp[1]!=0u ? 32u:findLSB(tmp[0]));
158+
const bool bottomNotEmpty = outstandingSampleMask[0]!=0u;
159+
uint subgroupFormatID = subgroupBroadcast(formatID,findLSB(bottomNotEmpty ? outstandingSampleMask[0]:outstandingSampleMask[1])+(bottomNotEmpty ? 0:32));
160160
bool canSample = subgroupFormatID==formatID; // do I need this? && (outstandingSampleMask&gl_SubGroupEqMaskARB)==gl_SubGroupEqMaskARB;
161161
outstandingSampleMask ^= subgroupBallot(canSample).xy;
162162
if (canSample)
@@ -196,11 +196,10 @@ vec4 nbl_glsl_vTextureGrad(in uvec2 _texData, in vec2 uv, in mat2 dUV)
196196
#if _NBL_VT_INT_VIEWS_COUNT
197197
ivec4 nbl_glsl_iVTextureLod_impl(in uint formatID, in vec3 virtualUV, in uint lod, in uint originalMaxFullMip)
198198
{
199-
int nonnegativeLod = int(lod);
200-
int clippedLoD = min(nonnegativeLod,originalMaxFullMip);
201-
int levelInTail = nonnegativeLod - clippedLoD;
199+
const int clippedLoD = originalMaxFullMip!=0u ? min(lod,originalMaxFullMip):0u;
200+
const int levelInTail = lod-clippedLoD;
202201

203-
vec3 physCoord = nbl_glsl_vTexture_helper(formatID, virtualUV, clippedLoD, levelInTail);
202+
const vec3 physCoord = nbl_glsl_vTexture_helper(formatID,virtualUV,clippedLoD,levelInTail);
204203
#ifdef NBL_GL_EXT_nonuniform_qualifier
205204
return textureLod(iphysicalTileStorageFormatView[nonuniformEXT(formatID)], physCoord, lod);
206205
#else
@@ -238,11 +237,10 @@ ivec4 nbl_glsl_iVTextureLod(in uvec2 _texData, in vec2 uv, in uint lod)
238237
#if _NBL_VT_UINT_VIEWS_COUNT
239238
uvec4 nbl_glsl_uVTextureLod_impl(in uint formatID, in vec3 virtualUV, in uint lod, in uint originalMaxFullMip)
240239
{
241-
int nonnegativeLod = int(lod);
242-
int clippedLoD = min(nonnegativeLod,originalMaxFullMip);
243-
int levelInTail = nonnegativeLod - clippedLoD;
240+
const int clippedLoD = originalMaxFullMip!=0u ? min(lod,originalMaxFullMip):0u;
241+
const int levelInTail = lod-clippedLoD;
244242

245-
vec3 physCoord = nbl_glsl_vTexture_helper(formatID, virtualUV, clippedLoD, levelInTail);
243+
const vec3 physCoord = nbl_glsl_vTexture_helper(formatID,virtualUV,clippedLoD,levelInTail);
246244
#ifdef NBL_GL_EXT_nonuniform_qualifier
247245
return textureLod(uphysicalTileStorageFormatView[nonuniformEXT(formatID)], physCoord, lod);
248246
#else
@@ -277,54 +275,4 @@ uvec4 nbl_glsl_uVTextureLod(in uvec2 _texData, in vec2 uv, in uint lod)
277275
}
278276
#endif //_NBL_VT_UINT_VIEWS_COUNT
279277

280-
/*
281-
#ifdef NBL_GL_EXT_nonuniform_qualifier
282-
#define _NBL_DIVERGENT_SAMPLING_IMPL(retval_t, physicalSamplerName) return textureLod(physicalSamplerName[nonuniformEXT(formatID)], physCoord, lod)
283-
#else
284-
#define _NBL_DIVERGENT_SAMPLING_IMPL(retval_t, physicalSamplerName) \
285-
retval_t retval; \
286-
uint64_t outstandingSampleMask = ballotARB(true); \
287-
while (outstandingSampleMask != uint64_t(0u)) \
288-
{ \
289-
uvec2 tmp = unpackUint2x32(outstandingSampleMask); \
290-
uint subgroupFormatID = readInvocationARB(formatID, tmp[1] != 0u ? 32u : findLSB(tmp[0])); \
291-
bool canSample = subgroupFormatID == formatID; \
292-
outstandingSampleMask ^= ballotARB(canSample); \
293-
if (canSample) \
294-
retval = textureLod(physicalSamplerName[subgroupFormatID], physCoord, lod); \
295-
} \
296-
return retval
297-
#endif
298-
299-
//problem is with this line below "unexpected LEFT_BRACE", no idea why
300-
#define _NBL_DEFINE_VT_INTEGER_FUNCTIONS(funcName, implFuncName, retval_t, physicalSamplerName) retval_t implFuncName##(in uint formatID, in vec3 virtualUV, in uint lod, in int originalMaxFullMip) \
301-
{ \
302-
int nonnegativeLod = int(lod); \
303-
int clippedLoD = min(nonnegativeLod,originalMaxFullMip); \
304-
int levelInTail = nonnegativeLod - clippedLoD; \
305-
\
306-
vec3 physCoord = nbl_glsl_vTexture_helper(formatID, virtualUV, clippedLoD, levelInTail); \
307-
_NBL_DIVERGENT_SAMPLING_IMPL(retval_t, physicalSamplerName); \
308-
} \
309-
retval_t funcName(in uvec2 _texData, in vec2 uv, in uint lod) \
310-
{ \
311-
vec2 originalSz = nbl_glsl_unpackSize(_texData); \
312-
\
313-
uvec2 wrap = nbl_glsl_unpackWrapModes(_texData); \
314-
uv.x = nbl_glsl_wrapTexCoord(uv.x, wrap.x); \
315-
uv.y = nbl_glsl_wrapTexCoord(uv.y, wrap.y); \
316-
\
317-
vec3 virtualUV = nbl_glsl_unpackVirtualUV(_texData); \
318-
uint formatID = nbl_glsl_VT_layer2pid(uint(virtualUV.z)); \
319-
virtualUV.xy += uv * originalSz; \
320-
virtualUV.xy *= nbl_glsl_VT_getVTexSzRcp(); \
321-
\
322-
return nbl_glsl_vTextureLod_impl(formatID, virtualUV, lod, nbl_glsl_unpackMaxMipInVT(_texData)); \
323-
}
324-
325-
_NBL_DEFINE_VT_INTEGER_FUNCTIONS(nbl_glsl_iVTextureLod, nbl_glsl_iVTextureLod_impl, ivec4, iphysicalTileStorageFormatView)
326-
_NBL_DEFINE_VT_INTEGER_FUNCTIONS(nbl_glsl_uVTextureLod, nbl_glsl_uVTextureLod_impl, uvec4, uphysicalTileStorageFormatView)
327-
#undef _NBL_DIVERGENT_SAMPLING_IMPL
328-
*/
329-
330278
#endif //!_NBL_BUILTIN_GLSL_VIRTUAL_TEXTURING_IMPL_FUNCTIONS_INCLUDED_

0 commit comments

Comments
 (0)