From 0a28786e83f0bf5109442f246254064017652bc2 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Mon, 4 Dec 2023 17:52:24 +0100 Subject: [PATCH] early-access version 4007 --- README.md | 2 +- .../glasm/emit_glasm_context_get_set.cpp | 10 +------ .../backend/glasm/glasm_emit_context.cpp | 6 ---- .../backend/glsl/emit_glsl.h | 5 ++-- .../glsl/emit_glsl_context_get_set.cpp | 9 ------ .../backend/glsl/glsl_emit_context.cpp | 6 ---- .../backend/spirv/emit_spirv.h | 6 ---- .../spirv/emit_spirv_context_get_set.cpp | 29 ++++++++++--------- .../backend/spirv/spirv_emit_context.cpp | 6 ---- src/shader_recompiler/runtime_info.h | 11 +++---- .../renderer_opengl/gl_shader_cache.cpp | 20 +++++-------- .../renderer_vulkan/vk_pipeline_cache.cpp | 13 ++------- src/video_core/vulkan_common/vulkan_device.h | 5 ---- 13 files changed, 34 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index cc4bb7ace..7ca2361c3 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4006. +This is the source code for early-access 4007. ## Legal Notice diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp index b516a94b2..f0faf786f 100755 --- a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp @@ -7,7 +7,6 @@ #include "shader_recompiler/backend/glasm/glasm_emit_context.h" #include "shader_recompiler/frontend/ir/value.h" #include "shader_recompiler/profile.h" -#include "shader_recompiler/runtime_info.h" #include "shader_recompiler/shader_info.h" namespace Shader::Backend::GLASM { @@ -24,14 +23,7 @@ void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU } if (binding.IsImmediate()) { - const u32 binding_index{binding.U32()}; - const u32 max_num_cbufs{ctx.runtime_info.max_num_cbufs}; - if (binding_index >= max_num_cbufs) { - // cbuf index exceeds device limit - ctx.Add("MOV.S {},0;", ret); - return; - } - ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding_index, offset); + ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding.U32(), offset); return; } diff --git a/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp b/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp index f654feaf4..1b7207acf 100755 --- a/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp +++ b/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp @@ -37,12 +37,6 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile if (desc.count != 1) { throw NotImplementedException("Constant buffer descriptor array"); } - if (cbuf_index >= runtime_info.max_num_cbufs) { - LOG_WARNING(Shader_GLASM, "Constant buffer binding index {} exceeds device limit of {}", - cbuf_index, runtime_info.max_num_cbufs); - ++cbuf_index; - continue; - } Add("CBUFFER c{}[]={{program.buffer[{}]}};", desc.index, cbuf_index); ++cbuf_index; } diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.h b/src/shader_recompiler/backend/glsl/emit_glsl.h index 62913166c..74ccc82ae 100755 --- a/src/shader_recompiler/backend/glsl/emit_glsl.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl.h @@ -15,10 +15,9 @@ namespace Shader::Backend::GLSL { [[nodiscard]] std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR::Program& program, Bindings& bindings); -[[nodiscard]] inline std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, - IR::Program& program) { +[[nodiscard]] inline std::string EmitGLSL(const Profile& profile, IR::Program& program) { Bindings binding; - return EmitGLSL(profile, runtime_info, program, binding); + return EmitGLSL(profile, {}, program, binding); } } // namespace Shader::Backend::GLSL diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp index b662ae0f7..79dac8124 100755 --- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp @@ -46,15 +46,6 @@ std::string ChooseCbuf(EmitContext& ctx, const IR::Value& binding, std::string_v void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding, const IR::Value& offset, u32 num_bits, std::string_view cast = {}, std::string_view bit_offset = {}) { - if (binding.IsImmediate()) { - const u32 binding_index{binding.U32()}; - const u32 max_num_cbufs{ctx.runtime_info.max_num_cbufs}; - if (binding_index >= max_num_cbufs) { - // cbuf index exceeds device limit - ctx.Add("{}=0u;", ret); - return; - } - } const bool is_immediate{offset.IsImmediate()}; const bool component_indexing_bug{!is_immediate && ctx.profile.has_gl_component_indexing_bug}; if (is_immediate) { diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index 4e5936c78..9687b3f7e 100755 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp @@ -431,12 +431,6 @@ void EmitContext::DefineConstantBuffers(Bindings& bindings) { return; } for (const auto& desc : info.constant_buffer_descriptors) { - if (bindings.uniform_buffer >= runtime_info.max_num_cbufs) { - LOG_WARNING(Shader_GLSL, "Constant buffer binding index {} exceeds device limit of {}", - bindings.uniform_buffer, runtime_info.max_num_cbufs); - bindings.uniform_buffer += desc.count; - continue; - } const auto cbuf_type{profile.has_gl_cbuf_ftou_bug ? "uvec4" : "vec4"}; const u32 cbuf_used_size{Common::DivCeil(info.constant_buffer_used_sizes[desc.index], 16U)}; const u32 cbuf_binding_size{info.uses_global_memory ? 0x1000U : cbuf_used_size}; diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index a6980bc82..497c02da7 100755 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h @@ -38,10 +38,4 @@ constexpr u32 RENDERAREA_LAYOUT_OFFSET = offsetof(RenderAreaLayout, render_area) return EmitSPIRV(profile, {}, program, binding); } -[[nodiscard]] inline std::vector EmitSPIRV(const Profile& profile, - const RuntimeInfo& runtime_info, - IR::Program& program) { - Bindings binding; - return EmitSPIRV(profile, runtime_info, program, binding); -} } // namespace Shader::Backend::SPIRV diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 95293ea12..29a40bdfd 100755 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp @@ -122,24 +122,25 @@ Id GetCbuf(EmitContext& ctx, Id result_type, Id UniformDefinitions::*member_ptr, if (!binding.IsImmediate()) { return ctx.OpFunctionCall(result_type, indirect_func, ctx.Def(binding), buffer_offset); } - const bool is_float{UniformDefinitions::IsFloat(member_ptr)}; - const Id zero_val{is_float ? ctx.Const(0.0f) : ctx.Const(0u)}; - const u32 binding_index{binding.U32()}; - const u32 max_num_cbufs{ctx.runtime_info.max_num_cbufs}; - if (binding_index >= max_num_cbufs) { - // cbuf index exceeds device limit - return zero_val; - } - const Id cbuf{ctx.cbufs[binding_index].*member_ptr}; + + const Id cbuf{ctx.cbufs[binding.U32()].*member_ptr}; const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, buffer_offset)}; - const Id val{ctx.OpLoad(result_type, access_chain)}; + const Id val = ctx.OpLoad(result_type, access_chain); + if (offset.IsImmediate() || !ctx.profile.has_broken_robust) { return val; } - const auto num_elements{UniformDefinitions::NumElements(member_ptr)}; - const std::array zero_vec{zero_val, zero_val, zero_val, zero_val}; - const Id cond{ctx.OpULessThanEqual(ctx.TypeBool(), buffer_offset, ctx.Const(0xFFFFu))}; - const Id zero{ctx.OpCompositeConstruct(result_type, std::span(zero_vec.data(), num_elements))}; + + const auto is_float = UniformDefinitions::IsFloat(member_ptr); + const auto num_elements = UniformDefinitions::NumElements(member_ptr); + const std::array zero_vec{ + is_float ? ctx.Const(0.0f) : ctx.Const(0u), + is_float ? ctx.Const(0.0f) : ctx.Const(0u), + is_float ? ctx.Const(0.0f) : ctx.Const(0u), + is_float ? ctx.Const(0.0f) : ctx.Const(0u), + }; + const Id cond = ctx.OpULessThanEqual(ctx.TypeBool(), buffer_offset, ctx.Const(0xFFFFu)); + const Id zero = ctx.OpCompositeConstruct(result_type, std::span(zero_vec.data(), num_elements)); return ctx.OpSelect(result_type, cond, val, zero); } diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index f1f404645..7a07c8862 100755 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp @@ -278,12 +278,6 @@ void DefineConstBuffers(EmitContext& ctx, const Info& info, Id UniformDefinition ctx.uniform_types.*member_type = uniform_type; for (const ConstantBufferDescriptor& desc : info.constant_buffer_descriptors) { - if (desc.index + desc.count > ctx.runtime_info.max_num_cbufs) { - LOG_WARNING(Shader_SPIRV, "Constant buffer binding index {} exceeds device limit of {}", - desc.index, ctx.runtime_info.max_num_cbufs); - binding += desc.count; - continue; - } const Id id{ctx.AddGlobalVariable(struct_pointer_type, spv::StorageClass::Uniform)}; ctx.Decorate(id, spv::Decoration::Binding, binding); ctx.Decorate(id, spv::Decoration::DescriptorSet, 0U); diff --git a/src/shader_recompiler/runtime_info.h b/src/shader_recompiler/runtime_info.h index a79f3f389..d632deca6 100755 --- a/src/shader_recompiler/runtime_info.h +++ b/src/shader_recompiler/runtime_info.h @@ -62,8 +62,8 @@ struct TransformFeedbackVarying { struct RuntimeInfo { std::array generic_input_types{}; - VaryingState previous_stage_stores{}; - std::map previous_stage_legacy_stores_mapping{}; + VaryingState previous_stage_stores; + std::map previous_stage_legacy_stores_mapping; bool convert_depth_mode{}; bool force_early_z{}; @@ -74,8 +74,8 @@ struct RuntimeInfo { InputTopology input_topology{}; - std::optional fixed_state_point_size{}; - std::optional alpha_test_func{}; + std::optional fixed_state_point_size; + std::optional alpha_test_func; float alpha_test_reference{}; /// Static Y negate value @@ -86,9 +86,6 @@ struct RuntimeInfo { /// Transform feedback state for each varying std::array xfb_varyings{}; u32 xfb_count{0}; - - /// Maximum number of UBO/CBUF bindings allowed by the host device - u32 max_num_cbufs{32}; }; } // namespace Shader diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index fcee1d3af..eb6f5d92d 100755 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -72,8 +72,7 @@ Shader::OutputTopology MaxwellToOutputTopology(Maxwell::PrimitiveTopology topolo Shader::RuntimeInfo MakeRuntimeInfo(const GraphicsPipelineKey& key, const Shader::IR::Program& program, const Shader::IR::Program* previous_program, - bool glasm_use_storage_buffers, bool use_assembly_shaders, - u32 max_num_cbufs) { + bool glasm_use_storage_buffers, bool use_assembly_shaders) { Shader::RuntimeInfo info; if (previous_program) { info.previous_stage_stores = previous_program->info.stores; @@ -153,7 +152,6 @@ Shader::RuntimeInfo MakeRuntimeInfo(const GraphicsPipelineKey& key, break; } info.glasm_use_storage_buffers = glasm_use_storage_buffers; - info.max_num_cbufs = max_num_cbufs; return info; } @@ -524,9 +522,8 @@ std::unique_ptr ShaderCache::CreateGraphicsPipeline( const size_t stage_index{index - 1}; infos[stage_index] = &program.info; - const u32 max_num_cbufs{device.GetMaxUniformBuffers(program.stage)}; - const auto runtime_info{MakeRuntimeInfo( - key, program, previous_program, glasm_use_storage_buffers, use_glasm, max_num_cbufs)}; + const auto runtime_info{ + MakeRuntimeInfo(key, program, previous_program, glasm_use_storage_buffers, use_glasm)}; switch (device.GetShaderBackend()) { case Settings::ShaderBackend::Glsl: ConvertLegacyToGeneric(program, runtime_info); @@ -583,21 +580,20 @@ std::unique_ptr ShaderCache::CreateComputePipeline( auto program{TranslateProgram(pools.inst, pools.block, env, cfg, host_info)}; const u32 num_storage_buffers{Shader::NumDescriptors(program.info.storage_buffers_descriptors)}; - const Shader::RuntimeInfo info{ - .glasm_use_storage_buffers = num_storage_buffers <= device.GetMaxGLASMStorageBufferBlocks(), - .max_num_cbufs = device.GetMaxUniformBuffers(program.stage), - }; + Shader::RuntimeInfo info; + info.glasm_use_storage_buffers = num_storage_buffers <= device.GetMaxGLASMStorageBufferBlocks(); + std::string code{}; std::vector code_spirv; switch (device.GetShaderBackend()) { case Settings::ShaderBackend::Glsl: - code = EmitGLSL(profile, info, program); + code = EmitGLSL(profile, program); break; case Settings::ShaderBackend::Glasm: code = EmitGLASM(profile, info, program); break; case Settings::ShaderBackend::SpirV: - code_spirv = EmitSPIRV(profile, info, program); + code_spirv = EmitSPIRV(profile, program); break; } diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 0b614cc22..1adb6d90a 100755 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -145,8 +145,7 @@ Shader::AttributeType AttributeType(const FixedPipelineState& state, size_t inde Shader::RuntimeInfo MakeRuntimeInfo(std::span programs, const GraphicsPipelineCacheKey& key, const Shader::IR::Program& program, - const Shader::IR::Program* previous_program, - u32 max_num_cbufs) { + const Shader::IR::Program* previous_program) { Shader::RuntimeInfo info; if (previous_program) { info.previous_stage_stores = previous_program->info.stores; @@ -262,7 +261,6 @@ Shader::RuntimeInfo MakeRuntimeInfo(std::span program } info.force_early_z = key.state.early_z != 0; info.y_negate = key.state.y_negate != 0; - info.max_num_cbufs = max_num_cbufs; return info; } @@ -657,7 +655,6 @@ std::unique_ptr PipelineCache::CreateGraphicsPipeline( const Shader::IR::Program* previous_stage{}; Shader::Backend::Bindings binding; - const u32 max_num_cbufs{static_cast(device.GetMaxPerStageUniformBuffers())}; for (size_t index = uses_vertex_a && uses_vertex_b ? 1 : 0; index < Maxwell::MaxShaderProgram; ++index) { const bool is_emulated_stage = layer_source_program != nullptr && @@ -671,8 +668,7 @@ std::unique_ptr PipelineCache::CreateGraphicsPipeline( const size_t stage_index{index - 1}; infos[stage_index] = &program.info; - const auto runtime_info{ - MakeRuntimeInfo(programs, key, program, previous_stage, max_num_cbufs)}; + const auto runtime_info{MakeRuntimeInfo(programs, key, program, previous_stage)}; ConvertLegacyToGeneric(program, runtime_info); const std::vector code{EmitSPIRV(profile, runtime_info, program, binding)}; device.SaveShader(code); @@ -768,10 +764,7 @@ std::unique_ptr PipelineCache::CreateComputePipeline( } auto program{TranslateProgram(pools.inst, pools.block, env, cfg, host_info)}; - const Shader::RuntimeInfo info{ - .max_num_cbufs = static_cast(device.GetMaxPerStageUniformBuffers()), - }; - const std::vector code{EmitSPIRV(profile, info, program)}; + const std::vector code{EmitSPIRV(profile, program)}; device.SaveShader(code); vk::ShaderModule spv_module{BuildShader(device, code)}; if (device.HasDebuggingToolAttached()) { diff --git a/src/video_core/vulkan_common/vulkan_device.h b/src/video_core/vulkan_common/vulkan_device.h index 8f461e238..5e8c431dd 100755 --- a/src/video_core/vulkan_common/vulkan_device.h +++ b/src/video_core/vulkan_common/vulkan_device.h @@ -299,11 +299,6 @@ public: return properties.properties.limits.maxComputeSharedMemorySize; } - /// Returns the maximum number of uniform buffers allowed per stage. - VkDeviceSize GetMaxPerStageUniformBuffers() const { - return properties.properties.limits.maxPerStageDescriptorUniformBuffers; - } - /// Returns float control properties of the device. const VkPhysicalDeviceFloatControlsPropertiesKHR& FloatControlProperties() const { return properties.float_controls;