diff options
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate_program.cpp | 116 |
1 files changed, 74 insertions, 42 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp index ac159d24b..a42453e90 100644 --- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp | |||
| @@ -171,6 +171,70 @@ std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings( | |||
| 171 | } | 171 | } |
| 172 | return mapping; | 172 | return mapping; |
| 173 | } | 173 | } |
| 174 | |||
| 175 | void EmitGeometryPassthrough(IR::IREmitter& ir, const IR::Program& program, | ||
| 176 | const Shader::VaryingState& passthrough_mask, | ||
| 177 | bool passthrough_position, | ||
| 178 | std::optional<IR::Attribute> passthrough_layer_attr) { | ||
| 179 | for (u32 i = 0; i < program.output_vertices; i++) { | ||
| 180 | // Assign generics from input | ||
| 181 | for (u32 j = 0; j < 32; j++) { | ||
| 182 | if (!passthrough_mask.Generic(j)) { | ||
| 183 | continue; | ||
| 184 | } | ||
| 185 | |||
| 186 | const IR::Attribute attr = IR::Attribute::Generic0X + (j * 4); | ||
| 187 | ir.SetAttribute(attr + 0, ir.GetAttribute(attr + 0, ir.Imm32(i)), ir.Imm32(0)); | ||
| 188 | ir.SetAttribute(attr + 1, ir.GetAttribute(attr + 1, ir.Imm32(i)), ir.Imm32(0)); | ||
| 189 | ir.SetAttribute(attr + 2, ir.GetAttribute(attr + 2, ir.Imm32(i)), ir.Imm32(0)); | ||
| 190 | ir.SetAttribute(attr + 3, ir.GetAttribute(attr + 3, ir.Imm32(i)), ir.Imm32(0)); | ||
| 191 | } | ||
| 192 | |||
| 193 | if (passthrough_position) { | ||
| 194 | // Assign position from input | ||
| 195 | const IR::Attribute attr = IR::Attribute::PositionX; | ||
| 196 | ir.SetAttribute(attr + 0, ir.GetAttribute(attr + 0, ir.Imm32(i)), ir.Imm32(0)); | ||
| 197 | ir.SetAttribute(attr + 1, ir.GetAttribute(attr + 1, ir.Imm32(i)), ir.Imm32(0)); | ||
| 198 | ir.SetAttribute(attr + 2, ir.GetAttribute(attr + 2, ir.Imm32(i)), ir.Imm32(0)); | ||
| 199 | ir.SetAttribute(attr + 3, ir.GetAttribute(attr + 3, ir.Imm32(i)), ir.Imm32(0)); | ||
| 200 | } | ||
| 201 | |||
| 202 | if (passthrough_layer_attr) { | ||
| 203 | // Assign layer | ||
| 204 | ir.SetAttribute(IR::Attribute::Layer, ir.GetAttribute(*passthrough_layer_attr), | ||
| 205 | ir.Imm32(0)); | ||
| 206 | } | ||
| 207 | |||
| 208 | // Emit vertex | ||
| 209 | ir.EmitVertex(ir.Imm32(0)); | ||
| 210 | } | ||
| 211 | ir.EndPrimitive(ir.Imm32(0)); | ||
| 212 | } | ||
| 213 | |||
| 214 | u32 GetOutputTopologyVertices(OutputTopology output_topology) { | ||
| 215 | switch (output_topology) { | ||
| 216 | case OutputTopology::PointList: | ||
| 217 | return 1; | ||
| 218 | case OutputTopology::LineStrip: | ||
| 219 | return 2; | ||
| 220 | default: | ||
| 221 | return 3; | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | void LowerGeometryPassthrough(const IR::Program& program, const HostTranslateInfo& host_info) { | ||
| 226 | for (IR::Block* const block : program.blocks) { | ||
| 227 | for (IR::Inst& inst : block->Instructions()) { | ||
| 228 | if (inst.GetOpcode() == IR::Opcode::Epilogue) { | ||
| 229 | IR::IREmitter ir{*block, IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 230 | EmitGeometryPassthrough( | ||
| 231 | ir, program, program.info.passthrough, | ||
| 232 | program.info.passthrough.AnyComponent(IR::Attribute::PositionX), {}); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 174 | } // Anonymous namespace | 238 | } // Anonymous namespace |
| 175 | 239 | ||
| 176 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, | 240 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, |
| @@ -195,9 +259,14 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo | |||
| 195 | program.is_geometry_passthrough = sph.common0.geometry_passthrough != 0; | 259 | program.is_geometry_passthrough = sph.common0.geometry_passthrough != 0; |
| 196 | if (program.is_geometry_passthrough) { | 260 | if (program.is_geometry_passthrough) { |
| 197 | const auto& mask{env.GpPassthroughMask()}; | 261 | const auto& mask{env.GpPassthroughMask()}; |
| 198 | for (size_t i = 0; i < program.info.passthrough.mask.size(); ++i) { | 262 | for (size_t i = 0; i < mask.size() * 32; ++i) { |
| 199 | program.info.passthrough.mask[i] = ((mask[i / 32] >> (i % 32)) & 1) == 0; | 263 | program.info.passthrough.mask[i] = ((mask[i / 32] >> (i % 32)) & 1) == 0; |
| 200 | } | 264 | } |
| 265 | |||
| 266 | if (!host_info.support_geometry_shader_passthrough) { | ||
| 267 | program.output_vertices = GetOutputTopologyVertices(program.output_topology); | ||
| 268 | LowerGeometryPassthrough(program, host_info); | ||
| 269 | } | ||
| 201 | } | 270 | } |
| 202 | break; | 271 | break; |
| 203 | } | 272 | } |
| @@ -223,7 +292,7 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo | |||
| 223 | 292 | ||
| 224 | Optimization::PositionPass(env, program); | 293 | Optimization::PositionPass(env, program); |
| 225 | 294 | ||
| 226 | Optimization::GlobalMemoryToStorageBufferPass(program); | 295 | Optimization::GlobalMemoryToStorageBufferPass(program, host_info); |
| 227 | Optimization::TexturePass(env, program, host_info); | 296 | Optimization::TexturePass(env, program, host_info); |
| 228 | 297 | ||
| 229 | if (Settings::values.resolution_info.active) { | 298 | if (Settings::values.resolution_info.active) { |
| @@ -342,17 +411,7 @@ IR::Program GenerateGeometryPassthrough(ObjectPool<IR::Inst>& inst_pool, | |||
| 342 | IR::Program program; | 411 | IR::Program program; |
| 343 | program.stage = Stage::Geometry; | 412 | program.stage = Stage::Geometry; |
| 344 | program.output_topology = output_topology; | 413 | program.output_topology = output_topology; |
| 345 | switch (output_topology) { | 414 | program.output_vertices = GetOutputTopologyVertices(output_topology); |
| 346 | case OutputTopology::PointList: | ||
| 347 | program.output_vertices = 1; | ||
| 348 | break; | ||
| 349 | case OutputTopology::LineStrip: | ||
| 350 | program.output_vertices = 2; | ||
| 351 | break; | ||
| 352 | default: | ||
| 353 | program.output_vertices = 3; | ||
| 354 | break; | ||
| 355 | } | ||
| 356 | 415 | ||
| 357 | program.is_geometry_passthrough = false; | 416 | program.is_geometry_passthrough = false; |
| 358 | program.info.loads.mask = source_program.info.stores.mask; | 417 | program.info.loads.mask = source_program.info.stores.mask; |
| @@ -366,35 +425,8 @@ IR::Program GenerateGeometryPassthrough(ObjectPool<IR::Inst>& inst_pool, | |||
| 366 | node.data.block = current_block; | 425 | node.data.block = current_block; |
| 367 | 426 | ||
| 368 | IR::IREmitter ir{*current_block}; | 427 | IR::IREmitter ir{*current_block}; |
| 369 | for (u32 i = 0; i < program.output_vertices; i++) { | 428 | EmitGeometryPassthrough(ir, program, program.info.stores, true, |
| 370 | // Assign generics from input | 429 | source_program.info.emulated_layer); |
| 371 | for (u32 j = 0; j < 32; j++) { | ||
| 372 | if (!program.info.stores.Generic(j)) { | ||
| 373 | continue; | ||
| 374 | } | ||
| 375 | |||
| 376 | const IR::Attribute attr = IR::Attribute::Generic0X + (j * 4); | ||
| 377 | ir.SetAttribute(attr + 0, ir.GetAttribute(attr + 0, ir.Imm32(i)), ir.Imm32(0)); | ||
| 378 | ir.SetAttribute(attr + 1, ir.GetAttribute(attr + 1, ir.Imm32(i)), ir.Imm32(0)); | ||
| 379 | ir.SetAttribute(attr + 2, ir.GetAttribute(attr + 2, ir.Imm32(i)), ir.Imm32(0)); | ||
| 380 | ir.SetAttribute(attr + 3, ir.GetAttribute(attr + 3, ir.Imm32(i)), ir.Imm32(0)); | ||
| 381 | } | ||
| 382 | |||
| 383 | // Assign position from input | ||
| 384 | const IR::Attribute attr = IR::Attribute::PositionX; | ||
| 385 | ir.SetAttribute(attr + 0, ir.GetAttribute(attr + 0, ir.Imm32(i)), ir.Imm32(0)); | ||
| 386 | ir.SetAttribute(attr + 1, ir.GetAttribute(attr + 1, ir.Imm32(i)), ir.Imm32(0)); | ||
| 387 | ir.SetAttribute(attr + 2, ir.GetAttribute(attr + 2, ir.Imm32(i)), ir.Imm32(0)); | ||
| 388 | ir.SetAttribute(attr + 3, ir.GetAttribute(attr + 3, ir.Imm32(i)), ir.Imm32(0)); | ||
| 389 | |||
| 390 | // Assign layer | ||
| 391 | ir.SetAttribute(IR::Attribute::Layer, ir.GetAttribute(source_program.info.emulated_layer), | ||
| 392 | ir.Imm32(0)); | ||
| 393 | |||
| 394 | // Emit vertex | ||
| 395 | ir.EmitVertex(ir.Imm32(0)); | ||
| 396 | } | ||
| 397 | ir.EndPrimitive(ir.Imm32(0)); | ||
| 398 | 430 | ||
| 399 | IR::Block* return_block{block_pool.Create(inst_pool)}; | 431 | IR::Block* return_block{block_pool.Create(inst_pool)}; |
| 400 | IR::IREmitter{*return_block}.Epilogue(); | 432 | IR::IREmitter{*return_block}.Epilogue(); |