draw_manager.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "common/common_types.h"
  5. #include "video_core/engines/maxwell_3d.h"
  6. namespace VideoCore {
  7. class RasterizerInterface;
  8. }
  9. namespace Tegra::Engines {
  10. using PrimitiveTopologyControl = Maxwell3D::Regs::PrimitiveTopologyControl;
  11. using PrimitiveTopology = Maxwell3D::Regs::PrimitiveTopology;
  12. using PrimitiveTopologyOverride = Maxwell3D::Regs::PrimitiveTopologyOverride;
  13. using IndexBuffer = Maxwell3D::Regs::IndexBuffer;
  14. using VertexBuffer = Maxwell3D::Regs::VertexBuffer;
  15. using IndexBufferSmall = Maxwell3D::Regs::IndexBufferSmall;
  16. class DrawManager {
  17. public:
  18. enum class DrawMode : u32 { General = 0, Instance, InlineIndex };
  19. struct State {
  20. PrimitiveTopology topology{};
  21. DrawMode draw_mode{};
  22. bool draw_indexed{};
  23. u32 base_index{};
  24. VertexBuffer vertex_buffer;
  25. IndexBuffer index_buffer;
  26. u32 base_instance{};
  27. u32 instance_count{};
  28. std::vector<u8> inline_index_draw_indexes;
  29. };
  30. struct DrawTextureState {
  31. f32 dst_x0;
  32. f32 dst_y0;
  33. f32 dst_x1;
  34. f32 dst_y1;
  35. f32 src_x0;
  36. f32 src_y0;
  37. f32 src_x1;
  38. f32 src_y1;
  39. u32 src_sampler;
  40. u32 src_texture;
  41. };
  42. struct IndirectParams {
  43. bool is_byte_count;
  44. bool is_indexed;
  45. bool include_count;
  46. GPUVAddr count_start_address;
  47. GPUVAddr indirect_start_address;
  48. size_t buffer_size;
  49. size_t max_draw_counts;
  50. size_t stride;
  51. };
  52. explicit DrawManager(Maxwell3D* maxwell_3d);
  53. void ProcessMethodCall(u32 method, u32 argument);
  54. void Clear(u32 layer_count);
  55. void DrawDeferred();
  56. void DrawArray(PrimitiveTopology topology, u32 vertex_first, u32 vertex_count,
  57. u32 base_instance, u32 num_instances);
  58. void DrawArrayInstanced(PrimitiveTopology topology, u32 vertex_first, u32 vertex_count,
  59. bool subsequent);
  60. void DrawIndex(PrimitiveTopology topology, u32 index_first, u32 index_count, u32 base_index,
  61. u32 base_instance, u32 num_instances);
  62. void DrawArrayIndirect(PrimitiveTopology topology);
  63. void DrawIndexedIndirect(PrimitiveTopology topology, u32 index_first, u32 index_count);
  64. const State& GetDrawState() const {
  65. return draw_state;
  66. }
  67. const DrawTextureState& GetDrawTextureState() const {
  68. return draw_texture_state;
  69. }
  70. IndirectParams& GetIndirectParams() {
  71. return indirect_state;
  72. }
  73. const IndirectParams& GetIndirectParams() const {
  74. return indirect_state;
  75. }
  76. private:
  77. void SetInlineIndexBuffer(u32 index);
  78. void DrawBegin();
  79. void DrawEnd(u32 instance_count = 1, bool force_draw = false);
  80. void DrawIndexSmall(u32 argument);
  81. void DrawTexture();
  82. void UpdateTopology();
  83. void ProcessDraw(bool draw_indexed, u32 instance_count);
  84. void ProcessDrawIndirect();
  85. Maxwell3D* maxwell3d{};
  86. State draw_state{};
  87. DrawTextureState draw_texture_state{};
  88. IndirectParams indirect_state{};
  89. };
  90. } // namespace Tegra::Engines