diff options
| author | 2018-03-17 17:06:23 -0500 | |
|---|---|---|
| committer | 2018-03-17 18:32:57 -0500 | |
| commit | 88698c156ffe567885f154c80270db962d29e82b (patch) | |
| tree | ec278246ce968261e472f43acb13e2362c0f1158 /src | |
| parent | GPU: Corrected some register offsets and removed superfluous macro registers. (diff) | |
| download | yuzu-88698c156ffe567885f154c80270db962d29e82b.tar.gz yuzu-88698c156ffe567885f154c80270db962d29e82b.tar.xz yuzu-88698c156ffe567885f154c80270db962d29e82b.zip | |
GPU: Store shader constbuffer bindings in the GPU state.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 38 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.h | 28 |
2 files changed, 61 insertions, 5 deletions
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 4b15ed2f2..50153eff3 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -43,6 +43,26 @@ void Maxwell3D::WriteReg(u32 method, u32 value) { | |||
| 43 | ASSERT_MSG(regs.code_address.CodeAddress() == 0, "Unexpected CODE_ADDRESS register value."); | 43 | ASSERT_MSG(regs.code_address.CodeAddress() == 0, "Unexpected CODE_ADDRESS register value."); |
| 44 | break; | 44 | break; |
| 45 | } | 45 | } |
| 46 | case MAXWELL3D_REG_INDEX(cb_bind[0].raw_config): { | ||
| 47 | ProcessCBBind(Regs::ShaderType::Vertex); | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | case MAXWELL3D_REG_INDEX(cb_bind[1].raw_config): { | ||
| 51 | ProcessCBBind(Regs::ShaderType::TesselationControl); | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | case MAXWELL3D_REG_INDEX(cb_bind[2].raw_config): { | ||
| 55 | ProcessCBBind(Regs::ShaderType::TesselationEval); | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | case MAXWELL3D_REG_INDEX(cb_bind[3].raw_config): { | ||
| 59 | ProcessCBBind(Regs::ShaderType::Geometry); | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | case MAXWELL3D_REG_INDEX(cb_bind[4].raw_config): { | ||
| 63 | ProcessCBBind(Regs::ShaderType::Fragment); | ||
| 64 | break; | ||
| 65 | } | ||
| 46 | case MAXWELL3D_REG_INDEX(draw.vertex_end_gl): { | 66 | case MAXWELL3D_REG_INDEX(draw.vertex_end_gl): { |
| 47 | DrawArrays(); | 67 | DrawArrays(); |
| 48 | break; | 68 | break; |
| @@ -95,11 +115,10 @@ void Maxwell3D::SetShader(const std::vector<u32>& parameters) { | |||
| 95 | auto shader_type = static_cast<Regs::ShaderType>(parameters[3]); | 115 | auto shader_type = static_cast<Regs::ShaderType>(parameters[3]); |
| 96 | GPUVAddr cb_address = parameters[4] << 8; | 116 | GPUVAddr cb_address = parameters[4] << 8; |
| 97 | 117 | ||
| 98 | auto& shader = state.shaders[static_cast<size_t>(shader_program)]; | 118 | auto& shader = state.shader_programs[static_cast<size_t>(shader_program)]; |
| 99 | shader.program = shader_program; | 119 | shader.program = shader_program; |
| 100 | shader.type = shader_type; | 120 | shader.type = shader_type; |
| 101 | shader.address = address; | 121 | shader.address = address; |
| 102 | shader.cb_address = cb_address; | ||
| 103 | 122 | ||
| 104 | // Perform the same operations as the real macro code. | 123 | // Perform the same operations as the real macro code. |
| 105 | // TODO(Subv): Early exit if register 0xD1C + shader_program contains the same as params[1]. | 124 | // TODO(Subv): Early exit if register 0xD1C + shader_program contains the same as params[1]. |
| @@ -118,6 +137,21 @@ void Maxwell3D::SetShader(const std::vector<u32>& parameters) { | |||
| 118 | // shader. It's likely that these are the constants for the shader. | 137 | // shader. It's likely that these are the constants for the shader. |
| 119 | regs.cb_bind[static_cast<size_t>(shader_type)].valid.Assign(1); | 138 | regs.cb_bind[static_cast<size_t>(shader_type)].valid.Assign(1); |
| 120 | regs.cb_bind[static_cast<size_t>(shader_type)].index.Assign(1); | 139 | regs.cb_bind[static_cast<size_t>(shader_type)].index.Assign(1); |
| 140 | |||
| 141 | ProcessCBBind(shader_type); | ||
| 142 | } | ||
| 143 | |||
| 144 | void Maxwell3D::ProcessCBBind(Regs::ShaderType stage) { | ||
| 145 | // Bind the buffer currently in CB_ADDRESS to the specified index in the desired shader stage. | ||
| 146 | auto& shader = state.shader_stages[static_cast<size_t>(stage)]; | ||
| 147 | auto& bind_data = regs.cb_bind[static_cast<size_t>(stage)]; | ||
| 148 | |||
| 149 | auto& buffer = shader.const_buffers[bind_data.index]; | ||
| 150 | |||
| 151 | buffer.enabled = bind_data.valid.Value() != 0; | ||
| 152 | buffer.index = bind_data.index; | ||
| 153 | buffer.address = regs.const_buffer.BufferAddress(); | ||
| 154 | buffer.size = regs.const_buffer.cb_size; | ||
| 121 | } | 155 | } |
| 122 | 156 | ||
| 123 | } // namespace Engines | 157 | } // namespace Engines |
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index c8920da50..9e28d8319 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -39,6 +39,8 @@ public: | |||
| 39 | static constexpr size_t NumVertexArrays = 32; | 39 | static constexpr size_t NumVertexArrays = 32; |
| 40 | static constexpr size_t MaxShaderProgram = 6; | 40 | static constexpr size_t MaxShaderProgram = 6; |
| 41 | static constexpr size_t MaxShaderType = 5; | 41 | static constexpr size_t MaxShaderType = 5; |
| 42 | // Maximum number of const buffers per shader stage. | ||
| 43 | static constexpr size_t MaxConstBuffers = 16; | ||
| 42 | 44 | ||
| 43 | enum class QueryMode : u32 { | 45 | enum class QueryMode : u32 { |
| 44 | Write = 0, | 46 | Write = 0, |
| @@ -146,12 +148,18 @@ public: | |||
| 146 | u32 cb_address_low; | 148 | u32 cb_address_low; |
| 147 | u32 cb_pos; | 149 | u32 cb_pos; |
| 148 | u32 cb_data[NumCBData]; | 150 | u32 cb_data[NumCBData]; |
| 151 | |||
| 152 | GPUVAddr BufferAddress() const { | ||
| 153 | return static_cast<GPUVAddr>( | ||
| 154 | (static_cast<GPUVAddr>(cb_address_high) << 32) | cb_address_low); | ||
| 155 | } | ||
| 149 | } const_buffer; | 156 | } const_buffer; |
| 150 | 157 | ||
| 151 | INSERT_PADDING_WORDS(0x10); | 158 | INSERT_PADDING_WORDS(0x10); |
| 152 | 159 | ||
| 153 | struct { | 160 | struct { |
| 154 | union { | 161 | union { |
| 162 | u32 raw_config; | ||
| 155 | BitField<0, 1, u32> valid; | 163 | BitField<0, 1, u32> valid; |
| 156 | BitField<4, 5, u32> index; | 164 | BitField<4, 5, u32> index; |
| 157 | }; | 165 | }; |
| @@ -167,14 +175,25 @@ public: | |||
| 167 | static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32), "Maxwell3D Regs has wrong size"); | 175 | static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32), "Maxwell3D Regs has wrong size"); |
| 168 | 176 | ||
| 169 | struct State { | 177 | struct State { |
| 170 | struct ShaderInfo { | 178 | struct ConstBufferInfo { |
| 179 | GPUVAddr address; | ||
| 180 | u32 index; | ||
| 181 | u32 size; | ||
| 182 | bool enabled; | ||
| 183 | }; | ||
| 184 | |||
| 185 | struct ShaderProgramInfo { | ||
| 171 | Regs::ShaderType type; | 186 | Regs::ShaderType type; |
| 172 | Regs::ShaderProgram program; | 187 | Regs::ShaderProgram program; |
| 173 | GPUVAddr address; | 188 | GPUVAddr address; |
| 174 | GPUVAddr cb_address; | ||
| 175 | }; | 189 | }; |
| 176 | 190 | ||
| 177 | std::array<ShaderInfo, Regs::MaxShaderProgram> shaders; | 191 | struct ShaderStageInfo { |
| 192 | std::array<ConstBufferInfo, Regs::MaxConstBuffers> const_buffers; | ||
| 193 | }; | ||
| 194 | |||
| 195 | std::array<ShaderStageInfo, Regs::MaxShaderType> shader_stages; | ||
| 196 | std::array<ShaderProgramInfo, Regs::MaxShaderProgram> shader_programs; | ||
| 178 | }; | 197 | }; |
| 179 | 198 | ||
| 180 | State state{}; | 199 | State state{}; |
| @@ -185,6 +204,9 @@ private: | |||
| 185 | /// Handles a write to the QUERY_GET register. | 204 | /// Handles a write to the QUERY_GET register. |
| 186 | void ProcessQueryGet(); | 205 | void ProcessQueryGet(); |
| 187 | 206 | ||
| 207 | /// Handles a write to the CB_BIND register. | ||
| 208 | void ProcessCBBind(Regs::ShaderType stage); | ||
| 209 | |||
| 188 | /// Handles a write to the VERTEX_END_GL register, triggering a draw. | 210 | /// Handles a write to the VERTEX_END_GL register, triggering a draw. |
| 189 | void DrawArrays(); | 211 | void DrawArrays(); |
| 190 | 212 | ||