If a hlsl_ir_load loads a variable whose components are stored from different
instructions, copy propagation doesn't replace it.
But if all these instructions are constants (which currently is the case
for value constructors), the load can be replaced with a constant value, which
is what the first patch of this series does.
For instance, this shader:
```
sampler s;
Texture2D t;
float4 main() : sv_target
{
return t.Gather(s, float2(0.6, 0.6), int2(0, 0));
}
```
results in the following IR before applying the patch:
```
float | 6.00000024e-01
float | 6.00000024e-01
uint | 0
| = (<constructor-2>[@4].x @2)
uint | 1
| = (<constructor-2>[@6].x @3)
float2 | <constructor-2>
int | 0
int | 0
uint | 0
| = (<constructor-5>[@11].x @9)
uint | 1
| = (<constructor-5>[@13].x @10)
int2 | <constructor-5>
float4 | gather_red(resource = t, sampler = s, coords = @8, offset = @15)
| return
| = (<output-sv_target0> @16)
```
and this IR afterwards:
```
float2 | {6.00000024e-01 6.00000024e-01 }
int2 | {0 0 }
float4 | gather_red(resource = t, sampler = s, coords = @2, offset = @3)
| return
| = (<output-sv_target0> @4)
```
This is required to write texel_offsets as aoffimmi modifiers in the sm4 backend, since it expects the texel_offset arguments to be hlsl_ir_constant.
This series also:
* Allows Gather() methods to use aoffimmi modifiers instead of an additional source register (which is the only way allowed for shader model 4.1), when possible.
* Adds support to texel_offsets in the Load() method via aoffimmi modifiers (the only allowed method).
--
v5: vkd3d-shader/hlsl: Propagate swizzle chains.
vkd3d-shader/hlsl: Replace swizzles with constants in copy prop.
tests: Test constant propagation through swizzles.
https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/51
Zebediah Figura (@zfigura) commented about dlls/kernelbase/path.c:
> + * First check for known, valid and typo free scheme
> + */
> + for (pos=1; pos<ARRAY_SIZE(url_scheme); pos++)
> + {
> + len = wcslen(url_scheme[pos]);
> + if ( (len <= wcslen(url)) && (!_wcsnicmp(url, url_scheme[pos], len)) )
> + {
> + /*
> + * check if string fits into maxChars
> + */
> + if (len+1 >= maxChars)
> + return S_FALSE;
> +
> + lstrcpynW(save_str, url_scheme[pos], len+1);
> + url += len;
> + goto scheme_done;
Can we use a helper function to fix up the scheme instead of using a goto? This will probably also help make the function easier to follow, by virtue of being less monolithic.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/1825#note_19809
Zebediah Figura (@zfigura) commented about dlls/kernelbase/path.c:
> */
> HRESULT WINAPI UrlFixupW(PCWSTR url, PWSTR translatedUrl, DWORD maxChars)
> {
> - DWORD srcLen;
> + DWORD srcLen, dstLen, len;
> + DWORD colon_pos = 0, pos = 0;
> + wchar_t *helper_str = NULL;
> + PWSTR save_str = translatedUrl;
We use WCHAR, not wchar_t.
It'd also be nice to use a consistent style for all of variable names in this function (wrt snake case vs camel case). In new code I think we prefer snake case.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/1825#note_19808
Zebediah Figura (@zfigura) commented about dlls/kernelbase/path.c:
>
> -HRESULT WINAPI UrlFixupW(const WCHAR *url, WCHAR *translatedUrl, DWORD maxChars)
> +/*
> + * from Documentation:
> + * https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-url…
> + *
> + * UrlFixupW attempts to correct a URL whose protocol identifier is incorrect.
> + * For example, htttp will be changed to http.
> + *
> + * LWSTDAPI UrlFixupW(
> + * [in] PCWSTR pcszUrl,
> + * [out] PWSTR pszTranslatedUrl,
> + * DWORD cchMax
> + * );
> +*/
> +HRESULT WINAPI UrlFixupW(PCWSTR url, PWSTR translatedUrl, DWORD maxChars)
Without trying to get bogged down in style, this change is somewhat counterproductive; we tend to avoid P* typedefs in new code, and we also have been abandoning the use of "documentation" style headers, which rarely convey any useful information.
(This also doesn't really belong in a commit which should only affect tests.)
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/1825#note_19805
On Sun Dec 18 23:01:30 2022 +0000, Zebediah Figura wrote:
> Hi Thomas, thanks for the patch!
> We want the tests to "pass" after every commit, i.e. have no failures.
> That may mean, in this case, introducing the tests marked as todo, and
> then later removing those todos.
Ok. Got it. Will do it soon
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/1825#note_19804