microsoft / microsoft/DirectXShaderCompiler
Compile-time goes up when "this" keyword is used as an argument for a global function.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
When a global function is called with "this" from a member function, the performance goes worse than expected and the generated binary size becomes unusually bigger.
Steps to Reproduce
When I compile the following HLSL without "USE_MEMBER", the compile-time takes much longer than with "USE_MEMBER".
The generated DXIL binary is also bigger than expected without "USE_MEMBER".
#ifndef LOOP_COUNT
#define LOOP_COUNT 1000
#endif
RWByteAddressBuffer buffer;
struct MyStruct;
void MyStruct_SetValue(inout MyStruct o, int i, float v);
struct MyStruct
{
float values[LOOP_COUNT];
void SetValue(int i, float v)
{
values[i] = v;
}
void Init(float v)
{
for (int i = 0; i < LOOP_COUNT; ++i)
{
#ifdef USE_MEMBER
this.SetValue(i, v);
#else
MyStruct_SetValue(this, i, v);
#endif
}
}
};
void MyStruct_SetValue(inout MyStruct o, int i, float v)
{
o.values[i] = v;
}
[numthreads(4, 1, 1)]
void MainCS(uint2 gid : SV_GroupID, uint gidx : SV_GroupIndex)
{
MyStruct src;
src.Init(0.f);
// For some reason, this copy construction is required to
// reproduce the issue
MyStruct dst = src;
for (int i = 0; i < LOOP_COUNT; i++)
buffer.Store<float>(i * 4, dst.values[i]);
}
You can compile it with following commands:
dxc.exe -E MainCS -T cs_6_6 -DUSE_MEMBER test.hlsl -Fo with_USE_MEMBER.out
dxc.exe -E MainCS -T cs_6_6 test.hlsl -Fo without_USE_MEMBER.out
Actual Behavior
Following files are generated when they are expected to be in a same or similar sizes.
-rwxrwxrwx 1 jkwak jkwak 3124 Apr 9 00:28 with_USE_MEMBER.out
-rwxrwxrwx 1 jkwak jkwak 31072 Apr 9 00:28 without_USE_MEMBER.out
Compile-time was 0.1 second for with_USE_MEMBER.out
ANd it was 0.4 seconds for without_USE_MEMBER.out
Environment
- DXC version : dxcompiler.dll: 1.7 - 1.7.0.4152 (93ad5b313)
- Host Operating System : Windows 11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied HLSL reproducer and run the two dxc.exe commands with and without USE_MEMBER to confirm the compile-time and DXIL size difference. No source files or tests are named; done means identifying and correcting the compiler behavior so both forms produce similar compile times and binary sizes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100