diff options
| author | 2021-06-02 00:33:03 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:37 -0400 | |
| commit | f4799e8fa15b92d8d5607dc5dfca4974901ee06c (patch) | |
| tree | fe05a0bb667c92f018d08aaf7e410fd55746e0c1 /src/shader_recompiler/backend/glsl/emit_context.cpp | |
| parent | glsl: Yet another gl_ViewportIndex fix attempt (diff) | |
| download | yuzu-f4799e8fa15b92d8d5607dc5dfca4974901ee06c.tar.gz yuzu-f4799e8fa15b92d8d5607dc5dfca4974901ee06c.tar.xz yuzu-f4799e8fa15b92d8d5607dc5dfca4974901ee06c.zip | |
glsl: Implement transform feedback
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index 6f10002fe..58355d5e3 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -37,7 +37,6 @@ bool StoresPerVertexAttributes(Stage stage) { | |||
| 37 | case Stage::VertexA: | 37 | case Stage::VertexA: |
| 38 | case Stage::VertexB: | 38 | case Stage::VertexB: |
| 39 | case Stage::Geometry: | 39 | case Stage::Geometry: |
| 40 | case Stage::TessellationControl: | ||
| 41 | case Stage::TessellationEval: | 40 | case Stage::TessellationEval: |
| 42 | return true; | 41 | return true; |
| 43 | default: | 42 | default: |
| @@ -154,9 +153,7 @@ void SetupOutPerVertex(Stage stage, const Info& info, std::string& header) { | |||
| 154 | return; | 153 | return; |
| 155 | } | 154 | } |
| 156 | header += "out gl_PerVertex{"; | 155 | header += "out gl_PerVertex{"; |
| 157 | if (info.stores_position) { | 156 | header += "vec4 gl_Position;"; |
| 158 | header += "vec4 gl_Position;"; | ||
| 159 | } | ||
| 160 | if (info.stores_point_size) { | 157 | if (info.stores_point_size) { |
| 161 | header += "float gl_PointSize;"; | 158 | header += "float gl_PointSize;"; |
| 162 | } | 159 | } |
| @@ -236,10 +233,8 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 236 | } | 233 | } |
| 237 | for (size_t index = 0; index < info.stores_generics.size(); ++index) { | 234 | for (size_t index = 0; index < info.stores_generics.size(); ++index) { |
| 238 | // TODO: Properly resolve attribute issues | 235 | // TODO: Properly resolve attribute issues |
| 239 | const auto declaration{fmt::format("layout(location={}) out vec4 out_attr{}{};", index, | ||
| 240 | index, OutputDecorator(stage, program.invocations))}; | ||
| 241 | if (info.stores_generics[index] || stage == Stage::VertexA || stage == Stage::VertexB) { | 236 | if (info.stores_generics[index] || stage == Stage::VertexA || stage == Stage::VertexB) { |
| 242 | header += declaration; | 237 | DefineGenericOutput(index, program.invocations); |
| 243 | } | 238 | } |
| 244 | } | 239 | } |
| 245 | header += "\n"; | 240 | header += "\n"; |
| @@ -312,13 +307,53 @@ void EmitContext::DefineStorageBuffers(Bindings& bindings) { | |||
| 312 | } | 307 | } |
| 313 | } | 308 | } |
| 314 | 309 | ||
| 310 | void EmitContext::DefineGenericOutput(size_t index, u32 invocations) { | ||
| 311 | static constexpr std::string_view swizzle{"xyzw"}; | ||
| 312 | const size_t base_index{static_cast<size_t>(IR::Attribute::Generic0X) + index * 4}; | ||
| 313 | u32 element{0}; | ||
| 314 | while (element < 4) { | ||
| 315 | std::string definition{fmt::format("layout(location={}", index)}; | ||
| 316 | const u32 remainder{4 - element}; | ||
| 317 | const TransformFeedbackVarying* xfb_varying{}; | ||
| 318 | if (!runtime_info.xfb_varyings.empty()) { | ||
| 319 | xfb_varying = &runtime_info.xfb_varyings[base_index + element]; | ||
| 320 | xfb_varying = xfb_varying && xfb_varying->components > 0 ? xfb_varying : nullptr; | ||
| 321 | } | ||
| 322 | const u32 num_components{xfb_varying ? xfb_varying->components : remainder}; | ||
| 323 | if (element > 0) { | ||
| 324 | definition += fmt::format(",component={}", element); | ||
| 325 | } | ||
| 326 | if (xfb_varying) { | ||
| 327 | definition += | ||
| 328 | fmt::format(",xfb_buffer={},xfb_stride={},xfb_offset={}", xfb_varying->buffer, | ||
| 329 | xfb_varying->stride, xfb_varying->offset); | ||
| 330 | } | ||
| 331 | std::string name{fmt::format("out_attr{}", index)}; | ||
| 332 | if (num_components < 4 || element > 0) { | ||
| 333 | name += fmt::format("_{}", swizzle.substr(element, num_components)); | ||
| 334 | } | ||
| 335 | const auto type{num_components == 1 ? "float" : fmt::format("vec{}", num_components)}; | ||
| 336 | definition += fmt::format(")out {} {}{};", type, name, OutputDecorator(stage, invocations)); | ||
| 337 | header += definition; | ||
| 338 | |||
| 339 | const GenericElementInfo element_info{ | ||
| 340 | .name = name, | ||
| 341 | .first_element = element, | ||
| 342 | .num_components = num_components, | ||
| 343 | }; | ||
| 344 | std::fill_n(output_generics[index].begin() + element, num_components, element_info); | ||
| 345 | element += num_components; | ||
| 346 | } | ||
| 347 | header += "\n"; | ||
| 348 | } | ||
| 349 | |||
| 315 | void EmitContext::DefineHelperFunctions() { | 350 | void EmitContext::DefineHelperFunctions() { |
| 316 | if (info.uses_global_increment || info.uses_shared_increment) { | 351 | if (info.uses_global_increment || info.uses_shared_increment) { |
| 317 | header += "uint CasIncrement(uint op_a,uint op_b){return(op_a>=op_b)?0u:(op_a+1u);}\n"; | 352 | header += "uint CasIncrement(uint op_a,uint op_b){return(op_a>=op_b)?0u:(op_a+1u);}\n"; |
| 318 | } | 353 | } |
| 319 | if (info.uses_global_decrement || info.uses_shared_decrement) { | 354 | if (info.uses_global_decrement || info.uses_shared_decrement) { |
| 320 | header += | 355 | header += "uint CasDecrement(uint op_a,uint " |
| 321 | "uint CasDecrement(uint op_a,uint op_b){return(op_a==0||op_a>op_b)?op_b:(op_a-1u);}\n"; | 356 | "op_b){return(op_a==0||op_a>op_b)?op_b:(op_a-1u);}\n"; |
| 322 | } | 357 | } |
| 323 | if (info.uses_atomic_f32_add) { | 358 | if (info.uses_atomic_f32_add) { |
| 324 | header += "uint CasFloatAdd(uint op_a,float op_b){return " | 359 | header += "uint CasFloatAdd(uint op_a,float op_b){return " |