mirror of
				https://gitlab.winehq.org/wine/vkd3d.git
				synced 2025-09-12 18:50:22 -07:00 
			
		
		
		
	vkd3d-shader/hlsl: Initialize static variables to 0 by default.
We are currently not initializing static values to zero by default.
Consider the following shader:
```hlsl
static float4 va;
float4 main() : sv_target
{
  return va;
}
```
we get the following output:
```
ps_5_0
dcl_output o0.xyzw
dcl_temps 2
mov r0.xyzw, r1.xyzw
mov o0.xyzw, r0.xyzw
ret
```
where r1.xyzw is not initialized.
This patch solves this by assigning the static variable the value of an
uint 0, and thus, relying on complex broadcasts.
This seems to be the behaviour of the 9.29.952.3111 version of the native
compiler, since it retrieves the following error on a shader that lacks
an initializer on a data type with object components:
```
error X3017: cannot convert from 'uint' to 'struct <unnamed>'
```
			
			
This commit is contained in:
		
				
					committed by
					
						 Alexandre Julliard
						Alexandre Julliard
					
				
			
			
				
	
			
			
			
						parent
						
							61f0d6d151
						
					
				
				
					commit
					5cfc8d378f
				
			
				
				Notes:
				
					Alexandre Julliard
				
				2023-01-19 22:45:10 +01:00 
			
			Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/54
| @@ -2174,6 +2174,41 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t | |||||||
|             vkd3d_free(v->initializer.args); |             vkd3d_free(v->initializer.args); | ||||||
|             vkd3d_free(v->initializer.instrs); |             vkd3d_free(v->initializer.instrs); | ||||||
|         } |         } | ||||||
|  |         else if (var->storage_modifiers & HLSL_STORAGE_STATIC) | ||||||
|  |         { | ||||||
|  |             struct hlsl_ir_constant *zero; | ||||||
|  |             struct hlsl_ir_store *store; | ||||||
|  |             struct hlsl_ir_node *cast; | ||||||
|  |  | ||||||
|  |             /* Initialize statics to zero by default. */ | ||||||
|  |  | ||||||
|  |             if (type_has_object_components(var->data_type, false)) | ||||||
|  |             { | ||||||
|  |                 hlsl_fixme(ctx, &var->loc, "Uninitialized static objects."); | ||||||
|  |                 vkd3d_free(v); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (!(zero = hlsl_new_uint_constant(ctx, 0, &var->loc))) | ||||||
|  |             { | ||||||
|  |                 vkd3d_free(v); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             list_add_tail(&ctx->static_initializers, &zero->node.entry); | ||||||
|  |  | ||||||
|  |             if (!(cast = add_cast(ctx, &ctx->static_initializers, &zero->node, var->data_type, &var->loc))) | ||||||
|  |             { | ||||||
|  |                 vkd3d_free(v); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (!(store = hlsl_new_simple_store(ctx, var, cast))) | ||||||
|  |             { | ||||||
|  |                 vkd3d_free(v); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             list_add_tail(&ctx->static_initializers, &store->node.entry); | ||||||
|  |         } | ||||||
|         vkd3d_free(v); |         vkd3d_free(v); | ||||||
|     } |     } | ||||||
|     vkd3d_free(var_list); |     vkd3d_free(var_list); | ||||||
|   | |||||||
| @@ -14,3 +14,12 @@ float4 main() : sv_target | |||||||
| [test] | [test] | ||||||
| draw quad | draw quad | ||||||
| todo probe all rgba (0.8, 0.0, 0.0, 0.0) | todo probe all rgba (0.8, 0.0, 0.0, 0.0) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | [pixel shader fail] | ||||||
|  | static uint i; | ||||||
|  |  | ||||||
|  | float4 main() : sv_target | ||||||
|  | { | ||||||
|  |     return 1 / i; | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user