2018-09-11 03:00:55 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-04-02 02:37:32 +02:00
|
|
|
#include <array>
|
|
|
|
#include <optional>
|
|
|
|
|
2018-09-11 03:00:55 +02:00
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_funcs.h"
|
2018-09-11 18:08:06 +02:00
|
|
|
#include "common/common_types.h"
|
2018-09-11 03:00:55 +02:00
|
|
|
|
|
|
|
namespace Tegra::Shader {
|
|
|
|
|
|
|
|
enum class OutputTopology : u32 {
|
|
|
|
PointList = 1,
|
|
|
|
LineStrip = 6,
|
|
|
|
TriangleStrip = 7,
|
|
|
|
};
|
|
|
|
|
2020-04-02 02:37:32 +02:00
|
|
|
enum class PixelImap : u8 {
|
2019-02-13 02:14:39 +01:00
|
|
|
Unused = 0,
|
|
|
|
Constant = 1,
|
|
|
|
Perspective = 2,
|
|
|
|
ScreenLinear = 3,
|
|
|
|
};
|
|
|
|
|
2018-09-11 03:00:55 +02:00
|
|
|
// Documentation in:
|
2020-04-02 02:37:32 +02:00
|
|
|
// http://download.nvidia.com/open-gpu-doc/Shader-Program-Header/1/Shader-Program-Header.html
|
2018-09-11 03:00:55 +02:00
|
|
|
struct Header {
|
|
|
|
union {
|
|
|
|
BitField<0, 5, u32> sph_type;
|
|
|
|
BitField<5, 5, u32> version;
|
|
|
|
BitField<10, 4, u32> shader_type;
|
|
|
|
BitField<14, 1, u32> mrt_enable;
|
|
|
|
BitField<15, 1, u32> kills_pixels;
|
|
|
|
BitField<16, 1, u32> does_global_store;
|
|
|
|
BitField<17, 4, u32> sass_version;
|
|
|
|
BitField<21, 5, u32> reserved;
|
|
|
|
BitField<26, 1, u32> does_load_or_store;
|
|
|
|
BitField<27, 1, u32> does_fp64;
|
|
|
|
BitField<28, 4, u32> stream_out_mask;
|
2019-11-04 00:54:03 +01:00
|
|
|
} common0{};
|
2018-09-11 03:00:55 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
BitField<0, 24, u32> shader_local_memory_low_size;
|
|
|
|
BitField<24, 8, u32> per_patch_attribute_count;
|
2019-11-04 00:54:03 +01:00
|
|
|
} common1{};
|
2018-09-11 03:00:55 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
BitField<0, 24, u32> shader_local_memory_high_size;
|
|
|
|
BitField<24, 8, u32> threads_per_input_primitive;
|
2019-11-04 00:54:03 +01:00
|
|
|
} common2{};
|
2018-09-11 03:00:55 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
BitField<0, 24, u32> shader_local_memory_crs_size;
|
|
|
|
BitField<24, 4, OutputTopology> output_topology;
|
|
|
|
BitField<28, 4, u32> reserved;
|
2019-11-04 00:54:03 +01:00
|
|
|
} common3{};
|
2018-09-11 03:00:55 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
BitField<0, 12, u32> max_output_vertices;
|
|
|
|
BitField<12, 8, u32> store_req_start; // NOTE: not used by geometry shaders.
|
2020-04-02 02:37:32 +02:00
|
|
|
BitField<20, 4, u32> reserved;
|
|
|
|
BitField<24, 8, u32> store_req_end; // NOTE: not used by geometry shaders.
|
2019-11-04 00:54:03 +01:00
|
|
|
} common4{};
|
2018-09-11 03:00:55 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_BYTES(3); // ImapSystemValuesA
|
|
|
|
INSERT_UNION_PADDING_BYTES(1); // ImapSystemValuesB
|
|
|
|
INSERT_UNION_PADDING_BYTES(16); // ImapGenericVector[32]
|
|
|
|
INSERT_UNION_PADDING_BYTES(2); // ImapColor
|
2018-11-23 05:57:49 +01:00
|
|
|
union {
|
|
|
|
BitField<0, 8, u16> clip_distances;
|
|
|
|
BitField<8, 1, u16> point_sprite_s;
|
|
|
|
BitField<9, 1, u16> point_sprite_t;
|
|
|
|
BitField<10, 1, u16> fog_coordinate;
|
|
|
|
BitField<12, 1, u16> tessellation_eval_point_u;
|
|
|
|
BitField<13, 1, u16> tessellation_eval_point_v;
|
|
|
|
BitField<14, 1, u16> instance_id;
|
|
|
|
BitField<15, 1, u16> vertex_id;
|
|
|
|
};
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_BYTES(5); // ImapFixedFncTexture[10]
|
|
|
|
INSERT_UNION_PADDING_BYTES(1); // ImapReserved
|
|
|
|
INSERT_UNION_PADDING_BYTES(3); // OmapSystemValuesA
|
|
|
|
INSERT_UNION_PADDING_BYTES(1); // OmapSystemValuesB
|
|
|
|
INSERT_UNION_PADDING_BYTES(16); // OmapGenericVector[32]
|
|
|
|
INSERT_UNION_PADDING_BYTES(2); // OmapColor
|
|
|
|
INSERT_UNION_PADDING_BYTES(2); // OmapSystemValuesC
|
|
|
|
INSERT_UNION_PADDING_BYTES(5); // OmapFixedFncTexture[10]
|
|
|
|
INSERT_UNION_PADDING_BYTES(1); // OmapReserved
|
2018-09-11 18:08:06 +02:00
|
|
|
} vtg;
|
2018-09-11 03:00:55 +02:00
|
|
|
|
|
|
|
struct {
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_BYTES(3); // ImapSystemValuesA
|
|
|
|
INSERT_UNION_PADDING_BYTES(1); // ImapSystemValuesB
|
2020-04-02 02:37:32 +02:00
|
|
|
|
2019-02-13 02:14:39 +01:00
|
|
|
union {
|
2020-04-02 02:37:32 +02:00
|
|
|
BitField<0, 2, PixelImap> x;
|
|
|
|
BitField<2, 2, PixelImap> y;
|
|
|
|
BitField<4, 2, PixelImap> z;
|
|
|
|
BitField<6, 2, PixelImap> w;
|
2019-02-13 02:14:39 +01:00
|
|
|
u8 raw;
|
|
|
|
} imap_generic_vector[32];
|
2020-04-02 02:37:32 +02:00
|
|
|
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_BYTES(2); // ImapColor
|
|
|
|
INSERT_UNION_PADDING_BYTES(2); // ImapSystemValuesC
|
|
|
|
INSERT_UNION_PADDING_BYTES(10); // ImapFixedFncTexture[10]
|
|
|
|
INSERT_UNION_PADDING_BYTES(2); // ImapReserved
|
2020-04-02 02:37:32 +02:00
|
|
|
|
2018-09-11 18:08:06 +02:00
|
|
|
struct {
|
|
|
|
u32 target;
|
|
|
|
union {
|
|
|
|
BitField<0, 1, u32> sample_mask;
|
|
|
|
BitField<1, 1, u32> depth;
|
|
|
|
BitField<2, 30, u32> reserved;
|
|
|
|
};
|
2018-09-11 03:00:55 +02:00
|
|
|
} omap;
|
2020-04-02 02:37:32 +02:00
|
|
|
|
2018-09-11 18:08:06 +02:00
|
|
|
bool IsColorComponentOutputEnabled(u32 render_target, u32 component) const {
|
|
|
|
const u32 bit = render_target * 4 + component;
|
|
|
|
return omap.target & (1 << bit);
|
|
|
|
}
|
2020-04-02 02:37:32 +02:00
|
|
|
|
|
|
|
PixelImap GetPixelImap(u32 attribute) const {
|
|
|
|
const auto get_index = [this, attribute](u32 index) {
|
|
|
|
return static_cast<PixelImap>(
|
|
|
|
(imap_generic_vector[attribute].raw >> (index * 2)) & 3);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::optional<PixelImap> result;
|
|
|
|
for (u32 component = 0; component < 4; ++component) {
|
|
|
|
const PixelImap index = get_index(component);
|
|
|
|
if (index == PixelImap::Unused) {
|
2019-02-13 02:14:39 +01:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-02 02:37:32 +02:00
|
|
|
if (result && result != index) {
|
|
|
|
LOG_CRITICAL(HW_GPU, "Generic attribute conflict in interpolation mode");
|
2019-02-13 02:14:39 +01:00
|
|
|
}
|
2020-04-02 02:37:32 +02:00
|
|
|
result = index;
|
2019-02-13 02:14:39 +01:00
|
|
|
}
|
2020-04-02 02:37:32 +02:00
|
|
|
return result.value_or(PixelImap::Unused);
|
2019-02-13 02:14:39 +01:00
|
|
|
}
|
2018-09-11 18:08:06 +02:00
|
|
|
} ps;
|
2019-11-04 00:54:03 +01:00
|
|
|
|
|
|
|
std::array<u32, 0xF> raw{};
|
2018-09-11 18:08:06 +02:00
|
|
|
};
|
2018-10-20 03:48:21 +02:00
|
|
|
|
2018-12-19 00:39:49 +01:00
|
|
|
u64 GetLocalMemorySize() const {
|
2018-10-20 03:48:21 +02:00
|
|
|
return (common1.shader_local_memory_low_size |
|
|
|
|
(common2.shader_local_memory_high_size << 24));
|
|
|
|
}
|
2018-09-11 03:00:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(Header) == 0x50, "Incorrect structure size");
|
|
|
|
|
|
|
|
} // namespace Tegra::Shader
|