DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] Support arrays of RWStructuredBuffers

Open cassiebeckley opened this issue 2 years ago • 2 comments

I'm not confident this generates the correct code in all cases, so I'd appreciate it if there are any suggestions.

Fixes #3281

cassiebeckley avatar Sep 16 '22 08:09 cassiebeckley

:white_check_mark: Build DirectXShaderCompiler 1.0.2019 completed (commit https://github.com/microsoft/DirectXShaderCompiler/commit/f4e46832db by @cassiebeckley)

AppVeyorBot avatar Sep 16 '22 12:09 AppVeyorBot

Id love to have this merged. This would make my hlsl api much nicer.

Ipotrick avatar Sep 18 '22 21:09 Ipotrick

Is there a reason this was not merged?

GabeRundlett avatar Nov 24 '22 03:11 GabeRundlett

There are still outstanding comments. @cassiebeckley PTAL when you have a chance.

I'm ok with the -fspv-flatten-resource-arrays behavior being fixed in a follow-up PR , but the problem with the non-existent counter variable should be fixed before this is merged.

vettoreldaniele avatar Nov 24 '22 15:11 vettoreldaniele

Sorry for the slow response on this, things have been busy. I'll try to get to this by the end of the week

cassiebeckley avatar Dec 05 '22 17:12 cassiebeckley

Thank you!

Ipotrick avatar Dec 09 '22 22:12 Ipotrick

Quick update: I did make some progress on this, but I'm still working on making sure the correct error messages show up in the correct situations

cassiebeckley avatar Dec 12 '22 19:12 cassiebeckley

This would be amazing to have for bindless workflows!

cshenton avatar Feb 08 '23 07:02 cshenton

Added a new commit that prevents counters from being created from an array subscript expression, which should fix issue 2. There are some tricky situations which should probably also result in errors that I don't know how to fix - for example, a counter is always created for any buffer returned from a function call. This seems difficult to detect statically - the return value of the function is effectively the buffer + the counter, and the function could have a branch where it either returns a buffer from an array, or a buffer that is not from an array.

As for issue 1, I'll create a tracking issue to follow up.

cassiebeckley avatar Feb 14 '23 13:02 cassiebeckley

:white_check_mark: Build DirectXShaderCompiler 1.0.2817 completed (commit https://github.com/microsoft/DirectXShaderCompiler/commit/57103c1342 by @cassiebeckley)

AppVeyorBot avatar Feb 14 '23 14:02 AppVeyorBot

RWStructuredBuffer<float4> localSBuffer = MyRWSBuffer[index];
localSBuffer.IncrementCounter();

For cases like this, we should be able to issue an error during validation after legalization. We could add something to the validator or do a specific search in DXC for a load with an undef address.

s-perron avatar Feb 14 '23 14:02 s-perron

As for issue 2, I'll create a tracking issue to follow up.

We should discuss this. We should not give a partially working feature until we have a design to make it fully functional. Something like issue 2 is a clear bug that would be nearly impossible to debug. Is there a design doc for this?

s-perron avatar Feb 14 '23 14:02 s-perron

(I mixed up issue 1 and 2 in my comment, fixed it)

cassiebeckley avatar Feb 14 '23 17:02 cassiebeckley

(I mixed up issue 1 and 2 in my comment, fixed it)

Cool, what is the error message?

s-perron avatar Feb 14 '23 17:02 s-perron

At the moment,

arr.hlsl:5:12: fatal error: cannot find the associated counter variable
    return localSBuffer.IncrementCounter();
           ^

cassiebeckley avatar Feb 14 '23 17:02 cassiebeckley