|
|
|
@ -248,6 +248,10 @@ namespace {
|
|
|
|
|
using Shader::Backend::SPIRV::EmitSPIRV;
|
|
|
|
|
using Shader::Maxwell::TranslateProgram;
|
|
|
|
|
|
|
|
|
|
// TODO: Move this to a separate file
|
|
|
|
|
constexpr std::array<char, 8> MAGIC_NUMBER{'y', 'u', 'z', 'u', 'c', 'a', 'c', 'h'};
|
|
|
|
|
constexpr u32 CACHE_VERSION{1};
|
|
|
|
|
|
|
|
|
|
class GraphicsEnvironment final : public GenericEnvironment {
|
|
|
|
|
public:
|
|
|
|
|
explicit GraphicsEnvironment() = default;
|
|
|
|
@ -379,13 +383,14 @@ void SerializePipeline(const Key& key, const Envs& envs, const std::string& file
|
|
|
|
|
try {
|
|
|
|
|
std::ofstream file;
|
|
|
|
|
file.exceptions(std::ifstream::failbit);
|
|
|
|
|
Common::FS::OpenFStream(file, filename, std::ios::binary | std::ios::app);
|
|
|
|
|
Common::FS::OpenFStream(file, filename, std::ios::binary | std::ios::ate | std::ios::app);
|
|
|
|
|
if (!file.is_open()) {
|
|
|
|
|
LOG_ERROR(Common_Filesystem, "Failed to open pipeline cache file {}", filename);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (file.tellp() == 0) {
|
|
|
|
|
// Write header...
|
|
|
|
|
file.write(MAGIC_NUMBER.data(), MAGIC_NUMBER.size())
|
|
|
|
|
.write(reinterpret_cast<const char*>(&CACHE_VERSION), sizeof(CACHE_VERSION));
|
|
|
|
|
}
|
|
|
|
|
const std::span key_span(reinterpret_cast<const char*>(&key), sizeof(key));
|
|
|
|
|
SerializePipeline(key_span, MakeSpan(envs), file);
|
|
|
|
@ -520,8 +525,27 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading
|
|
|
|
|
file.exceptions(std::ifstream::failbit);
|
|
|
|
|
const auto end{file.tellg()};
|
|
|
|
|
file.seekg(0, std::ios::beg);
|
|
|
|
|
// Read header...
|
|
|
|
|
|
|
|
|
|
std::array<char, 8> magic_number;
|
|
|
|
|
u32 cache_version;
|
|
|
|
|
file.read(magic_number.data(), magic_number.size())
|
|
|
|
|
.read(reinterpret_cast<char*>(&cache_version), sizeof(cache_version));
|
|
|
|
|
if (magic_number != MAGIC_NUMBER || cache_version != CACHE_VERSION) {
|
|
|
|
|
file.close();
|
|
|
|
|
if (Common::FS::Delete(pipeline_cache_filename)) {
|
|
|
|
|
if (magic_number != MAGIC_NUMBER) {
|
|
|
|
|
LOG_ERROR(Render_Vulkan, "Invalid pipeline cache file");
|
|
|
|
|
}
|
|
|
|
|
if (cache_version != CACHE_VERSION) {
|
|
|
|
|
LOG_INFO(Render_Vulkan, "Deleting old pipeline cache");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LOG_ERROR(Render_Vulkan,
|
|
|
|
|
"Invalid pipeline cache file and failed to delete it in \"{}\"",
|
|
|
|
|
pipeline_cache_filename);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while (file.tellg() != end) {
|
|
|
|
|
if (stop_loading) {
|
|
|
|
|
return;
|
|
|
|
@ -879,6 +903,88 @@ static Shader::AttributeType CastAttributeType(const FixedPipelineState::VertexA
|
|
|
|
|
return Shader::AttributeType::Float;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::vector<Shader::TransformFeedbackVarying> MakeTransformFeedbackVaryings(
|
|
|
|
|
const GraphicsPipelineCacheKey& key) {
|
|
|
|
|
static constexpr std::array VECTORS{
|
|
|
|
|
28, // gl_Position
|
|
|
|
|
32, // Generic 0
|
|
|
|
|
36, // Generic 1
|
|
|
|
|
40, // Generic 2
|
|
|
|
|
44, // Generic 3
|
|
|
|
|
48, // Generic 4
|
|
|
|
|
52, // Generic 5
|
|
|
|
|
56, // Generic 6
|
|
|
|
|
60, // Generic 7
|
|
|
|
|
64, // Generic 8
|
|
|
|
|
68, // Generic 9
|
|
|
|
|
72, // Generic 10
|
|
|
|
|
76, // Generic 11
|
|
|
|
|
80, // Generic 12
|
|
|
|
|
84, // Generic 13
|
|
|
|
|
88, // Generic 14
|
|
|
|
|
92, // Generic 15
|
|
|
|
|
96, // Generic 16
|
|
|
|
|
100, // Generic 17
|
|
|
|
|
104, // Generic 18
|
|
|
|
|
108, // Generic 19
|
|
|
|
|
112, // Generic 20
|
|
|
|
|
116, // Generic 21
|
|
|
|
|
120, // Generic 22
|
|
|
|
|
124, // Generic 23
|
|
|
|
|
128, // Generic 24
|
|
|
|
|
132, // Generic 25
|
|
|
|
|
136, // Generic 26
|
|
|
|
|
140, // Generic 27
|
|
|
|
|
144, // Generic 28
|
|
|
|
|
148, // Generic 29
|
|
|
|
|
152, // Generic 30
|
|
|
|
|
156, // Generic 31
|
|
|
|
|
160, // gl_FrontColor
|
|
|
|
|
164, // gl_FrontSecondaryColor
|
|
|
|
|
160, // gl_BackColor
|
|
|
|
|
164, // gl_BackSecondaryColor
|
|
|
|
|
192, // gl_TexCoord[0]
|
|
|
|
|
196, // gl_TexCoord[1]
|
|
|
|
|
200, // gl_TexCoord[2]
|
|
|
|
|
204, // gl_TexCoord[3]
|
|
|
|
|
208, // gl_TexCoord[4]
|
|
|
|
|
212, // gl_TexCoord[5]
|
|
|
|
|
216, // gl_TexCoord[6]
|
|
|
|
|
220, // gl_TexCoord[7]
|
|
|
|
|
};
|
|
|
|
|
std::vector<Shader::TransformFeedbackVarying> xfb(256);
|
|
|
|
|
for (size_t buffer = 0; buffer < Maxwell::NumTransformFeedbackBuffers; ++buffer) {
|
|
|
|
|
const auto& locations = key.state.xfb_state.varyings[buffer];
|
|
|
|
|
const auto& layout = key.state.xfb_state.layouts[buffer];
|
|
|
|
|
const u32 varying_count = layout.varying_count;
|
|
|
|
|
u32 highest = 0;
|
|
|
|
|
for (u32 offset = 0; offset < varying_count; ++offset) {
|
|
|
|
|
const u32 base_offset = offset;
|
|
|
|
|
const u8 location = locations[offset];
|
|
|
|
|
|
|
|
|
|
Shader::TransformFeedbackVarying varying;
|
|
|
|
|
varying.buffer = layout.stream;
|
|
|
|
|
varying.stride = layout.stride;
|
|
|
|
|
varying.offset = offset * 4;
|
|
|
|
|
varying.components = 1;
|
|
|
|
|
|
|
|
|
|
if (std::ranges::find(VECTORS, Common::AlignDown(location, 4)) != VECTORS.end()) {
|
|
|
|
|
UNIMPLEMENTED_IF_MSG(location % 4 != 0, "Unaligned TFB");
|
|
|
|
|
|
|
|
|
|
const u8 base_index = location / 4;
|
|
|
|
|
while (offset + 1 < varying_count && base_index == locations[offset + 1] / 4) {
|
|
|
|
|
++offset;
|
|
|
|
|
++varying.components;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
xfb[location] = varying;
|
|
|
|
|
highest = std::max(highest, (base_offset + varying.components) * 4);
|
|
|
|
|
}
|
|
|
|
|
UNIMPLEMENTED_IF(highest != layout.stride);
|
|
|
|
|
}
|
|
|
|
|
return xfb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Shader::Profile PipelineCache::MakeProfile(const GraphicsPipelineCacheKey& key,
|
|
|
|
|
const Shader::IR::Program& program) {
|
|
|
|
|
Shader::Profile profile{base_profile};
|
|
|
|
@ -893,6 +999,9 @@ Shader::Profile PipelineCache::MakeProfile(const GraphicsPipelineCacheKey& key,
|
|
|
|
|
if (key.state.topology == Maxwell::PrimitiveTopology::Points) {
|
|
|
|
|
profile.fixed_state_point_size = point_size;
|
|
|
|
|
}
|
|
|
|
|
if (key.state.xfb_enabled != 0) {
|
|
|
|
|
profile.xfb_varyings = MakeTransformFeedbackVaryings(key);
|
|
|
|
|
}
|
|
|
|
|
profile.convert_depth_mode = gl_ndc;
|
|
|
|
|
}
|
|
|
|
|
std::ranges::transform(key.state.attributes, profile.generic_input_types.begin(),
|
|
|
|
@ -902,6 +1011,9 @@ Shader::Profile PipelineCache::MakeProfile(const GraphicsPipelineCacheKey& key,
|
|
|
|
|
if (program.output_topology == Shader::OutputTopology::PointList) {
|
|
|
|
|
profile.fixed_state_point_size = point_size;
|
|
|
|
|
}
|
|
|
|
|
if (key.state.xfb_enabled != 0) {
|
|
|
|
|
profile.xfb_varyings = MakeTransformFeedbackVaryings(key);
|
|
|
|
|
}
|
|
|
|
|
profile.convert_depth_mode = gl_ndc;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|