Skip to content
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

video_core: Add constant buffer support #147

Merged
merged 1 commit into from
May 26, 2024
Merged

video_core: Add constant buffer support #147

merged 1 commit into from
May 26, 2024

Conversation

raphaelthegreat
Copy link
Collaborator

@raphaelthegreat raphaelthegreat commented May 26, 2024

Next step after previous PR was to add constant buffers to shader recompiler. The goal of the design is to hopefully be able to handle more advanced cases like bindless or when sharps are nested behind many constant load operations. So in general, cases where sharp location is difficult to know upfront. When emitting IR we the recompiler is not aware of the sharp location. The emitted instruction will have a handle that is the SGPR of the loaded sharp and some additional arguments that we can derive without needing to read the sharp.

Then once IR has been emitted we run a resource tracking pass whose job is to follow constant loads and figure out where the sharp is located in memory. After it's loaded we patch the buffer instruction, replacing the handle with the binding index in the buffer resource array and compute the full address. Also it will check if the sharp address is aligned to UBO requirement of the host and fallback to SSBO if not. On SPIR-V side for simplicity buffers are arrays of floats (will also be uint in the future), so it can handle any provided address it has been given (not all loads can be expressed as a single composite array load, especially 3 dword loads whose offset is not 3 dword aligned). In the future I would like to experiment with attempting to reconstruct the struct layout of the UBO/SSBO.

For vulkan side, resources use push descriptors for the simplicity. I think some AMD drivers have broken push descriptors though so a fallback back with normal descriptor writes can be implemented as well without too much hassle.

#version 450
#extension GL_EXT_scalar_block_layout : require

layout(set = 0, binding = 0, scalar) uniform vs_cbuf_block_f32
{
    float data[16];
} c0;

layout(location = 0) in vec4 vs_in_attr0;
layout(location = 0) out vec4 out_attr0;

void main()
{
    uint _57 = uint(gl_VertexIndex) * 4u;
    vec4 _70 = vec4(c0.data[_57 + 0u], c0.data[_57 + 1u], c0.data[_57 + 2u], c0.data[_57 + 3u]);
    gl_Position.x = vs_in_attr0.x;
    gl_Position.y = vs_in_attr0.y;
    gl_Position.z = vs_in_attr0.z;
    gl_Position.w = vs_in_attr0.w;
    out_attr0.x = _70.x;
    out_attr0.y = _70.y;
    out_attr0.z = _70.z;
    out_attr0.w = _70.w;
}

@raphaelthegreat raphaelthegreat merged commit 8dfa578 into main May 26, 2024
7 checks passed
psucien pushed a commit that referenced this pull request May 26, 2024
@georgemoralis georgemoralis deleted the const-buf branch June 30, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant