Skip to content

Commit

Permalink
renderer_vulkan: Disable dynamic index conditionally (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelthegreat authored Mar 7, 2024
1 parent c4c90f0 commit 8433057
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 12 deletions.
17 changes: 16 additions & 1 deletion src/video_core/host_shaders/vulkan_present.frag
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ layout (push_constant, std140) uniform DrawInfo {

layout (set = 0, binding = 0) uniform sampler2D screen_textures[3];

vec4 GetScreen(int screen_id) {
#ifdef ARRAY_DYNAMIC_INDEX
return texture(screen_textures[screen_id], frag_tex_coord);
#else
switch (screen_id) {
case 0:
return texture(screen_textures[0], frag_tex_coord);
case 1:
return texture(screen_textures[1], frag_tex_coord);
case 2:
return texture(screen_textures[2], frag_tex_coord);
}
#endif
}

void main() {
color = texture(screen_textures[screen_id_l], frag_tex_coord);
color = GetScreen(screen_id_l);
}
19 changes: 17 additions & 2 deletions src/video_core/host_shaders/vulkan_present_anaglyph.frag
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,23 @@ layout (push_constant, std140) uniform DrawInfo {

layout (set = 0, binding = 0) uniform sampler2D screen_textures[3];

vec4 GetScreen(int screen_id) {
#ifdef ARRAY_DYNAMIC_INDEX
return texture(screen_textures[screen_id], frag_tex_coord);
#else
switch (screen_id) {
case 0:
return texture(screen_textures[0], frag_tex_coord);
case 1:
return texture(screen_textures[1], frag_tex_coord);
case 2:
return texture(screen_textures[2], frag_tex_coord);
}
#endif
}

void main() {
vec4 color_tex_l = texture(screen_textures[screen_id_l], frag_tex_coord);
vec4 color_tex_r = texture(screen_textures[screen_id_r], frag_tex_coord);
vec4 color_tex_l = GetScreen(screen_id_l);
vec4 color_tex_r = GetScreen(screen_id_r);
color = vec4(color_tex_l.rgb*l+color_tex_r.rgb*r, color_tex_l.a);
}
19 changes: 17 additions & 2 deletions src/video_core/host_shaders/vulkan_present_interlaced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,25 @@ layout (push_constant, std140) uniform DrawInfo {

layout (set = 0, binding = 0) uniform sampler2D screen_textures[3];

vec4 GetScreen(int screen_id) {
#ifdef ARRAY_DYNAMIC_INDEX
return texture(screen_textures[screen_id], frag_tex_coord);
#else
switch (screen_id) {
case 0:
return texture(screen_textures[0], frag_tex_coord);
case 1:
return texture(screen_textures[1], frag_tex_coord);
case 2:
return texture(screen_textures[2], frag_tex_coord);
}
#endif
}

void main() {
float screen_row = o_resolution.x * frag_tex_coord.x;
if (int(screen_row) % 2 == reverse_interlaced)
color = texture(screen_textures[screen_id_l], frag_tex_coord);
color = GetScreen(screen_id_l);
else
color = texture(screen_textures[screen_id_r], frag_tex_coord);
color = GetScreen(screen_id_r);
}
12 changes: 7 additions & 5 deletions src/video_core/renderer_vulkan/renderer_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,17 @@ void RendererVulkan::LoadFBToScreenInfo(const Pica::FramebufferConfig& framebuff
}

void RendererVulkan::CompileShaders() {
vk::Device device = instance.GetDevice();
const vk::Device device = instance.GetDevice();
const std::string_view preamble =
instance.IsImageArrayDynamicIndexSupported() ? "#define ARRAY_DYNAMIC_INDEX" : "";
present_vertex_shader =
Compile(HostShaders::VULKAN_PRESENT_VERT, vk::ShaderStageFlagBits::eVertex, device);
present_shaders[0] =
Compile(HostShaders::VULKAN_PRESENT_FRAG, vk::ShaderStageFlagBits::eFragment, device);
present_shaders[0] = Compile(HostShaders::VULKAN_PRESENT_FRAG,
vk::ShaderStageFlagBits::eFragment, device, preamble);
present_shaders[1] = Compile(HostShaders::VULKAN_PRESENT_ANAGLYPH_FRAG,
vk::ShaderStageFlagBits::eFragment, device);
vk::ShaderStageFlagBits::eFragment, device, preamble);
present_shaders[2] = Compile(HostShaders::VULKAN_PRESENT_INTERLACED_FRAG,
vk::ShaderStageFlagBits::eFragment, device);
vk::ShaderStageFlagBits::eFragment, device, preamble);

auto properties = instance.GetPhysicalDevice().getProperties();
for (std::size_t i = 0; i < present_samplers.size(); i++) {
Expand Down
5 changes: 5 additions & 0 deletions src/video_core/renderer_vulkan/vk_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ class Instance {
return triangle_fan_supported;
}

/// Returns true if dynamic indices can be used inside shaders.
bool IsImageArrayDynamicIndexSupported() const {
return features.shaderSampledImageArrayDynamicIndexing;
}

/// Returns the minimum vertex stride alignment
u32 GetMinVertexStrideAlignment() const {
return min_vertex_stride_alignment;
Expand Down
4 changes: 3 additions & 1 deletion src/video_core/renderer_vulkan/vk_shader_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ bool InitializeCompiler() {
}
} // Anonymous namespace

vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device) {
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device,
std::string_view premable) {
if (!InitializeCompiler()) {
return {};
}
Expand All @@ -176,6 +177,7 @@ vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, v
shader->setEnvTarget(glslang::EShTargetSpv,
glslang::EShTargetLanguageVersion::EShTargetSpv_1_3);
shader->setStringsWithLengths(&pass_source_code, &pass_source_code_length, 1);
shader->setPreamble(premable.data());

glslang::TShader::ForbidIncluder includer;
if (!shader->parse(&DefaultTBuiltInResource, default_version, profile, false, true, messages,
Expand Down
3 changes: 2 additions & 1 deletion src/video_core/renderer_vulkan/vk_shader_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace Vulkan {
* @param stage The pipeline stage the shader will be used in.
* @param device The vulkan device handle.
*/
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device);
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device,
std::string_view premable = "");

/**
* @brief Creates a vulkan shader module from SPIR-V bytecode.
Expand Down

5 comments on commit 8433057

@dxgldotorg
Copy link

@dxgldotorg dxgldotorg commented on 8433057 Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up, you're still a member of the "citra-emu" organization. (referring to @gpucode).
Luckily the most I've done to an emulator codebase has been making Dolphin compliant with Windows 8/8.1/10/11+ High Contrast theme.

@raphaelthegreat
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

@dxgldotorg
Copy link

@dxgldotorg dxgldotorg commented on 8433057 Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Don't want to run into legal troubles? Are you not potentially affected by the court order?

If you're not worried, you do you, but if I were under a permanent injunction I'd be scared to touch the code ever again.

@raphaelthegreat
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the concern. My contributions to yuzu were minimal and I didn't come in contact with the sued company. I mostly worked on Citra that wasn't mentioned in the suit

@dxgldotorg
Copy link

@dxgldotorg dxgldotorg commented on 8433057 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, is that GLSL source code I see being used in Vulkan? Just so you know, I currently know zero about Vullkan.

Please sign in to comment.