textureSize missing for shadow samplers and lod level ignored?
EvilTrev opened this issue · 4 comments
EvilTrev commented
Cannot compile shaders that invoke textureSize on a shadow sampler, but it also looks like the lod level is ignored from the parameter passed here.
I think the following is missing from bgfx_shader.sh:
vec2 bgfxTextureSize(BgfxSampler2DShadow _sampler, int _lod)
{
vec2 result;
_sampler.m_texture.GetDimensions(result.x, result.y);
return result;
}
But, shouldn't lod be included in all the bgfxTextureSize routines to get the resolution of that particular mip layer?
bkaradzic commented
Try this:
diff --git a/src/bgfx_shader.sh b/src/bgfx_shader.sh
index dde910ab7..ecc87668b 100644
--- a/src/bgfx_shader.sh
+++ b/src/bgfx_shader.sh
@@ -235,11 +235,25 @@ float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord)
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z);
}
+vec2 bgfxTextureSize(BgfxSampler2DShadow _sampler, int _lod)
+{
+ vec2 result;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y);
+ return result;
+}
+
vec4 bgfxShadow2DArray(BgfxSampler2DArrayShadow _sampler, vec4 _coord)
{
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w);
}
+vec2 bgfxTextureSize(BgfxSampler2DArrayShadow _sampler, int _lod)
+{
+ vec2 result;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y);
+ return result;
+}
+
vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord)
{
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
@@ -297,21 +311,21 @@ vec4 bgfxTexelFetchOffset(BgfxSampler2D _sampler, ivec2 _coord, int _lod, ivec2
vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod)
{
vec2 result;
- _sampler.m_texture.GetDimensions(result.x, result.y);
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y);
return result;
}
vec2 bgfxTextureSize(BgfxISampler2D _sampler, int _lod)
{
vec2 result;
- _sampler.m_texture.GetDimensions(result.x, result.y);
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y);
return result;
}
vec2 bgfxTextureSize(BgfxUSampler2D _sampler, int _lod)
{
vec2 result;
- _sampler.m_texture.GetDimensions(result.x, result.y);
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y);
return result;
}
@@ -319,14 +333,17 @@ vec4 bgfxTextureGather0(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather1(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather2(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather3(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord);
@@ -336,14 +353,17 @@ vec4 bgfxTextureGatherOffset0(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset
{
return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord, _offset);
}
+
vec4 bgfxTextureGatherOffset1(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset)
{
return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord, _offset);
}
+
vec4 bgfxTextureGatherOffset2(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset)
{
return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord, _offset);
}
+
vec4 bgfxTextureGatherOffset3(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset)
{
return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord, _offset);
@@ -353,14 +373,17 @@ vec4 bgfxTextureGather0(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather1(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather2(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather3(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord);
@@ -394,7 +417,7 @@ vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod)
vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod)
{
vec3 result;
- _sampler.m_texture.GetDimensions(result.x, result.y, result.z);
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y, result.z);
return result;
}
EvilTrev commented
I did try this, but was hitting errors compiling metal shaders. They were along the lines of:
ERROR: 0:200: '__BI_GetDimensions' : no matching overloaded function found
I also tried uint for _lod, which I thought might be the problem, but that didn't seem to help either.
bkaradzic commented
diff --git a/src/bgfx_shader.sh b/src/bgfx_shader.sh
index 3dd755682..48dbfd073 100644
--- a/src/bgfx_shader.sh
+++ b/src/bgfx_shader.sh
@@ -235,11 +235,28 @@ float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord)
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z);
}
+vec2 bgfxTextureSize(BgfxSampler2DShadow _sampler, int _lod)
+{
+ vec2 result;
+ float numberOfMipMapLevels;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels);
+ return result;
+}
+
vec4 bgfxShadow2DArray(BgfxSampler2DArrayShadow _sampler, vec4 _coord)
{
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w);
}
+vec2 bgfxTextureSize(BgfxSampler2DArrayShadow _sampler, int _lod)
+{
+ vec2 result;
+ float numberOfMipMapLevels;
+ float numberOfElements;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfElements, numberOfMipMapLevels);
+ return result;
+}
+
vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord)
{
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
@@ -297,21 +314,24 @@ vec4 bgfxTexelFetchOffset(BgfxSampler2D _sampler, ivec2 _coord, int _lod, ivec2
vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod)
{
vec2 result;
- _sampler.m_texture.GetDimensions(result.x, result.y);
+ float numberOfMipMapLevels;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels);
return result;
}
vec2 bgfxTextureSize(BgfxISampler2D _sampler, int _lod)
{
vec2 result;
- _sampler.m_texture.GetDimensions(result.x, result.y);
+ float numberOfMipMapLevels;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels);
return result;
}
vec2 bgfxTextureSize(BgfxUSampler2D _sampler, int _lod)
{
vec2 result;
- _sampler.m_texture.GetDimensions(result.x, result.y);
+ float numberOfMipMapLevels;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels);
return result;
}
@@ -319,14 +339,17 @@ vec4 bgfxTextureGather0(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather1(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather2(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather3(BgfxSampler2D _sampler, vec2 _coord)
{
return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord);
@@ -336,14 +359,17 @@ vec4 bgfxTextureGatherOffset0(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset
{
return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord, _offset);
}
+
vec4 bgfxTextureGatherOffset1(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset)
{
return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord, _offset);
}
+
vec4 bgfxTextureGatherOffset2(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset)
{
return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord, _offset);
}
+
vec4 bgfxTextureGatherOffset3(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset)
{
return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord, _offset);
@@ -353,14 +379,17 @@ vec4 bgfxTextureGather0(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather1(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather2(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord);
}
+
vec4 bgfxTextureGather3(BgfxSampler2DArray _sampler, vec3 _coord)
{
return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord);
@@ -394,7 +423,8 @@ vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod)
vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod)
{
vec3 result;
- _sampler.m_texture.GetDimensions(result.x, result.y, result.z);
+ float numberOfMipMapLevels;
+ _sampler.m_texture.GetDimensions(_lod, result.x, result.y, result.z, numberOfMipMapLevels);
return result;
}
EvilTrev commented
Thank you! That worked well. I also added the missing BgfxSamplerCube texture size functionality locally too.