2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-02-12 03:34:20 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-09-26 00:41:21 +02:00
|
|
|
#include <array>
|
2019-03-06 02:25:01 +01:00
|
|
|
#include <cstddef>
|
2023-08-27 02:58:00 +02:00
|
|
|
#include <optional>
|
2019-04-23 01:05:43 +02:00
|
|
|
#include <vector>
|
|
|
|
#include "common/bit_field.h"
|
2018-09-26 00:41:21 +02:00
|
|
|
#include "common/common_funcs.h"
|
2018-02-12 03:34:20 +01:00
|
|
|
#include "common/common_types.h"
|
2020-04-28 03:47:58 +02:00
|
|
|
#include "video_core/engines/engine_interface.h"
|
2019-09-25 15:53:18 +02:00
|
|
|
#include "video_core/engines/engine_upload.h"
|
2019-07-12 02:54:07 +02:00
|
|
|
#include "video_core/textures/texture.h"
|
2019-04-06 00:21:15 +02:00
|
|
|
|
2019-04-23 01:05:43 +02:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2019-04-06 00:21:15 +02:00
|
|
|
namespace Tegra {
|
|
|
|
class MemoryManager;
|
|
|
|
}
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2019-04-23 01:05:43 +02:00
|
|
|
namespace VideoCore {
|
|
|
|
class RasterizerInterface;
|
|
|
|
}
|
|
|
|
|
2018-07-21 00:14:17 +02:00
|
|
|
namespace Tegra::Engines {
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2019-04-23 14:44:52 +02:00
|
|
|
/**
|
|
|
|
* This Engine is known as GK104_Compute. Documentation can be found in:
|
|
|
|
* https://github.com/envytools/envytools/blob/master/rnndb/graph/gk104_compute.xml
|
|
|
|
* https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nvc0/nve4_compute.xml.h
|
|
|
|
*/
|
|
|
|
|
2019-01-23 00:49:31 +01:00
|
|
|
#define KEPLER_COMPUTE_REG_INDEX(field_name) \
|
|
|
|
(offsetof(Tegra::Engines::KeplerCompute::Regs, field_name) / sizeof(u32))
|
2018-09-26 00:41:21 +02:00
|
|
|
|
2023-08-27 02:58:00 +02:00
|
|
|
#define LAUNCH_REG_INDEX(field_name) \
|
|
|
|
(offsetof(Tegra::Engines::KeplerCompute::LaunchParams, field_name) / sizeof(u32))
|
|
|
|
|
2021-02-17 00:52:12 +01:00
|
|
|
class KeplerCompute final : public EngineInterface {
|
2018-02-12 05:44:12 +01:00
|
|
|
public:
|
2020-06-11 05:58:57 +02:00
|
|
|
explicit KeplerCompute(Core::System& system, MemoryManager& memory_manager);
|
2019-01-23 00:49:31 +01:00
|
|
|
~KeplerCompute();
|
|
|
|
|
2020-06-11 05:58:57 +02:00
|
|
|
/// Binds a rasterizer to this engine.
|
2021-01-05 08:09:39 +01:00
|
|
|
void BindRasterizer(VideoCore::RasterizerInterface* rasterizer);
|
2020-06-11 05:58:57 +02:00
|
|
|
|
2019-01-23 00:49:31 +01:00
|
|
|
static constexpr std::size_t NumConstBuffers = 8;
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-09-26 00:41:21 +02:00
|
|
|
struct Regs {
|
|
|
|
static constexpr std::size_t NUM_REGS = 0xCF8;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x60);
|
2019-04-23 01:05:43 +02:00
|
|
|
|
2019-04-25 18:57:10 +02:00
|
|
|
Upload::Registers upload;
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
BitField<0, 1, u32> linear;
|
|
|
|
};
|
|
|
|
} exec_upload;
|
|
|
|
|
|
|
|
u32 data_upload;
|
|
|
|
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x3F);
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 address;
|
|
|
|
GPUVAddr Address() const {
|
2022-11-29 14:04:40 +01:00
|
|
|
return GPUVAddr{address} << 8;
|
2019-04-23 01:05:43 +02:00
|
|
|
}
|
|
|
|
} launch_desc_loc;
|
|
|
|
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x1);
|
2018-09-26 00:41:21 +02:00
|
|
|
|
2019-01-23 00:49:31 +01:00
|
|
|
u32 launch;
|
2018-09-26 00:41:21 +02:00
|
|
|
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x4A7);
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 address_high;
|
|
|
|
u32 address_low;
|
|
|
|
u32 limit;
|
|
|
|
GPUVAddr Address() const {
|
2022-11-29 14:04:40 +01:00
|
|
|
return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low};
|
2019-04-23 01:05:43 +02:00
|
|
|
}
|
|
|
|
} tsc;
|
|
|
|
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x3);
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 address_high;
|
|
|
|
u32 address_low;
|
|
|
|
u32 limit;
|
|
|
|
GPUVAddr Address() const {
|
2022-11-29 14:04:40 +01:00
|
|
|
return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low};
|
2019-04-23 01:05:43 +02:00
|
|
|
}
|
|
|
|
} tic;
|
|
|
|
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x22);
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 address_high;
|
|
|
|
u32 address_low;
|
|
|
|
GPUVAddr Address() const {
|
2022-11-29 14:04:40 +01:00
|
|
|
return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low};
|
2019-04-23 01:05:43 +02:00
|
|
|
}
|
|
|
|
} code_loc;
|
|
|
|
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x3FE);
|
2019-04-23 01:05:43 +02:00
|
|
|
|
2019-07-12 02:54:07 +02:00
|
|
|
u32 tex_cb_index;
|
2019-04-23 01:05:43 +02:00
|
|
|
|
2021-01-15 08:25:40 +01:00
|
|
|
INSERT_PADDING_WORDS_NOINIT(0x374);
|
2018-09-26 00:41:21 +02:00
|
|
|
};
|
|
|
|
std::array<u32, NUM_REGS> reg_array;
|
|
|
|
};
|
|
|
|
} regs{};
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
struct LaunchParams {
|
|
|
|
static constexpr std::size_t NUM_LAUNCH_PARAMETERS = 0x40;
|
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x8);
|
|
|
|
|
|
|
|
u32 program_start;
|
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x2);
|
|
|
|
|
|
|
|
BitField<30, 1, u32> linked_tsc;
|
|
|
|
|
|
|
|
BitField<0, 31, u32> grid_dim_x;
|
|
|
|
union {
|
|
|
|
BitField<0, 16, u32> grid_dim_y;
|
|
|
|
BitField<16, 16, u32> grid_dim_z;
|
|
|
|
};
|
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x3);
|
|
|
|
|
2019-11-13 03:26:56 +01:00
|
|
|
BitField<0, 18, u32> shared_alloc;
|
2019-04-23 01:05:43 +02:00
|
|
|
|
2019-06-08 01:35:46 +02:00
|
|
|
BitField<16, 16, u32> block_dim_x;
|
2019-04-23 01:05:43 +02:00
|
|
|
union {
|
|
|
|
BitField<0, 16, u32> block_dim_y;
|
|
|
|
BitField<16, 16, u32> block_dim_z;
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
BitField<0, 8, u32> const_buffer_enable_mask;
|
|
|
|
BitField<29, 2, u32> cache_layout;
|
2019-07-12 02:54:07 +02:00
|
|
|
};
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x8);
|
|
|
|
|
2019-06-08 01:36:22 +02:00
|
|
|
struct ConstBufferConfig {
|
2019-04-23 01:05:43 +02:00
|
|
|
u32 address_low;
|
|
|
|
union {
|
|
|
|
BitField<0, 8, u32> address_high;
|
|
|
|
BitField<15, 17, u32> size;
|
|
|
|
};
|
|
|
|
GPUVAddr Address() const {
|
2022-11-29 14:04:40 +01:00
|
|
|
return (GPUVAddr{address_high.Value()} << 32) | GPUVAddr{address_low};
|
2019-04-23 01:05:43 +02:00
|
|
|
}
|
2019-06-08 01:36:22 +02:00
|
|
|
};
|
|
|
|
std::array<ConstBufferConfig, NumConstBuffers> const_buffer_config;
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
BitField<0, 20, u32> local_pos_alloc;
|
|
|
|
BitField<27, 5, u32> barrier_alloc;
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
BitField<0, 20, u32> local_neg_alloc;
|
|
|
|
BitField<24, 5, u32> gpr_alloc;
|
|
|
|
};
|
|
|
|
|
2019-11-13 04:25:52 +01:00
|
|
|
union {
|
|
|
|
BitField<0, 20, u32> local_crs_alloc;
|
|
|
|
BitField<24, 5, u32> sass_version;
|
|
|
|
};
|
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x10);
|
2019-11-04 00:54:03 +01:00
|
|
|
} launch_description{};
|
2019-04-23 01:05:43 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 write_offset = 0;
|
|
|
|
u32 copy_size = 0;
|
|
|
|
std::vector<u8> inner_buffer;
|
|
|
|
} state{};
|
|
|
|
|
2018-09-26 00:41:21 +02:00
|
|
|
static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32),
|
2019-01-23 00:49:31 +01:00
|
|
|
"KeplerCompute Regs has wrong size");
|
|
|
|
|
2019-04-23 01:05:43 +02:00
|
|
|
static_assert(sizeof(LaunchParams) == LaunchParams::NUM_LAUNCH_PARAMETERS * sizeof(u32),
|
|
|
|
"KeplerCompute LaunchParams has wrong size");
|
|
|
|
|
2018-02-12 05:44:12 +01:00
|
|
|
/// Write the value to the register identified by method.
|
2020-04-28 03:47:58 +02:00
|
|
|
void CallMethod(u32 method, u32 method_argument, bool is_last_call) override;
|
2019-04-06 00:25:20 +02:00
|
|
|
|
2020-04-20 08:16:56 +02:00
|
|
|
/// Write multiple values to the register identified by method.
|
2020-04-28 19:53:47 +02:00
|
|
|
void CallMultiMethod(u32 method, const u32* base_start, u32 amount,
|
|
|
|
u32 methods_pending) override;
|
2020-04-20 08:16:56 +02:00
|
|
|
|
2023-08-27 02:58:00 +02:00
|
|
|
std::optional<GPUVAddr> GetIndirectComputeAddress() const {
|
|
|
|
return indirect_compute;
|
|
|
|
}
|
|
|
|
|
2019-04-06 00:25:20 +02:00
|
|
|
private:
|
2019-04-23 01:05:43 +02:00
|
|
|
void ProcessLaunch();
|
2019-07-12 02:54:07 +02:00
|
|
|
|
2022-11-27 00:58:06 +01:00
|
|
|
void ConsumeSinkImpl() override;
|
|
|
|
|
2019-07-12 02:54:07 +02:00
|
|
|
/// Retrieves information about a specific TIC entry from the TIC buffer.
|
|
|
|
Texture::TICEntry GetTICEntry(u32 tic_index) const;
|
|
|
|
|
|
|
|
/// Retrieves information about a specific TSC entry from the TSC buffer.
|
|
|
|
Texture::TSCEntry GetTSCEntry(u32 tsc_index) const;
|
2020-06-11 05:58:57 +02:00
|
|
|
|
|
|
|
Core::System& system;
|
|
|
|
MemoryManager& memory_manager;
|
|
|
|
VideoCore::RasterizerInterface* rasterizer = nullptr;
|
|
|
|
Upload::State upload_state;
|
2023-08-27 02:58:00 +02:00
|
|
|
GPUVAddr upload_address;
|
|
|
|
|
|
|
|
struct UploadInfo {
|
|
|
|
GPUVAddr upload_address;
|
|
|
|
GPUVAddr exec_address;
|
|
|
|
u32 copy_size;
|
|
|
|
};
|
|
|
|
std::vector<UploadInfo> uploads;
|
|
|
|
std::optional<GPUVAddr> indirect_compute{};
|
2018-02-12 05:44:12 +01:00
|
|
|
};
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-09-26 00:41:21 +02:00
|
|
|
#define ASSERT_REG_POSITION(field_name, position) \
|
2019-01-23 00:49:31 +01:00
|
|
|
static_assert(offsetof(KeplerCompute::Regs, field_name) == position * 4, \
|
2018-09-26 00:41:21 +02:00
|
|
|
"Field " #field_name " has invalid position")
|
|
|
|
|
2019-04-23 01:05:43 +02:00
|
|
|
#define ASSERT_LAUNCH_PARAM_POSITION(field_name, position) \
|
|
|
|
static_assert(offsetof(KeplerCompute::LaunchParams, field_name) == position * 4, \
|
|
|
|
"Field " #field_name " has invalid position")
|
|
|
|
|
|
|
|
ASSERT_REG_POSITION(upload, 0x60);
|
|
|
|
ASSERT_REG_POSITION(exec_upload, 0x6C);
|
|
|
|
ASSERT_REG_POSITION(data_upload, 0x6D);
|
2019-01-23 00:49:31 +01:00
|
|
|
ASSERT_REG_POSITION(launch, 0xAF);
|
2019-04-23 01:05:43 +02:00
|
|
|
ASSERT_REG_POSITION(tsc, 0x557);
|
|
|
|
ASSERT_REG_POSITION(tic, 0x55D);
|
|
|
|
ASSERT_REG_POSITION(code_loc, 0x582);
|
2019-07-12 02:54:07 +02:00
|
|
|
ASSERT_REG_POSITION(tex_cb_index, 0x982);
|
2019-04-23 01:05:43 +02:00
|
|
|
ASSERT_LAUNCH_PARAM_POSITION(program_start, 0x8);
|
|
|
|
ASSERT_LAUNCH_PARAM_POSITION(grid_dim_x, 0xC);
|
|
|
|
ASSERT_LAUNCH_PARAM_POSITION(shared_alloc, 0x11);
|
|
|
|
ASSERT_LAUNCH_PARAM_POSITION(block_dim_x, 0x12);
|
2019-07-12 02:54:07 +02:00
|
|
|
ASSERT_LAUNCH_PARAM_POSITION(const_buffer_enable_mask, 0x14);
|
2019-04-23 01:05:43 +02:00
|
|
|
ASSERT_LAUNCH_PARAM_POSITION(const_buffer_config, 0x1D);
|
2018-09-26 00:41:21 +02:00
|
|
|
|
|
|
|
#undef ASSERT_REG_POSITION
|
|
|
|
|
2018-07-21 00:14:17 +02:00
|
|
|
} // namespace Tegra::Engines
|