Merge pull request #51843 from reduz/fixes-to-mobile-renderer-3

More fixes to mobile renderer
This commit is contained in:
Rémi Verschelde 2021-08-18 20:43:25 +02:00 committed by GitHub
commit f6626a40e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 125 additions and 108 deletions

View file

@ -213,7 +213,7 @@ static String _interpstr(SL::DataInterpolation p_interp) {
return ""; return "";
} }
static String _prestr(SL::DataPrecision p_pres) { static String _prestr(SL::DataPrecision p_pres, bool p_force_highp = false) {
switch (p_pres) { switch (p_pres) {
case SL::PRECISION_LOWP: case SL::PRECISION_LOWP:
return "lowp "; return "lowp ";
@ -222,7 +222,7 @@ static String _prestr(SL::DataPrecision p_pres) {
case SL::PRECISION_HIGHP: case SL::PRECISION_HIGHP:
return "highp "; return "highp ";
case SL::PRECISION_DEFAULT: case SL::PRECISION_DEFAULT:
return ""; return p_force_highp ? "highp " : "";
} }
return ""; return "";
} }
@ -617,7 +617,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
//this is an integer to index the global table //this is an integer to index the global table
ucode += _typestr(ShaderLanguage::TYPE_UINT); ucode += _typestr(ShaderLanguage::TYPE_UINT);
} else { } else {
ucode += _prestr(uniform.precision); ucode += _prestr(uniform.precision, ShaderLanguage::is_float_type(uniform.type));
ucode += _typestr(uniform.type); ucode += _typestr(uniform.type);
} }
@ -742,7 +742,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
String vcode; String vcode;
String interp_mode = _interpstr(varying.interpolation); String interp_mode = _interpstr(varying.interpolation);
vcode += _prestr(varying.precision); vcode += _prestr(varying.precision, ShaderLanguage::is_float_type(varying.type));
vcode += _typestr(varying.type); vcode += _typestr(varying.type);
vcode += " " + _mkid(varying_name); vcode += " " + _mkid(varying_name);
if (varying.array_size > 0) { if (varying.array_size > 0) {
@ -777,7 +777,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
const SL::ShaderNode::Constant &cnode = pnode->vconstants[i]; const SL::ShaderNode::Constant &cnode = pnode->vconstants[i];
String gcode; String gcode;
gcode += "const "; gcode += "const ";
gcode += _prestr(cnode.precision); gcode += _prestr(cnode.precision, ShaderLanguage::is_float_type(cnode.type));
if (cnode.type == SL::TYPE_STRUCT) { if (cnode.type == SL::TYPE_STRUCT) {
gcode += _mkid(cnode.type_str); gcode += _mkid(cnode.type_str);
} else { } else {

View file

@ -1,18 +1,18 @@
struct DecalData { struct DecalData {
mat4 xform; //to decal transform highp mat4 xform; //to decal transform
vec3 inv_extents; highp vec3 inv_extents;
float albedo_mix; mediump float albedo_mix;
vec4 albedo_rect; highp vec4 albedo_rect;
vec4 normal_rect; highp vec4 normal_rect;
vec4 orm_rect; highp vec4 orm_rect;
vec4 emission_rect; highp vec4 emission_rect;
vec4 modulate; highp vec4 modulate;
float emission_energy; mediump float emission_energy;
uint mask; uint mask;
float upper_fade; mediump float upper_fade;
float lower_fade; mediump float lower_fade;
mat3x4 normal_xform; mediump mat3x4 normal_xform;
vec3 normal; mediump vec3 normal;
float normal_fade; mediump float normal_fade;
}; };

View file

@ -4,28 +4,28 @@
struct LightData { //this structure needs to be as packed as possible struct LightData { //this structure needs to be as packed as possible
highp vec3 position; highp vec3 position;
float inv_radius; highp float inv_radius;
vec3 direction; mediump vec3 direction;
float size; highp float size;
vec3 color; mediump vec3 color;
float attenuation; mediump float attenuation;
float cone_attenuation; mediump float cone_attenuation;
float cone_angle; mediump float cone_angle;
float specular_amount; mediump float specular_amount;
bool shadow_enabled; bool shadow_enabled;
highp vec4 atlas_rect; // rect in the shadow atlas highp vec4 atlas_rect; // rect in the shadow atlas
highp mat4 shadow_matrix; highp mat4 shadow_matrix;
float shadow_bias; highp float shadow_bias;
float shadow_normal_bias; highp float shadow_normal_bias;
float transmittance_bias; highp float transmittance_bias;
float soft_shadow_size; // for spot, it's the size in uv coordinates of the light, for omni it's the span angle highp float soft_shadow_size; // for spot, it's the size in uv coordinates of the light, for omni it's the span angle
float soft_shadow_scale; // scales the shadow kernel for blurrier shadows highp float soft_shadow_scale; // scales the shadow kernel for blurrier shadows
uint mask; uint mask;
float shadow_volumetric_fog_fade; mediump float shadow_volumetric_fog_fade;
uint bake_mode; uint bake_mode;
highp vec4 projector_rect; //projector rect in srgb decal atlas highp vec4 projector_rect; //projector rect in srgb decal atlas
}; };
@ -35,53 +35,53 @@ struct LightData { //this structure needs to be as packed as possible
#define REFLECTION_AMBIENT_COLOR 2 #define REFLECTION_AMBIENT_COLOR 2
struct ReflectionData { struct ReflectionData {
vec3 box_extents; highp vec3 box_extents;
float index; mediump float index;
vec3 box_offset; highp vec3 box_offset;
uint mask; uint mask;
vec3 ambient; // ambient color mediump vec3 ambient; // ambient color
float intensity; mediump float intensity;
bool exterior; bool exterior;
bool box_project; bool box_project;
uint ambient_mode; uint ambient_mode;
uint pad; uint pad;
//0-8 is intensity,8-9 is ambient, mode //0-8 is intensity,8-9 is ambient, mode
mat4 local_matrix; // up to here for spot and omni, rest is for directional highp mat4 local_matrix; // up to here for spot and omni, rest is for directional
// notes: for ambientblend, use distance to edge to blend between already existing global environment // notes: for ambientblend, use distance to edge to blend between already existing global environment
}; };
struct DirectionalLightData { struct DirectionalLightData {
vec3 direction; mediump vec3 direction;
float energy; mediump float energy;
vec3 color; mediump vec3 color;
float size; mediump float size;
float specular; mediump float specular;
uint mask; uint mask;
float softshadow_angle; highp float softshadow_angle;
float soft_shadow_scale; highp float soft_shadow_scale;
bool blend_splits; bool blend_splits;
bool shadow_enabled; bool shadow_enabled;
float fade_from; highp float fade_from;
float fade_to; highp float fade_to;
uvec2 pad; uvec2 pad;
uint bake_mode; uint bake_mode;
float shadow_volumetric_fog_fade; mediump float shadow_volumetric_fog_fade;
vec4 shadow_bias; highp vec4 shadow_bias;
vec4 shadow_normal_bias; highp vec4 shadow_normal_bias;
vec4 shadow_transmittance_bias; highp vec4 shadow_transmittance_bias;
highp vec4 shadow_z_range; highp vec4 shadow_z_range;
highp vec4 shadow_range_begin; highp vec4 shadow_range_begin;
vec4 shadow_split_offsets; highp vec4 shadow_split_offsets;
highp mat4 shadow_matrix1; highp mat4 shadow_matrix1;
highp mat4 shadow_matrix2; highp mat4 shadow_matrix2;
highp mat4 shadow_matrix3; highp mat4 shadow_matrix3;
highp mat4 shadow_matrix4; highp mat4 shadow_matrix4;
vec4 shadow_color1; mediump vec4 shadow_color1;
vec4 shadow_color2; mediump vec4 shadow_color2;
vec4 shadow_color3; mediump vec4 shadow_color3;
vec4 shadow_color4; mediump vec4 shadow_color4;
vec2 uv_scale1; highp vec2 uv_scale1;
vec2 uv_scale2; highp vec2 uv_scale2;
vec2 uv_scale3; highp vec2 uv_scale3;
vec2 uv_scale4; highp vec2 uv_scale4;
}; };

View file

@ -92,7 +92,7 @@ layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms
#ifdef MODE_DUAL_PARABOLOID #ifdef MODE_DUAL_PARABOLOID
layout(location = 8) out float dp_clip; layout(location = 8) out highp float dp_clip;
#endif #endif
@ -370,11 +370,6 @@ void main() {
#VERSION_DEFINES #VERSION_DEFINES
//use medium precision for floats on mobile.
precision mediump float;
precision highp int;
/* Specialization Constants */ /* Specialization Constants */
#if !defined(MODE_RENDER_DEPTH) #if !defined(MODE_RENDER_DEPTH)
@ -498,7 +493,7 @@ layout(location = 0) out vec4 diffuse_buffer; //diffuse (rgb) and roughness
layout(location = 1) out vec4 specular_buffer; //specular and SSS (subsurface scatter) layout(location = 1) out vec4 specular_buffer; //specular and SSS (subsurface scatter)
#else #else
layout(location = 0) out vec4 frag_color; layout(location = 0) out mediump vec4 frag_color;
#endif // MODE_MULTIPLE_RENDER_TARGETS #endif // MODE_MULTIPLE_RENDER_TARGETS
#endif // RENDER DEPTH #endif // RENDER DEPTH

View file

@ -93,7 +93,7 @@ directional_lights;
#define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2 #define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2
struct Lightmap { struct Lightmap {
mat3 normal_xform; mediump mat3 normal_xform;
}; };
layout(set = 0, binding = 9, std140) restrict readonly buffer Lightmaps { layout(set = 0, binding = 9, std140) restrict readonly buffer Lightmaps {
@ -102,7 +102,7 @@ layout(set = 0, binding = 9, std140) restrict readonly buffer Lightmaps {
lightmaps; lightmaps;
struct LightmapCapture { struct LightmapCapture {
vec4 sh[9]; mediump vec4 sh[9];
}; };
layout(set = 0, binding = 10, std140) restrict readonly buffer LightmapCaptures { layout(set = 0, binding = 10, std140) restrict readonly buffer LightmapCaptures {
@ -110,8 +110,8 @@ layout(set = 0, binding = 10, std140) restrict readonly buffer LightmapCaptures
} }
lightmap_captures; lightmap_captures;
layout(set = 0, binding = 11) uniform texture2D decal_atlas; layout(set = 0, binding = 11) uniform mediump texture2D decal_atlas;
layout(set = 0, binding = 12) uniform texture2D decal_atlas_srgb; layout(set = 0, binding = 12) uniform mediump texture2D decal_atlas_srgb;
layout(set = 0, binding = 13, std430) restrict readonly buffer Decals { layout(set = 0, binding = 13, std430) restrict readonly buffer Decals {
DecalData data[]; DecalData data[];
@ -119,7 +119,7 @@ layout(set = 0, binding = 13, std430) restrict readonly buffer Decals {
decals; decals;
layout(set = 0, binding = 14, std430) restrict readonly buffer GlobalVariableData { layout(set = 0, binding = 14, std430) restrict readonly buffer GlobalVariableData {
vec4 data[]; highp vec4 data[];
} }
global_variables; global_variables;
@ -135,56 +135,56 @@ layout(set = 1, binding = 0, std140) uniform SceneData {
highp mat4 projection_matrix_view[MAX_VIEWS]; highp mat4 projection_matrix_view[MAX_VIEWS];
highp mat4 inv_projection_matrix_view[MAX_VIEWS]; highp mat4 inv_projection_matrix_view[MAX_VIEWS];
vec2 viewport_size; highp vec2 viewport_size;
vec2 screen_pixel_size; highp vec2 screen_pixel_size;
// Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted. // Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted.
vec4 directional_penumbra_shadow_kernel[32]; highp vec4 directional_penumbra_shadow_kernel[32];
vec4 directional_soft_shadow_kernel[32]; highp vec4 directional_soft_shadow_kernel[32];
vec4 penumbra_shadow_kernel[32]; highp vec4 penumbra_shadow_kernel[32];
vec4 soft_shadow_kernel[32]; highp vec4 soft_shadow_kernel[32];
vec4 ambient_light_color_energy; mediump vec4 ambient_light_color_energy;
float ambient_color_sky_mix; mediump float ambient_color_sky_mix;
bool use_ambient_light; bool use_ambient_light;
bool use_ambient_cubemap; bool use_ambient_cubemap;
bool use_reflection_cubemap; bool use_reflection_cubemap;
mat3 radiance_inverse_xform; mediump mat3 radiance_inverse_xform;
vec2 shadow_atlas_pixel_size; highp vec2 shadow_atlas_pixel_size;
vec2 directional_shadow_pixel_size; highp vec2 directional_shadow_pixel_size;
uint directional_light_count; uint directional_light_count;
float dual_paraboloid_side; mediump float dual_paraboloid_side;
float z_far; highp float z_far;
float z_near; highp float z_near;
bool ssao_enabled; bool ssao_enabled;
float ssao_light_affect; mediump float ssao_light_affect;
float ssao_ao_affect; mediump float ssao_ao_affect;
bool roughness_limiter_enabled; bool roughness_limiter_enabled;
float roughness_limiter_amount; mediump float roughness_limiter_amount;
float roughness_limiter_limit; mediump float roughness_limiter_limit;
uvec2 roughness_limiter_pad; uvec2 roughness_limiter_pad;
vec4 ao_color; mediump vec4 ao_color;
bool fog_enabled; bool fog_enabled;
float fog_density; highp float fog_density;
float fog_height; highp float fog_height;
float fog_height_density; highp float fog_height_density;
vec3 fog_light_color; mediump vec3 fog_light_color;
float fog_sun_scatter; mediump float fog_sun_scatter;
float fog_aerial_perspective; mediump float fog_aerial_perspective;
bool material_uv2_mode; bool material_uv2_mode;
float time; highp float time;
float reflection_multiplier; // one normally, zero when rendering reflections mediump float reflection_multiplier; // one normally, zero when rendering reflections
bool pancake_shadows; bool pancake_shadows;
uint pad1; uint pad1;
@ -195,30 +195,30 @@ scene_data;
#ifdef USE_RADIANCE_CUBEMAP_ARRAY #ifdef USE_RADIANCE_CUBEMAP_ARRAY
layout(set = 1, binding = 2) uniform textureCubeArray radiance_cubemap; layout(set = 1, binding = 2) uniform mediump textureCubeArray radiance_cubemap;
#else #else
layout(set = 1, binding = 2) uniform textureCube radiance_cubemap; layout(set = 1, binding = 2) uniform mediump textureCube radiance_cubemap;
#endif #endif
layout(set = 1, binding = 3) uniform textureCubeArray reflection_atlas; layout(set = 1, binding = 3) uniform mediump textureCubeArray reflection_atlas;
layout(set = 1, binding = 4) uniform texture2D shadow_atlas; layout(set = 1, binding = 4) uniform highp texture2D shadow_atlas;
layout(set = 1, binding = 5) uniform texture2D directional_shadow_atlas; layout(set = 1, binding = 5) uniform highp texture2D directional_shadow_atlas;
// this needs to change to providing just the lightmap we're using.. // this needs to change to providing just the lightmap we're using..
layout(set = 1, binding = 6) uniform texture2DArray lightmap_textures[MAX_LIGHTMAP_TEXTURES]; layout(set = 1, binding = 6) uniform texture2DArray lightmap_textures[MAX_LIGHTMAP_TEXTURES];
layout(set = 1, binding = 9) uniform texture2D depth_buffer; layout(set = 1, binding = 9) uniform highp texture2D depth_buffer;
layout(set = 1, binding = 10) uniform texture2D color_buffer; layout(set = 1, binding = 10) uniform mediump texture2D color_buffer;
/* Set 2 Skeleton & Instancing (can change per item) */ /* Set 2 Skeleton & Instancing (can change per item) */
layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms { layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms {
vec4 data[]; highp vec4 data[];
} }
transforms; transforms;

View file

@ -2877,6 +2877,27 @@ bool ShaderLanguage::is_scalar_type(DataType p_type) {
return p_type == TYPE_BOOL || p_type == TYPE_INT || p_type == TYPE_UINT || p_type == TYPE_FLOAT; return p_type == TYPE_BOOL || p_type == TYPE_INT || p_type == TYPE_UINT || p_type == TYPE_FLOAT;
} }
bool ShaderLanguage::is_float_type(DataType p_type) {
switch (p_type) {
case TYPE_FLOAT:
case TYPE_VEC2:
case TYPE_VEC3:
case TYPE_VEC4:
case TYPE_MAT2:
case TYPE_MAT3:
case TYPE_MAT4:
case TYPE_SAMPLER2D:
case TYPE_SAMPLER2DARRAY:
case TYPE_SAMPLER3D:
case TYPE_SAMPLERCUBE:
case TYPE_SAMPLERCUBEARRAY: {
return true;
}
default: {
return false;
}
}
}
bool ShaderLanguage::is_sampler_type(DataType p_type) { bool ShaderLanguage::is_sampler_type(DataType p_type) {
return p_type == TYPE_SAMPLER2D || return p_type == TYPE_SAMPLER2D ||
p_type == TYPE_ISAMPLER2D || p_type == TYPE_ISAMPLER2D ||

View file

@ -774,6 +774,7 @@ public:
static DataType get_scalar_type(DataType p_type); static DataType get_scalar_type(DataType p_type);
static int get_cardinality(DataType p_type); static int get_cardinality(DataType p_type);
static bool is_scalar_type(DataType p_type); static bool is_scalar_type(DataType p_type);
static bool is_float_type(DataType p_type);
static bool is_sampler_type(DataType p_type); static bool is_sampler_type(DataType p_type);
static Variant constant_value_to_variant(const Vector<ShaderLanguage::ConstantNode::Value> &p_value, DataType p_type, ShaderLanguage::ShaderNode::Uniform::Hint p_hint = ShaderLanguage::ShaderNode::Uniform::HINT_NONE); static Variant constant_value_to_variant(const Vector<ShaderLanguage::ConstantNode::Value> &p_value, DataType p_type, ShaderLanguage::ShaderNode::Uniform::Hint p_hint = ShaderLanguage::ShaderNode::Uniform::HINT_NONE);
static PropertyInfo uniform_to_property_info(const ShaderNode::Uniform &p_uniform); static PropertyInfo uniform_to_property_info(const ShaderNode::Uniform &p_uniform);