diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index 484548467..cbcf0a1eb 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -13,7 +13,7 @@ u32 CbufIndex(size_t offset) { | |||
| 13 | return (offset / 4) % 4; | 13 | return (offset / 4) % 4; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | char CbufSwizzle(size_t offset) { | 16 | char Swizzle(size_t offset) { |
| 17 | return "xyzw"[CbufIndex(offset)]; | 17 | return "xyzw"[CbufIndex(offset)]; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| @@ -341,8 +341,8 @@ void EmitContext::SetupExtensions(std::string&) { | |||
| 341 | header += "#extension GL_NV_shader_thread_shuffle : enable\n"; | 341 | header += "#extension GL_NV_shader_thread_shuffle : enable\n"; |
| 342 | } | 342 | } |
| 343 | } | 343 | } |
| 344 | if (info.stores_viewport_index && profile.support_viewport_index_layer_non_geometry && | 344 | if ((info.stores_viewport_index || info.stores_layer) && |
| 345 | stage != Stage::Geometry) { | 345 | profile.support_viewport_index_layer_non_geometry && stage != Stage::Geometry) { |
| 346 | header += "#extension GL_ARB_shader_viewport_layer_array : enable\n"; | 346 | header += "#extension GL_ARB_shader_viewport_layer_array : enable\n"; |
| 347 | } | 347 | } |
| 348 | if (info.uses_sparse_residency) { | 348 | if (info.uses_sparse_residency) { |
| @@ -428,16 +428,16 @@ void EmitContext::DefineHelperFunctions() { | |||
| 428 | header += "uint CasIncrement(uint op_a,uint op_b){return op_a>=op_b?0u:(op_a+1u);}"; | 428 | header += "uint CasIncrement(uint op_a,uint op_b){return op_a>=op_b?0u:(op_a+1u);}"; |
| 429 | } | 429 | } |
| 430 | if (info.uses_global_decrement || info.uses_shared_decrement) { | 430 | if (info.uses_global_decrement || info.uses_shared_decrement) { |
| 431 | header += "uint CasDecrement(uint op_a,uint " | 431 | header += "uint CasDecrement(uint op_a,uint op_b){" |
| 432 | "op_b){return op_a==0||op_a>op_b?op_b:(op_a-1u);}"; | 432 | "return op_a==0||op_a>op_b?op_b:(op_a-1u);}"; |
| 433 | } | 433 | } |
| 434 | if (info.uses_atomic_f32_add) { | 434 | if (info.uses_atomic_f32_add) { |
| 435 | header += "uint CasFloatAdd(uint op_a,float op_b){return " | 435 | header += "uint CasFloatAdd(uint op_a,float op_b){" |
| 436 | "ftou(utof(op_a)+op_b);}"; | 436 | "return ftou(utof(op_a)+op_b);}"; |
| 437 | } | 437 | } |
| 438 | if (info.uses_atomic_f32x2_add) { | 438 | if (info.uses_atomic_f32x2_add) { |
| 439 | header += "uint CasFloatAdd32x2(uint op_a,vec2 op_b){return " | 439 | header += "uint CasFloatAdd32x2(uint op_a,vec2 op_b){" |
| 440 | "packHalf2x16(unpackHalf2x16(op_a)+op_b);}"; | 440 | "return packHalf2x16(unpackHalf2x16(op_a)+op_b);}"; |
| 441 | } | 441 | } |
| 442 | if (info.uses_atomic_f32x2_min) { | 442 | if (info.uses_atomic_f32x2_min) { |
| 443 | header += "uint CasFloatMin32x2(uint op_a,vec2 op_b){return " | 443 | header += "uint CasFloatMin32x2(uint op_a,vec2 op_b){return " |
| @@ -476,9 +476,10 @@ void EmitContext::DefineHelperFunctions() { | |||
| 476 | "masked_index=uint(base_index)&3u;switch(base_index>>2){{", | 476 | "masked_index=uint(base_index)&3u;switch(base_index>>2){{", |
| 477 | vertex_arg)}; | 477 | vertex_arg)}; |
| 478 | if (info.loads_position) { | 478 | if (info.loads_position) { |
| 479 | func += fmt::format("case {}:", static_cast<u32>(IR::Attribute::PositionX) >> 2); | ||
| 480 | const auto position_idx{is_array ? "gl_in[vertex]." : ""}; | 479 | const auto position_idx{is_array ? "gl_in[vertex]." : ""}; |
| 481 | func += fmt::format("return {}{}[masked_index];", position_idx, position_name); | 480 | func += fmt::format("case {}:return {}{}[masked_index];", |
| 481 | static_cast<u32>(IR::Attribute::PositionX) >> 2, position_idx, | ||
| 482 | position_name); | ||
| 482 | } | 483 | } |
| 483 | const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2; | 484 | const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2; |
| 484 | for (u32 i = 0; i < info.input_generics.size(); ++i) { | 485 | for (u32 i = 0; i < info.input_generics.size(); ++i) { |
| @@ -486,8 +487,8 @@ void EmitContext::DefineHelperFunctions() { | |||
| 486 | continue; | 487 | continue; |
| 487 | } | 488 | } |
| 488 | const auto vertex_idx{is_array ? "[vertex]" : ""}; | 489 | const auto vertex_idx{is_array ? "[vertex]" : ""}; |
| 489 | func += fmt::format("case {}:", base_attribute_value + i); | 490 | func += fmt::format("case {}:return in_attr{}{}[masked_index];", |
| 490 | func += fmt::format("return in_attr{}{}[masked_index];", i, vertex_idx); | 491 | base_attribute_value + i, i, vertex_idx); |
| 491 | } | 492 | } |
| 492 | func += "default: return 0.0;}}"; | 493 | func += "default: return 0.0;}}"; |
| 493 | header += func; | 494 | header += func; |
| @@ -508,8 +509,8 @@ std::string EmitContext::DefineGlobalMemoryFunctions() { | |||
| 508 | for (size_t i = 0; i < addr_xy.size(); ++i) { | 509 | for (size_t i = 0; i < addr_xy.size(); ++i) { |
| 509 | const auto addr_loc{ssbo.cbuf_offset + 4 * i}; | 510 | const auto addr_loc{ssbo.cbuf_offset + 4 * i}; |
| 510 | const auto size_loc{size_cbuf_offset + 4 * i}; | 511 | const auto size_loc{size_cbuf_offset + 4 * i}; |
| 511 | addr_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, addr_loc / 16, CbufSwizzle(addr_loc)); | 512 | addr_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, addr_loc / 16, Swizzle(addr_loc)); |
| 512 | size_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, size_loc / 16, CbufSwizzle(size_loc)); | 513 | size_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, size_loc / 16, Swizzle(size_loc)); |
| 513 | } | 514 | } |
| 514 | const auto addr_pack{fmt::format("packUint2x32(uvec2({},{}))", addr_xy[0], addr_xy[1])}; | 515 | const auto addr_pack{fmt::format("packUint2x32(uvec2({},{}))", addr_xy[0], addr_xy[1])}; |
| 515 | const auto addr_statment{fmt::format("uint64_t {}={};", ssbo_addr, addr_pack)}; | 516 | const auto addr_statment{fmt::format("uint64_t {}={};", ssbo_addr, addr_pack)}; |