[PR #145] [MERGED] video_core: Bringup some basic functionality #1335

Closed
opened 2026-02-27 21:12:08 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/145
Author: @raphaelthegreat
Created: 5/24/2024
Status: Merged
Merged: 5/25/2024
Merged by: @raphaelthegreat

Base: mainHead: quad-work


📝 Commits (4)

  • 08e1559 video_core: Remove hack in rasterizer
  • 0eaa7d5 shader_recompiler: Implement attribute loads/stores
  • f480d09 video_core: Add basic vertex, index buffer handling and pipeline caching
  • 898e821 externals: Make xxhash lowercase

📊 Changes

50 files changed (+1038 additions, -391 deletions)

View changed files

📝 .gitmodules (+3 -3)
📝 CMakeLists.txt (+3 -0)
📝 externals/CMakeLists.txt (+3 -3)
📝 externals/xxhash (+0 -0)
📝 src/core/memory.cpp (+93 -0)
📝 src/core/memory.h (+24 -4)
📝 src/main.cpp (+0 -1)
📝 src/shader_recompiler/backend/spirv/emit_spirv.cpp (+3 -3)
📝 src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp (+6 -11)
📝 src/shader_recompiler/backend/spirv/emit_spirv_instructions.h (+3 -3)
📝 src/shader_recompiler/backend/spirv/spirv_emit_context.cpp (+105 -4)
📝 src/shader_recompiler/backend/spirv/spirv_emit_context.h (+9 -9)
src/shader_recompiler/frontend/fetch_shader.cpp (+83 -0)
src/shader_recompiler/frontend/fetch_shader.h (+21 -0)
📝 src/shader_recompiler/frontend/structured_control_flow.cpp (+6 -7)
📝 src/shader_recompiler/frontend/structured_control_flow.h (+2 -2)
📝 src/shader_recompiler/frontend/translate/translate.cpp (+37 -4)
📝 src/shader_recompiler/frontend/translate/translate.h (+7 -3)
📝 src/shader_recompiler/frontend/translate/vector_alu.cpp (+2 -3)
📝 src/shader_recompiler/frontend/translate/vector_interpolation.cpp (+3 -1)

...and 30 more files

📄 Description

This expands on the previous PR that added shader recompiler and fixes a couple very basic things before we move on to resource management.

  • Removes a hack in DrawIndex that skipped the first draw. This was in place because the display buffer had not been created yet and the texture cache didn't have the ability to create render targets. Now can, using the color buffer parameters from registers.

  • Attribute handling has been added. It's not complete but I hope will handle most not complex cases just fine. Doesn't help that the pipeline is a bit complex. VS receives inputs from vertex buffers using the fetch shader which needs special handling. Since the pattern generated is quite predictable, I chose to parse it directly from GCN assembly and not convert it to IR. VS then exports attributes either in Position0/1/.. (this is for position and other special VS outputs like gl_PointSize or gl_ClipDistance) or in Param0/1/... From what I saw in renderdoc the driver might try to pack more than one attribute in a single "param" or split an attribute into two "params". Then on PS side, there is SPI_PS_INPUT_CNTL_[0-31] registers which define a mapping between "param" and "attr" used in vector interpolation instructions. Flat inputs appear to always set the FLAT_SHADE member so it should be easy to detect.

The IR constant folding pass is also able to detect fp16 pack -> unpack operations and eliminate them which is neat.

#version 450

layout(location = 0) in vec4 fs_in_attr0;
layout(location = 0) out vec4 frag_color0;

void main()
{
    frag_color0.x = fs_in_attr0.x;
    frag_color0.y = fs_in_attr0.y;
    frag_color0.z = fs_in_attr0.z;
    frag_color0.w = fs_in_attr0.w;
}
  • Pipeline handling has been greatly reworked, now there is a more complete pipeline key that gets generated from liverpool register state and we check in a hashmap for cached pipelines. The drawing mechanism has been reworked to be actually accurate as well. Triangle demo uses index buffers now as it should, while a primitive QuadList emulation has been added that generates a CPU side index buffer for TriangleList into a stream buffer. Vertex buffers are also implemented using the fetch shader parse result to retrieve sharps. For both vertex and index buffers I used VK_EXT_external_memory_host as a quick but accurate solution. I'm aware this is extremely slow and alternative management methods are being considered but for now this is good. Though renderdoc doesn't support the extension so we might need to switch sooner rather than later :/

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/145 **Author:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Created:** 5/24/2024 **Status:** ✅ Merged **Merged:** 5/25/2024 **Merged by:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Base:** `main` ← **Head:** `quad-work` --- ### 📝 Commits (4) - [`08e1559`](https://github.com/shadps4-emu/shadPS4/commit/08e155946e8ce6a5c9caafe29f00b8d4baf69ec8) video_core: Remove hack in rasterizer - [`0eaa7d5`](https://github.com/shadps4-emu/shadPS4/commit/0eaa7d58599a336898b54eb2a680e13a5c9a2feb) shader_recompiler: Implement attribute loads/stores - [`f480d09`](https://github.com/shadps4-emu/shadPS4/commit/f480d091ce7b3569e1b63e36de947a792f760603) video_core: Add basic vertex, index buffer handling and pipeline caching - [`898e821`](https://github.com/shadps4-emu/shadPS4/commit/898e821225241842b0d90f5e2b997c3f5aa7dd33) externals: Make xxhash lowercase ### 📊 Changes **50 files changed** (+1038 additions, -391 deletions) <details> <summary>View changed files</summary> 📝 `.gitmodules` (+3 -3) 📝 `CMakeLists.txt` (+3 -0) 📝 `externals/CMakeLists.txt` (+3 -3) 📝 `externals/xxhash` (+0 -0) 📝 `src/core/memory.cpp` (+93 -0) 📝 `src/core/memory.h` (+24 -4) 📝 `src/main.cpp` (+0 -1) 📝 `src/shader_recompiler/backend/spirv/emit_spirv.cpp` (+3 -3) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp` (+6 -11) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_instructions.h` (+3 -3) 📝 `src/shader_recompiler/backend/spirv/spirv_emit_context.cpp` (+105 -4) 📝 `src/shader_recompiler/backend/spirv/spirv_emit_context.h` (+9 -9) ➕ `src/shader_recompiler/frontend/fetch_shader.cpp` (+83 -0) ➕ `src/shader_recompiler/frontend/fetch_shader.h` (+21 -0) 📝 `src/shader_recompiler/frontend/structured_control_flow.cpp` (+6 -7) 📝 `src/shader_recompiler/frontend/structured_control_flow.h` (+2 -2) 📝 `src/shader_recompiler/frontend/translate/translate.cpp` (+37 -4) 📝 `src/shader_recompiler/frontend/translate/translate.h` (+7 -3) 📝 `src/shader_recompiler/frontend/translate/vector_alu.cpp` (+2 -3) 📝 `src/shader_recompiler/frontend/translate/vector_interpolation.cpp` (+3 -1) _...and 30 more files_ </details> ### 📄 Description This expands on the previous PR that added shader recompiler and fixes a couple very basic things before we move on to resource management. * Removes a hack in DrawIndex that skipped the first draw. This was in place because the display buffer had not been created yet and the texture cache didn't have the ability to create render targets. Now can, using the color buffer parameters from registers. * Attribute handling has been added. It's not complete but I hope will handle most not complex cases just fine. Doesn't help that the pipeline is a bit complex. VS receives inputs from vertex buffers using the fetch shader which needs special handling. Since the pattern generated is quite predictable, I chose to parse it directly from GCN assembly and not convert it to IR. VS then exports attributes either in Position0/1/.. (this is for position and other special VS outputs like gl_PointSize or gl_ClipDistance) or in Param0/1/... From what I saw in renderdoc the driver might try to pack more than one attribute in a single "param" or split an attribute into two "params". Then on PS side, there is SPI_PS_INPUT_CNTL_[0-31] registers which define a mapping between "param" and "attr" used in vector interpolation instructions. Flat inputs appear to always set the FLAT_SHADE member so it should be easy to detect. The IR constant folding pass is also able to detect fp16 pack -> unpack operations and eliminate them which is neat. ```glsl #version 450 layout(location = 0) in vec4 fs_in_attr0; layout(location = 0) out vec4 frag_color0; void main() { frag_color0.x = fs_in_attr0.x; frag_color0.y = fs_in_attr0.y; frag_color0.z = fs_in_attr0.z; frag_color0.w = fs_in_attr0.w; } ``` * Pipeline handling has been greatly reworked, now there is a more complete pipeline key that gets generated from liverpool register state and we check in a hashmap for cached pipelines. The drawing mechanism has been reworked to be actually accurate as well. Triangle demo uses index buffers now as it should, while a primitive QuadList emulation has been added that generates a CPU side index buffer for TriangleList into a stream buffer. Vertex buffers are also implemented using the fetch shader parse result to retrieve sharps. For both vertex and index buffers I used VK_EXT_external_memory_host as a quick but accurate solution. I'm aware this is extremely slow and alternative management methods are being considered but for now this is good. Though renderdoc doesn't support the extension so we might need to switch sooner rather than later :/ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:12:08 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#1335
No description provided.