[PR #148] [MERGED] video_core: Add linear image support #1337

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

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/148
Author: @raphaelthegreat
Created: 5/27/2024
Status: Merged
Merged: 5/27/2024
Merged by: @psucien

Base: mainHead: images


📝 Commits (2)

  • d59b102 video_core: Add image support
  • 4d728e9 video_core: Address some feedback

📊 Changes

48 files changed (+1263 additions, -248 deletions)

View changed files

📝 CMakeLists.txt (+2 -0)
📝 src/common/config.cpp (+17 -10)
📝 src/common/config.h (+1 -0)
📝 src/core/libraries/gnmdriver/gnmdriver.cpp (+9 -4)
📝 src/core/libraries/kernel/event_queue.cpp (+0 -1)
📝 src/core/libraries/kernel/libkernel.cpp (+2 -1)
📝 src/core/memory.cpp (+2 -0)
📝 src/shader_recompiler/backend/spirv/emit_spirv.cpp (+2 -2)
📝 src/shader_recompiler/backend/spirv/emit_spirv.h (+1 -7)
📝 src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp (+12 -19)
📝 src/shader_recompiler/backend/spirv/emit_spirv_image.cpp (+8 -3)
📝 src/shader_recompiler/backend/spirv/emit_spirv_instructions.h (+7 -14)
📝 src/shader_recompiler/backend/spirv/spirv_emit_context.cpp (+105 -22)
📝 src/shader_recompiler/backend/spirv/spirv_emit_context.h (+15 -3)
📝 src/shader_recompiler/frontend/translate/scalar_memory.cpp (+9 -8)
📝 src/shader_recompiler/frontend/translate/translate.cpp (+39 -2)
📝 src/shader_recompiler/frontend/translate/translate.h (+6 -0)
📝 src/shader_recompiler/frontend/translate/vector_alu.cpp (+42 -1)
📝 src/shader_recompiler/frontend/translate/vector_memory.cpp (+17 -10)
📝 src/shader_recompiler/ir/attribute.cpp (+2 -0)

...and 28 more files

📄 Description

Recompiler can now read sampled images. Images and samplers are separated as it better matches how guest hardware works with separate T# and S#. The idea is the same as buffers, the resource tracking pass finds any image instructions and patches it to the correct binding and resolves certain parameters like texture coordinates and lod bias.

Tiled textures are not supported atm so only linear were tested. For texture tiling we will probably use freegnm gpuaddr library as a basis, though pal gpuaddr seems a bit more complete.

This PR also fixes the embedded vertex shader to work correctly when used and have correct alignment. Blending support has been added based on the register configuration as well as a few depth formats. Finally I've added a config to dump both binary gcn shaders and generated spirv shaders which can be quite useful for debugging.

#version 450

layout(set = 0, binding = 1) uniform texture2D fs_img104_00;
layout(set = 0, binding = 2) uniform sampler fs_samp104_08;

layout(location = 0) in vec3 fs_in_attr0;
layout(location = 1) in vec2 fs_in_attr1;
layout(location = 0) out vec4 frag_color0;

void main()
{
    vec4 _53 = texture(sampler2D(fs_img104_00, fs_samp104_08), vec2(fs_in_attr1.x, fs_in_attr1.y));
    frag_color0.x = _53.x * fs_in_attr0.x;
    frag_color0.y = fs_in_attr0.y * _53.y;
    frag_color0.z = fs_in_attr0.z * _53.z;
    frag_color0.w = _53.w;
}

🔄 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/148 **Author:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Created:** 5/27/2024 **Status:** ✅ Merged **Merged:** 5/27/2024 **Merged by:** [@psucien](https://github.com/psucien) **Base:** `main` ← **Head:** `images` --- ### 📝 Commits (2) - [`d59b102`](https://github.com/shadps4-emu/shadPS4/commit/d59b102b6f42cecad42b11e6573e4e8e31d4aaee) video_core: Add image support - [`4d728e9`](https://github.com/shadps4-emu/shadPS4/commit/4d728e943d6df4ed0de5234a0cf3f082db2fd1e4) video_core: Address some feedback ### 📊 Changes **48 files changed** (+1263 additions, -248 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+2 -0) 📝 `src/common/config.cpp` (+17 -10) 📝 `src/common/config.h` (+1 -0) 📝 `src/core/libraries/gnmdriver/gnmdriver.cpp` (+9 -4) 📝 `src/core/libraries/kernel/event_queue.cpp` (+0 -1) 📝 `src/core/libraries/kernel/libkernel.cpp` (+2 -1) 📝 `src/core/memory.cpp` (+2 -0) 📝 `src/shader_recompiler/backend/spirv/emit_spirv.cpp` (+2 -2) 📝 `src/shader_recompiler/backend/spirv/emit_spirv.h` (+1 -7) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp` (+12 -19) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_image.cpp` (+8 -3) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_instructions.h` (+7 -14) 📝 `src/shader_recompiler/backend/spirv/spirv_emit_context.cpp` (+105 -22) 📝 `src/shader_recompiler/backend/spirv/spirv_emit_context.h` (+15 -3) 📝 `src/shader_recompiler/frontend/translate/scalar_memory.cpp` (+9 -8) 📝 `src/shader_recompiler/frontend/translate/translate.cpp` (+39 -2) 📝 `src/shader_recompiler/frontend/translate/translate.h` (+6 -0) 📝 `src/shader_recompiler/frontend/translate/vector_alu.cpp` (+42 -1) 📝 `src/shader_recompiler/frontend/translate/vector_memory.cpp` (+17 -10) 📝 `src/shader_recompiler/ir/attribute.cpp` (+2 -0) _...and 28 more files_ </details> ### 📄 Description Recompiler can now read sampled images. Images and samplers are separated as it better matches how guest hardware works with separate T# and S#. The idea is the same as buffers, the resource tracking pass finds any image instructions and patches it to the correct binding and resolves certain parameters like texture coordinates and lod bias. Tiled textures are not supported atm so only linear were tested. For texture tiling we will probably use [freegnm](https://gitgud.io/gluesniffer/freegnm/-/blob/master/gnm/gpuaddr/gpuaddr.h) gpuaddr library as a basis, though pal gpuaddr seems a bit more complete. This PR also fixes the embedded vertex shader to work correctly when used and have correct alignment. Blending support has been added based on the register configuration as well as a few depth formats. Finally I've added a config to dump both binary gcn shaders and generated spirv shaders which can be quite useful for debugging. ```glsl #version 450 layout(set = 0, binding = 1) uniform texture2D fs_img104_00; layout(set = 0, binding = 2) uniform sampler fs_samp104_08; layout(location = 0) in vec3 fs_in_attr0; layout(location = 1) in vec2 fs_in_attr1; layout(location = 0) out vec4 frag_color0; void main() { vec4 _53 = texture(sampler2D(fs_img104_00, fs_samp104_08), vec2(fs_in_attr1.x, fs_in_attr1.y)); frag_color0.x = _53.x * fs_in_attr0.x; frag_color0.y = fs_in_attr0.y * _53.y; frag_color0.z = fs_in_attr0.z * _53.z; frag_color0.w = _53.w; } ``` --- <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:09 +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#1337
No description provided.