-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Handle DS_READ_U16, DS_WRITE_B16, DS_ADD_U64 #3007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle DS_READ_U16, DS_WRITE_B16, DS_ADD_U64 #3007
Conversation
@@ -6,6 +6,13 @@ | |||
|
|||
namespace Shader::Backend::SPIRV { | |||
|
|||
Id EmitLoadSharedU16(EmitContext& ctx, Id offset) { | |||
const Id shift_id{ctx.ConstU32(2U)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure shift by 2 (divide by 4) is still correct for a 16-bit value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, documentation doesn't really say that, they use addr
for all accesses 16/32/64bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I suppose regardless of guest requirements you do need to have the right index for whatever we are using on the SPIR-V side, for example if we have a shared memory u16 array you need to shift 1 over to index by u16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are using an array of 32 bit values, so dividing by 4 will be the base index, and then you need to take either the upper or lower part depending on the first bit:
result = ((offset & 1)=0) ? buf[offset/4] & 0xFFFF : buf[offset/4] & 0xFFFF0000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the second bit is not the first, lol
result = ((offset & 2)=0) ? buf[offset/4] & 0xFFFF : buf[offset/4] & 0xFFFF0000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach mentioned by @red-prig here is probably correct if we don't have a way in SPIR-V to alias the same shared memory array as a different type (I don't remember if this is the case). The code as of current revision creates two separate arrays which could be problematic if a shader mixes access sizes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating aliases usually works fine, the problem is more likely in addressing a 16-bit value, not all GPUs support this, and those that do may work slower
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are fine in that regard given we already may do so for buffers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm working on a better implementation with aliasing definitions for u16/32/64, as the partial access mentioned by red_prig won't work for atomic operations
src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp
Outdated
Show resolved
Hide resolved
src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp
Outdated
Show resolved
Hide resolved
src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp
Outdated
Show resolved
Hide resolved
07e0417
to
dc8f050
Compare
187c22d
to
236aacb
Compare
236aacb
to
72553c4
Compare
Review issues seems to be fixed |
Hit by God of War