diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index 0e8fe017d..d224c4d84 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -148,6 +148,16 @@ std::string_view ImageFormatString(ImageFormat format) { | |||
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | std::string_view ImageAccessQualifier(bool is_written, bool is_read) { | ||
| 152 | if (is_written && !is_read) { | ||
| 153 | return "writeonly "; | ||
| 154 | } | ||
| 155 | if (is_read && !is_written) { | ||
| 156 | return "readonly "; | ||
| 157 | } | ||
| 158 | return ""; | ||
| 159 | } | ||
| 160 | |||
| 151 | std::string_view GetTessMode(TessPrimitive primitive) { | 161 | std::string_view GetTessMode(TessPrimitive primitive) { |
| 152 | switch (primitive) { | 162 | switch (primitive) { |
| 153 | case TessPrimitive::Triangles: | 163 | case TessPrimitive::Triangles: |
| @@ -262,7 +272,9 @@ void SetupLegacyInPerFragment(EmitContext& ctx, std::string& header) { | |||
| 262 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, | 272 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, |
| 263 | const RuntimeInfo& runtime_info_) | 273 | const RuntimeInfo& runtime_info_) |
| 264 | : info{program.info}, profile{profile_}, runtime_info{runtime_info_} { | 274 | : info{program.info}, profile{profile_}, runtime_info{runtime_info_} { |
| 265 | header += "#pragma optionNV(fastmath off)\n"; | 275 | if (profile.need_fastmath_off) { |
| 276 | header += "#pragma optionNV(fastmath off)\n"; | ||
| 277 | } | ||
| 266 | SetupExtensions(); | 278 | SetupExtensions(); |
| 267 | stage = program.stage; | 279 | stage = program.stage; |
| 268 | switch (program.stage) { | 280 | switch (program.stage) { |
| @@ -335,7 +347,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 335 | } | 347 | } |
| 336 | for (size_t index = 0; index < info.stores_generics.size(); ++index) { | 348 | for (size_t index = 0; index < info.stores_generics.size(); ++index) { |
| 337 | // TODO: Properly resolve attribute issues | 349 | // TODO: Properly resolve attribute issues |
| 338 | if (info.stores_generics[index] || stage == Stage::VertexA || stage == Stage::VertexB) { | 350 | if (info.stores_generics[index] || StageInitializesVaryings()) { |
| 339 | DefineGenericOutput(index, program.invocations); | 351 | DefineGenericOutput(index, program.invocations); |
| 340 | } | 352 | } |
| 341 | } | 353 | } |
| @@ -347,6 +359,17 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 347 | DefineConstants(); | 359 | DefineConstants(); |
| 348 | } | 360 | } |
| 349 | 361 | ||
| 362 | bool EmitContext::StageInitializesVaryings() const noexcept { | ||
| 363 | switch (stage) { | ||
| 364 | case Stage::VertexA: | ||
| 365 | case Stage::VertexB: | ||
| 366 | case Stage::Geometry: | ||
| 367 | return true; | ||
| 368 | default: | ||
| 369 | return false; | ||
| 370 | } | ||
| 371 | } | ||
| 372 | |||
| 350 | void EmitContext::SetupExtensions() { | 373 | void EmitContext::SetupExtensions() { |
| 351 | if (info.uses_shadow_lod && profile.support_gl_texture_shadow_lod) { | 374 | if (info.uses_shadow_lod && profile.support_gl_texture_shadow_lod) { |
| 352 | header += "#extension GL_EXT_texture_shadow_lod : enable\n"; | 375 | header += "#extension GL_EXT_texture_shadow_lod : enable\n"; |
| @@ -361,7 +384,7 @@ void EmitContext::SetupExtensions() { | |||
| 361 | header += "#extension GL_NV_shader_atomic_float : enable\n"; | 384 | header += "#extension GL_NV_shader_atomic_float : enable\n"; |
| 362 | } | 385 | } |
| 363 | if (info.uses_atomic_f16x2_add || info.uses_atomic_f16x2_min || info.uses_atomic_f16x2_max) { | 386 | if (info.uses_atomic_f16x2_add || info.uses_atomic_f16x2_min || info.uses_atomic_f16x2_max) { |
| 364 | header += "#extension NV_shader_atomic_fp16_vector : enable\n"; | 387 | header += "#extension GL_NV_shader_atomic_fp16_vector : enable\n"; |
| 365 | } | 388 | } |
| 366 | if (info.uses_fp16) { | 389 | if (info.uses_fp16) { |
| 367 | if (profile.support_gl_nv_gpu_shader_5) { | 390 | if (profile.support_gl_nv_gpu_shader_5) { |
| @@ -392,7 +415,7 @@ void EmitContext::SetupExtensions() { | |||
| 392 | if (info.stores_viewport_mask && profile.support_viewport_mask) { | 415 | if (info.stores_viewport_mask && profile.support_viewport_mask) { |
| 393 | header += "#extension GL_NV_viewport_array2 : enable\n"; | 416 | header += "#extension GL_NV_viewport_array2 : enable\n"; |
| 394 | } | 417 | } |
| 395 | if (info.uses_typeless_image_reads || info.uses_typeless_image_writes) { | 418 | if (info.uses_typeless_image_reads) { |
| 396 | header += "#extension GL_EXT_shader_image_load_formatted : enable\n"; | 419 | header += "#extension GL_EXT_shader_image_load_formatted : enable\n"; |
| 397 | } | 420 | } |
| 398 | if (info.uses_derivatives && profile.support_gl_derivative_control) { | 421 | if (info.uses_derivatives && profile.support_gl_derivative_control) { |
| @@ -593,9 +616,9 @@ std::string EmitContext::DefineGlobalMemoryFunctions() { | |||
| 593 | "return uvec4({0}[uint(addr-{1})>>2],{0}[uint(addr-{1}+4)>>2],{0}[" | 616 | "return uvec4({0}[uint(addr-{1})>>2],{0}[uint(addr-{1}+4)>>2],{0}[" |
| 594 | "uint(addr-{1}+8)>>2],{0}[uint(addr-{1}+12)>>2]);}}"); | 617 | "uint(addr-{1}+8)>>2],{0}[uint(addr-{1}+12)>>2]);}}"); |
| 595 | } | 618 | } |
| 596 | write_func += "}"; | 619 | write_func += '}'; |
| 597 | write_func_64 += "}"; | 620 | write_func_64 += '}'; |
| 598 | write_func_128 += "}"; | 621 | write_func_128 += '}'; |
| 599 | load_func += "return 0u;}"; | 622 | load_func += "return 0u;}"; |
| 600 | load_func_64 += "return uvec2(0);}"; | 623 | load_func_64 += "return uvec2(0);}"; |
| 601 | load_func_128 += "return uvec4(0);}"; | 624 | load_func_128 += "return uvec4(0);}"; |
| @@ -607,9 +630,10 @@ void EmitContext::SetupImages(Bindings& bindings) { | |||
| 607 | for (const auto& desc : info.image_buffer_descriptors) { | 630 | for (const auto& desc : info.image_buffer_descriptors) { |
| 608 | image_buffers.push_back({bindings.image, desc.count}); | 631 | image_buffers.push_back({bindings.image, desc.count}); |
| 609 | const auto format{ImageFormatString(desc.format)}; | 632 | const auto format{ImageFormatString(desc.format)}; |
| 633 | const auto qualifier{ImageAccessQualifier(desc.is_written, desc.is_read)}; | ||
| 610 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; | 634 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; |
| 611 | header += fmt::format("layout(binding={}{}) uniform uimageBuffer img{}{};", bindings.image, | 635 | header += fmt::format("layout(binding={}{}) uniform {}uimageBuffer img{}{};", |
| 612 | format, bindings.image, array_decorator); | 636 | bindings.image, format, qualifier, bindings.image, array_decorator); |
| 613 | bindings.image += desc.count; | 637 | bindings.image += desc.count; |
| 614 | } | 638 | } |
| 615 | images.reserve(info.image_descriptors.size()); | 639 | images.reserve(info.image_descriptors.size()); |
| @@ -617,7 +641,7 @@ void EmitContext::SetupImages(Bindings& bindings) { | |||
| 617 | images.push_back({bindings.image, desc.count}); | 641 | images.push_back({bindings.image, desc.count}); |
| 618 | const auto format{ImageFormatString(desc.format)}; | 642 | const auto format{ImageFormatString(desc.format)}; |
| 619 | const auto image_type{ImageType(desc.type)}; | 643 | const auto image_type{ImageType(desc.type)}; |
| 620 | const auto qualifier{desc.is_written ? "" : "readonly "}; | 644 | const auto qualifier{ImageAccessQualifier(desc.is_written, desc.is_read)}; |
| 621 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; | 645 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; |
| 622 | header += fmt::format("layout(binding={}{})uniform {}{} img{}{};", bindings.image, format, | 646 | header += fmt::format("layout(binding={}{})uniform {}{} img{}{};", bindings.image, format, |
| 623 | qualifier, image_type, bindings.image, array_decorator); | 647 | qualifier, image_type, bindings.image, array_decorator); |