Skip to content

Commit

Permalink
[Vk/GL] Declare textures as mediump when appropriate
Browse files Browse the repository at this point in the history
We were doing this for Metal, but not for GLSL.
  • Loading branch information
darksylinc committed Nov 16, 2023
1 parent 6d06db9 commit bb07bae
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
#define midf3x3_c mat3
#define midf4x4_c mat4

#define midf_tex

#define toMidf3x3( x ) mat3( x )
#define buildMidf3x3( row0, row1, row2 ) mat3( row0, row1, row2 )

Expand Down Expand Up @@ -152,6 +154,8 @@
#define midf3x3_c f16mat3x3
#define midf4x4_c f16mat4x4

#define midf_tex mediump

#define toMidf3x3( x ) f16mat3x3( x )
#define buildMidf3x3( row0, row1, row2 ) f16mat3x3( row0, row1, row2 )

Expand Down Expand Up @@ -190,6 +194,8 @@
#define midf3x3_c mat3
#define midf4x4_c mat4

#define midf_tex mediump

#define toMidf3x3( x ) mat3( x )
#define buildMidf3x3( row0, row1, row2 ) mat3( row0, row1, row2 )

Expand Down
2 changes: 1 addition & 1 deletion Samples/Media/Hlms/Pbs/Any/AreaLights_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
uniform sampler2DArray areaLightMasks;
@end
@property( syntax == glslvk )
layout( ogre_t@value(areaLightMasks) ) uniform texture2DArray areaLightMasks;
layout( ogre_t@value(areaLightMasks) ) midf_tex uniform texture2DArray areaLightMasks;
layout( ogre_s@value(areaLightMasks) ) uniform sampler areaLightMasksSampler;
@end
@property( syntax == hlsl )
Expand Down
4 changes: 2 additions & 2 deletions Samples/Media/Hlms/Pbs/Any/Main/200.Textures_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
uniform sampler2DArray ltcMatrix;
@end
@property( syntax == glslvk )
layout( ogre_t@value(ltcMatrix) ) uniform texture2DArray ltcMatrix;
layout( ogre_s@value(ltcMatrix) ) uniform sampler ltcSampler;
layout( ogre_t@value(ltcMatrix) ) midf_tex uniform texture2DArray ltcMatrix;
layout( ogre_s@value(ltcMatrix) ) midf_tex uniform sampler ltcSampler;
@end
@property( syntax == hlsl )
Texture2DArray<float4> ltcMatrix : register(t@value(ltcMatrix));
Expand Down
6 changes: 3 additions & 3 deletions Samples/Media/Hlms/Pbs/GLSL/Forward3D_piece_ps.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
@property( syntax == glslvk )
layout( ogre_s@value(decalsSampler) ) uniform sampler decalsSampler;
@end
@property( hlms_decals_diffuse )vulkan_layout( ogre_t@value(decalsDiffuseTex) ) uniform texture2DArray decalsDiffuseTex;@end
@property( hlms_decals_normals )vulkan_layout( ogre_t@value(decalsNormalsTex) ) uniform texture2DArray decalsNormalsTex;@end
@property( hlms_decals_diffuse )vulkan_layout( ogre_t@value(decalsDiffuseTex) ) midf_tex uniform texture2DArray decalsDiffuseTex;@end
@property( hlms_decals_normals )vulkan_layout( ogre_t@value(decalsNormalsTex) ) midf_tex uniform texture2DArray decalsNormalsTex;@end
@property( hlms_decals_diffuse == hlms_decals_emissive )
#define decalsEmissiveTex decalsDiffuseTex
@end
@property( hlms_decals_emissive && hlms_decals_diffuse != hlms_decals_emissive )
vulkan_layout( ogre_t@value(decalsEmissiveTex) ) uniform texture2DArray decalsEmissiveTex;
vulkan_layout( ogre_t@value(decalsEmissiveTex) ) midf_tex uniform texture2DArray decalsEmissiveTex;
@end
@end
@end
Expand Down
18 changes: 9 additions & 9 deletions Samples/Media/Hlms/Pbs/GLSL/PixelShader_ps.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ layout(std140) uniform;
vulkan_layout( ogre_t@value(depthTextureNoMsaa) ) uniform texture2D depthTextureNoMsaa;
@end
@end
vulkan_layout( ogre_t@value(refractionMap) ) uniform texture2D refractionMap;
vulkan( layout( ogre_s@value(refractionMap) ) uniform sampler refractionMapSampler );
vulkan_layout( ogre_t@value(refractionMap) ) midf_tex uniform texture2D refractionMap;
vulkan( layout( ogre_s@value(refractionMap) ) uniform sampler refractionMapSampler );
@end

@insertpiece( DeclPlanarReflTextures )
Expand Down Expand Up @@ -82,21 +82,21 @@ vulkan_layout( location = 0 ) in block
ReadOnlyBufferF( @value(f3dLightList), float4, f3dLightList );
@end
@property( irradiance_volumes )
vulkan_layout( ogre_t@value(irradianceVolume) ) uniform texture3D irradianceVolume;
vulkan( layout( ogre_s@value(irradianceVolume) )uniform sampler irradianceVolumeSampler );
vulkan_layout( ogre_t@value(irradianceVolume) ) midf_tex uniform texture3D irradianceVolume;
vulkan( layout( ogre_s@value(irradianceVolume) )uniform sampler irradianceVolumeSampler );
@end

@foreach( num_textures, n )
vulkan_layout( ogre_t@value(textureMaps@n) ) uniform texture2DArray textureMaps@n;@end
vulkan_layout( ogre_t@value(textureMaps@n) ) midf_tex uniform texture2DArray textureMaps@n;@end

@property( use_envprobe_map )
@property( !hlms_enable_cubemaps_auto )
vulkan_layout( ogre_t@value(texEnvProbeMap) ) uniform textureCube texEnvProbeMap;
vulkan_layout( ogre_t@value(texEnvProbeMap) ) midf_tex uniform textureCube texEnvProbeMap;
@else
@property( !hlms_cubemaps_use_dpm )
vulkan_layout( ogre_t@value(texEnvProbeMap) ) uniform textureCubeArray texEnvProbeMap;
vulkan_layout( ogre_t@value(texEnvProbeMap) ) midf_tex uniform textureCubeArray texEnvProbeMap;
@else
vulkan_layout( ogre_t@value(texEnvProbeMap) ) uniform texture2DArray texEnvProbeMap;
vulkan_layout( ogre_t@value(texEnvProbeMap) ) midf_tex uniform texture2DArray texEnvProbeMap;
@insertpiece( DeclDualParaboloidFunc )
@end
@end
Expand Down Expand Up @@ -140,7 +140,7 @@ void main()

@property( alpha_test )
@foreach( num_textures, n )
vulkan_layout( ogre_t@value(textureMaps@n) ) uniform texture2DArray textureMaps@n;@end
vulkan_layout( ogre_t@value(textureMaps@n) ) midf_tex uniform texture2DArray textureMaps@n;@end

@property( syntax == glslvk )
@foreach( num_samplers, n )
Expand Down
16 changes: 8 additions & 8 deletions Samples/Media/Hlms/Terra/GLSL/PixelShader_ps.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ in block
in vec4 gl_FragCoord;
@end

vulkan_layout( ogre_t@value(terrainNormals) ) uniform texture2D terrainNormals;
vulkan_layout( ogre_t@value(terrainShadows) ) uniform texture2D terrainShadows;
vulkan_layout( ogre_t@value(terrainNormals) ) midf_tex uniform texture2D terrainNormals;
vulkan_layout( ogre_t@value(terrainShadows) ) midf_tex uniform texture2D terrainShadows;
vulkan( layout( ogre_s@value(terrainNormals) ) uniform sampler samplerStateTerra );

@property( hlms_forwardplus )
vulkan_layout( ogre_T@value(f3dGrid) ) uniform usamplerBuffer f3dGrid;
ReadOnlyBufferF( @value(f3dLightList), float4, f3dLightList );
@end
@property( irradiance_volumes )
vulkan_layout( ogre_t@value(irradianceVolume) ) uniform texture3D irradianceVolume;
vulkan( layout( ogre_s@value(irradianceVolume) )uniform sampler irradianceVolumeSampler );
vulkan_layout( ogre_t@value(irradianceVolume) ) midf_tex uniform texture3D irradianceVolume;
vulkan( layout( ogre_s@value(irradianceVolume) )uniform sampler irradianceVolumeSampler );
@end

@foreach( num_textures, n )
vulkan_layout( ogre_t@value(textureMaps@n) ) uniform texture2DArray textureMaps@n;@end
vulkan_layout( ogre_t@value(textureMaps@n) ) midf_tex uniform texture2DArray textureMaps@n;@end

@property( use_envprobe_map )
@property( !hlms_enable_cubemaps_auto )
vulkan_layout( ogre_t@value(texEnvProbeMap) ) uniform textureCube texEnvProbeMap;
vulkan_layout( ogre_t@value(texEnvProbeMap) ) midf_tex uniform textureCube texEnvProbeMap;
@else
@property( !hlms_cubemaps_use_dpm )
vulkan_layout( ogre_t@value(texEnvProbeMap) ) uniform textureCubeArray texEnvProbeMap;
vulkan_layout( ogre_t@value(texEnvProbeMap) ) midf_tex uniform textureCubeArray texEnvProbeMap;
@else
vulkan_layout( ogre_t@value(texEnvProbeMap) ) uniform texture2DArray texEnvProbeMap;
vulkan_layout( ogre_t@value(texEnvProbeMap) ) midf_tex uniform texture2DArray texEnvProbeMap;
@insertpiece( DeclDualParaboloidFunc )
@end
@end
Expand Down
8 changes: 4 additions & 4 deletions Samples/Media/Hlms/Unlit/GLSL/PixelShader_ps.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ layout(location = FRAG_COLOR, index = 0) out midf outColour;
@property( syntax != glslvk )
@foreach( num_textures, n )
@property( is_texture@n_array )
uniform sampler2DArray textureMapsArray@n;
midf_tex uniform sampler2DArray textureMapsArray@n;
@else
uniform sampler2D textureMaps@n;
midf_tex uniform sampler2D textureMaps@n;
@end
@end
@else
@foreach( num_textures, n )
@property( is_texture@n_array )
layout( ogre_t@value(textureMapsArray@n) ) uniform texture2DArray textureMapsArray@n;
layout( ogre_t@value(textureMapsArray@n) ) midf_tex uniform texture2DArray textureMapsArray@n;
@else
layout( ogre_t@value(textureMaps@n) ) uniform texture2D textureMaps@n;
layout( ogre_t@value(textureMaps@n) ) midf_tex uniform texture2D textureMaps@n;
@end
@end
@end
Expand Down

0 comments on commit bb07bae

Please sign in to comment.