Changeset View
Standalone View
source/blender/gpu/shaders/metal/mtl_shader_defines.msl
| Show First 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | else { | ||||
| return vec<S, 4>(0); | return vec<S, 4>(0); | ||||
| } | } | ||||
| } | } | ||||
| template<typename S, typename T, access A> | template<typename S, typename T, access A> | ||||
| inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex, | inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex, | ||||
| T texel, | T texel, | ||||
| uint lod, | uint lod, | ||||
| T offset = 0) | T offset) | ||||
fclem: If you make `offset` non optional, you need to change `#define texelFetch _texelFetch_internal`… | |||||
Not Done Inline ActionsThanks for the feedback! I believe this shouldn't be required, as the first overload variant (with optional LOD) still provides coverage for this case. The purpose of this patch was to remove a redundant, conflicting, definition of the function which utilised Vec<T, n> syntax for the 1D case, which was intended to add support for implicit casts from float to integer coordinates, though these variants are not needed as scalar type T can be used directly. The second case, was also caused by ambiguity when 3 integer arguments were passed in, as this could either refer to the first function (with optional LOD), or equally, the variant with default offset was also valid. So making the offset non-default ensures that the first two cases (2 and 3 arguments) always default to the first function, and the 4-argument case defaults to second function. Function 1): template<typename S, typename T, access A>
inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex,
T texel,
uint lod = 0)
{
float w = tex.texture->get_width();
if (texel >= 0 && texel < w) {
return tex.texture->read(uint(texel));
}
else {
return vec<S, 4>(0);
}
}Provides an overload for The second function (with default offset removed): template<typename S, typename T, access A>
inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex,
T texel,
uint lod,
T offset)
{
float w = tex.texture->get_width();
if ((texel + offset) >= 0 && (texel + offset) < w) {
/* LODs not supported for 1d textures. This must be zero. */
return tex.texture->read(uint(texel + offset), 0);
}
else {
return vec<S, 4>(0);
}
}Provides coverage for the texelFetchOffset(Tex, TexelCoord, LOD, Offset) case with 4 arguments. Adding in the macro arguments would always force 3 arguments to be used, which makes sense for the sampler 1D/2D/3D cases, however, for samplerBuffer, texelFetch in GLSL does not expose an LOD parameter, so this could cause secondary issues. The LOD parameter could however be made non-optional for the other cases, if this is preferred. But please let me know if I've misunderstood! MichaelPW: Thanks for the feedback!
I believe this shouldn't be required, as the first overload variant… | |||||
Done Inline ActionsMy bad! I understand now. This is all fine. fclem: My bad! I understand now. This is all fine. | |||||
| { | { | ||||
| float w = tex.texture->get_width(); | float w = tex.texture->get_width(); | ||||
| if ((texel + offset) >= 0 && (texel + offset) < w) { | if ((texel + offset) >= 0 && (texel + offset) < w) { | ||||
| /* LODs not supported for 1d textures. This must be zero. */ | /* LODs not supported for 1d textures. This must be zero. */ | ||||
| return tex.texture->read(uint(texel + offset), 0); | return tex.texture->read(uint(texel + offset), 0); | ||||
| } | } | ||||
| else { | else { | ||||
| return vec<S, 4>(0); | return vec<S, 4>(0); | ||||
| } | } | ||||
| } | } | ||||
| template<typename S, typename T, access A> | template<typename S, typename T, access A> | ||||
| inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex, | |||||
| vec<T, 1> texel, | |||||
| uint lod, | |||||
| vec<T, 1> offset = 0) | |||||
| { | |||||
| float w = tex.texture->get_width(); | |||||
| if ((texel + offset) >= 0 && (texel + offset) < w) { | |||||
| /* LODs not supported for 1d textures. This must be zero. */ | |||||
| return tex.texture->read(uint(texel + offset), 0); | |||||
| } | |||||
| else { | |||||
| return vec<S, 4>(0); | |||||
| } | |||||
| } | |||||
| template<typename S, typename T, int n, access A> | |||||
| inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex, | |||||
| vec<T, n> texel, | |||||
| uint lod, | |||||
| vec<T, n> offset = vec<T, n>(0)) | |||||
| { | |||||
| float w = tex.texture->get_width(); | |||||
| if ((texel.x + offset.x) >= 0 && (texel.x + offset.x) < w) { | |||||
| /* LODs not supported for 1d textures. This must be zero. */ | |||||
| return tex.texture->read(uint(texel.x + offset.x), 0); | |||||
| } | |||||
| else { | |||||
| return vec<S, 4>(0); | |||||
| } | |||||
| } | |||||
| template<typename S, typename T, access A> | |||||
| inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d_array<S, A> tex, | inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d_array<S, A> tex, | ||||
| vec<T, 2> texel, | vec<T, 2> texel, | ||||
| uint lod, | uint lod, | ||||
| vec<T, 2> offset = vec<T, 2>(0, 0)) | vec<T, 2> offset = vec<T, 2>(0, 0)) | ||||
| { | { | ||||
| float w = tex.texture->get_width(); | float w = tex.texture->get_width(); | ||||
| float h = tex.texture->get_array_size(); | float h = tex.texture->get_array_size(); | ||||
| ▲ Show 20 Lines • Show All 965 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return mat3(a, b, c); | return mat3(a, b, c); | ||||
| } | } | ||||
| mat3 MAT3x3( | mat3 MAT3x3( | ||||
| float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3) | float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3) | ||||
| { | { | ||||
| return mat3(vec3(a1, a2, a3), vec3(b1, b2, b3), vec3(c1, c2, c3)); | return mat3(vec3(a1, a2, a3), vec3(b1, b2, b3), vec3(c1, c2, c3)); | ||||
| } | } | ||||
| mat3 MAT3x3( | mat3 MAT3x3(vec3 a, float b1, float b2, float b3, float c1, float c2, float c3) | ||||
| vec3 a, float b1, float b2, float b3, float c1, float c2, float c3) | |||||
| { | { | ||||
| return mat3(a, vec3(b1, b2, b3), vec3(c1, c2, c3)); | return mat3(a, vec3(b1, b2, b3), vec3(c1, c2, c3)); | ||||
| } | } | ||||
| mat3 MAT3x3(float f) | mat3 MAT3x3(float f) | ||||
| { | { | ||||
| return mat3(f); | return mat3(f); | ||||
| } | } | ||||
| mat3 MAT3x3(mat4 m) | mat3 MAT3x3(mat4 m) | ||||
| ▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines | |||||
If you make offset non optional, you need to change #define texelFetch _texelFetch_internal into #define texelFetch(__tex, __texel, __lod) _texelFetch_internal(__tex, __texel, __lod).