Compare commits

..

3 Commits

Author SHA1 Message Date
Levi Behunin
9b6739a36b Refactor Logging Impl
Loop on stop_token and remove final_entry in Entry.
Move Backend thread out of Impl Constructor to its own function.
Add Start function for backend thread.
Use stop token in PopWait and check if entry filename is nullptr before logging.
2021-10-30 16:43:45 -06:00
Fernando S
7aa0d97eed Merge pull request #7201 from ameerj/spirv-depth-sampling
emit_spirv_image: Fix depth image implicit lod sample in non-fragment stages
2021-10-30 16:45:58 +02:00
ameerj
06894b0711 emit_spirv_image: Fix depth image implicit lod sample in compute
Ensures all drivers behave the same way in this case.
2021-10-17 17:09:11 -04:00
13 changed files with 61 additions and 101 deletions

1
externals/FidelityFX-FSR vendored Submodule

Submodule externals/FidelityFX-FSR added at bcffc8171e

View File

@@ -6,6 +6,7 @@
#include <chrono>
#include <climits>
#include <exception>
#include <stop_token>
#include <thread>
#include <vector>
@@ -186,6 +187,10 @@ public:
initialization_in_progress_suppress_logging = false;
}
static void Start() {
instance->StartBackendThread();
}
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
@@ -201,7 +206,7 @@ public:
}
void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num,
const char* function, std::string message) {
const char* function, std::string&& message) {
if (!filter.CheckMessage(log_class, log_level))
return;
const Entry& entry =
@@ -211,40 +216,41 @@ public:
private:
Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_)
: filter{filter_}, file_backend{file_backend_filename}, backend_thread{std::thread([this] {
Common::SetCurrentThreadName("yuzu:Log");
Entry entry;
const auto write_logs = [this, &entry]() {
ForEachBackend([&entry](Backend& backend) { backend.Write(entry); });
};
while (true) {
entry = message_queue.PopWait();
if (entry.final_entry) {
break;
}
write_logs();
}
// Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
// case where a system is repeatedly spamming logs even on close.
int max_logs_to_write = filter.IsDebug() ? INT_MAX : 100;
while (max_logs_to_write-- && message_queue.Pop(entry)) {
write_logs();
}
})} {}
: filter{filter_}, file_backend{file_backend_filename} {}
~Impl() {
StopBackendThread();
}
void StartBackendThread() {
backend_thread = std::thread([this] {
Common::SetCurrentThreadName("yuzu:Log");
Entry entry;
const auto write_logs = [this, &entry]() {
ForEachBackend([&entry](Backend& backend) { backend.Write(entry); });
};
while (!stop.stop_requested()) {
entry = message_queue.PopWait(stop.get_token());
if (entry.filename != nullptr) {
write_logs();
}
}
// Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
// case where a system is repeatedly spamming logs even on close.
int max_logs_to_write = filter.IsDebug() ? INT_MAX : 100;
while (max_logs_to_write-- && message_queue.Pop(entry)) {
write_logs();
}
});
}
void StopBackendThread() {
Entry stop_entry{};
stop_entry.final_entry = true;
message_queue.Push(stop_entry);
stop.request_stop();
backend_thread.join();
}
Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
const char* function, std::string message) const {
const char* function, std::string&& message) const {
using std::chrono::duration_cast;
using std::chrono::microseconds;
using std::chrono::steady_clock;
@@ -257,7 +263,6 @@ private:
.line_num = line_nr,
.function = function,
.message = std::move(message),
.final_entry = false,
};
}
@@ -278,8 +283,9 @@ private:
ColorConsoleBackend color_console_backend{};
FileBackend file_backend;
std::stop_source stop;
std::thread backend_thread;
MPSCQueue<Entry> message_queue{};
MPSCQueue<Entry, true> message_queue{};
std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
};
} // namespace
@@ -288,6 +294,10 @@ void Initialize() {
Impl::Initialize();
}
void Start() {
Impl::Start();
}
void DisableLoggingInTests() {
initialization_in_progress_suppress_logging = true;
}

View File

@@ -14,6 +14,8 @@ class Filter;
/// Initializes the logging system. This should be the first thing called in main.
void Initialize();
void Start();
void DisableLoggingInTests();
/**

View File

@@ -22,7 +22,6 @@ struct Entry {
unsigned int line_num = 0;
std::string function;
std::string message;
bool final_entry = false;
};
} // namespace Common::Log

View File

@@ -18,7 +18,7 @@ namespace Shader::Backend::GLASM {
#define NotImplemented() throw NotImplementedException("GLASM instruction {}", __LINE__)
static void DefinePhi(EmitContext& ctx, IR::Inst& phi) {
switch (phi.Type()) {
switch (phi.Arg(0).Type()) {
case IR::Type::U1:
case IR::Type::U32:
case IR::Type::F32:

View File

@@ -68,7 +68,7 @@ void EmitPhi(EmitContext& ctx, IR::Inst& phi) {
}
if (!phi.Definition<Id>().is_valid) {
// The phi node wasn't forward defined
ctx.var_alloc.PhiDefine(phi, phi.Type());
ctx.var_alloc.PhiDefine(phi, phi.Arg(0).Type());
}
}
@@ -80,7 +80,7 @@ void EmitReference(EmitContext& ctx, const IR::Value& value) {
void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& value) {
IR::Inst& phi{*phi_value.InstRecursive()};
const auto phi_type{phi.Type()};
const auto phi_type{phi.Arg(0).Type()};
if (!phi.Definition<Id>().is_valid) {
// The phi node wasn't forward defined
ctx.var_alloc.PhiDefine(phi, phi_type);

View File

@@ -355,11 +355,22 @@ Id EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value&
Id EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
Id coords, Id dref, Id bias_lc, const IR::Value& offset) {
const auto info{inst->Flags<IR::TextureInstInfo>()};
const ImageOperands operands(ctx, info.has_bias != 0, false, info.has_lod_clamp != 0, bias_lc,
offset);
return Emit(&EmitContext::OpImageSparseSampleDrefImplicitLod,
&EmitContext::OpImageSampleDrefImplicitLod, ctx, inst, ctx.F32[1],
Texture(ctx, info, index), coords, dref, operands.MaskOptional(), operands.Span());
if (ctx.stage == Stage::Fragment) {
const ImageOperands operands(ctx, info.has_bias != 0, false, info.has_lod_clamp != 0,
bias_lc, offset);
return Emit(&EmitContext::OpImageSparseSampleDrefImplicitLod,
&EmitContext::OpImageSampleDrefImplicitLod, ctx, inst, ctx.F32[1],
Texture(ctx, info, index), coords, dref, operands.MaskOptional(),
operands.Span());
} else {
// Implicit lods in compute behave on hardware as if sampling from LOD 0.
// This check is to ensure all drivers behave this way.
const Id lod{ctx.Const(0.0f)};
const ImageOperands operands(ctx, false, true, false, lod, offset);
return Emit(&EmitContext::OpImageSparseSampleDrefExplicitLod,
&EmitContext::OpImageSampleDrefExplicitLod, ctx, inst, ctx.F32[1],
Texture(ctx, info, index), coords, dref, operands.Mask(), operands.Span());
}
}
Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,

View File

@@ -152,17 +152,6 @@ public:
return instructions.crend();
}
// Set the order of the block, it can be set pre order, the user decides
void SetOrder(u32 new_order) {
order = new_order;
}
// Get the order of the block.
// The higher, the closer is the block to the end.
[[nodiscard]] u32 GetOrder() const {
return order;
}
private:
/// Memory pool for instruction list
ObjectPool<Inst>* inst_pool;
@@ -182,9 +171,6 @@ private:
/// Intrusively stored host definition of this block.
u32 definition{};
/// Order of the block.
u32 order{};
};
using BlockList = std::vector<Block*>;

View File

@@ -6,7 +6,6 @@
#include <memory>
#include "shader_recompiler/exception.h"
#include "shader_recompiler/frontend/ir/basic_block.h"
#include "shader_recompiler/frontend/ir/type.h"
#include "shader_recompiler/frontend/ir/value.h"
@@ -254,10 +253,6 @@ Inst* Inst::GetAssociatedPseudoOperation(IR::Opcode opcode) {
}
IR::Type Inst::Type() const {
if (op == IR::Opcode::Phi) {
// The type of a phi node is stored in its flags
return Flags<IR::Type>();
}
return TypeOf(op);
}
@@ -296,16 +291,6 @@ void Inst::AddPhiOperand(Block* predecessor, const Value& value) {
phi_args.emplace_back(predecessor, value);
}
void Inst::OrderPhiArgs() {
if (op != Opcode::Phi) {
throw LogicError("{} is not a Phi instruction", op);
}
std::sort(phi_args.begin(), phi_args.end(),
[](const std::pair<Block*, Value>& a, const std::pair<Block*, Value>& b) {
return a.first->GetOrder() < b.first->GetOrder();
});
}
void Inst::Invalidate() {
ClearArgs();
ReplaceOpcode(Opcode::Void);

View File

@@ -182,9 +182,6 @@ public:
/// Add phi operand to a phi instruction.
void AddPhiOperand(Block* predecessor, const Value& value);
/// Orders the Phi arguments from farthest away to nearest.
void OrderPhiArgs();
void Invalidate();
void ClearArgs();

View File

@@ -27,11 +27,9 @@ IR::BlockList GenerateBlocks(const IR::AbstractSyntaxList& syntax_list) {
}
IR::BlockList blocks;
blocks.reserve(num_syntax_blocks);
u32 order_index{};
for (const auto& node : syntax_list) {
if (node.type == IR::AbstractSyntaxNode::Type::Block) {
blocks.push_back(node.data.block);
blocks.back()->SetOrder(order_index++);
}
}
return blocks;

View File

@@ -14,7 +14,6 @@
// https://link.springer.com/chapter/10.1007/978-3-642-37051-9_6
//
#include <deque>
#include <span>
#include <variant>
#include <vector>
@@ -371,26 +370,6 @@ void VisitBlock(Pass& pass, IR::Block* block) {
}
pass.SealBlock(block);
}
IR::Type GetConcreteType(IR::Inst* inst) {
std::deque<IR::Inst*> queue;
queue.push_back(inst);
while (!queue.empty()) {
IR::Inst* current = queue.front();
queue.pop_front();
const size_t num_args{current->NumArgs()};
for (size_t i = 0; i < num_args; ++i) {
const auto set_type = current->Arg(i).Type();
if (set_type != IR::Type::Opaque) {
return set_type;
}
if (!current->Arg(i).IsImmediate()) {
queue.push_back(current->Arg(i).Inst());
}
}
}
return IR::Type::Opaque;
}
} // Anonymous namespace
void SsaRewritePass(IR::Program& program) {
@@ -399,16 +378,6 @@ void SsaRewritePass(IR::Program& program) {
for (auto block = program.post_order_blocks.rbegin(); block != end; ++block) {
VisitBlock(pass, *block);
}
for (auto block = program.post_order_blocks.rbegin(); block != end; ++block) {
for (IR::Inst& inst : (*block)->Instructions()) {
if (inst.GetOpcode() == IR::Opcode::Phi) {
if (inst.Type() == IR::Type::Opaque) {
inst.SetFlags(GetConcreteType(&inst));
}
inst.OrderPhiArgs();
}
}
}
}
} // namespace Shader::Optimization

View File

@@ -299,6 +299,8 @@ GMainWindow::GMainWindow()
SDL_EnableScreenSaver();
#endif
Common::Log::Start();
QStringList args = QApplication::arguments();
if (args.size() < 2) {