2021-05-20 04:58:32 +03:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "shader_recompiler/backend/bindings.h"
|
|
|
|
#include "shader_recompiler/backend/glsl/emit_context.h"
|
|
|
|
#include "shader_recompiler/frontend/ir/program.h"
|
|
|
|
|
|
|
|
namespace Shader::Backend::GLSL {
|
|
|
|
|
|
|
|
EmitContext::EmitContext(IR::Program& program, [[maybe_unused]] Bindings& bindings,
|
|
|
|
const Profile& profile_)
|
|
|
|
: info{program.info}, profile{profile_} {
|
2021-05-21 06:38:38 +03:00
|
|
|
std::string header = "#version 450\n";
|
|
|
|
if (program.stage == Stage::Compute) {
|
|
|
|
header += fmt::format("layout(local_size_x={},local_size_y={},local_size_z={}) in;\n",
|
|
|
|
program.workgroup_size[0], program.workgroup_size[1],
|
|
|
|
program.workgroup_size[2]);
|
|
|
|
}
|
2021-05-20 04:58:32 +03:00
|
|
|
code += header;
|
|
|
|
DefineConstantBuffers();
|
2021-05-21 06:38:38 +03:00
|
|
|
DefineStorageBuffers();
|
|
|
|
code += "void main(){\n";
|
2021-05-20 04:58:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmitContext::DefineConstantBuffers() {
|
|
|
|
if (info.constant_buffer_descriptors.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-21 06:38:38 +03:00
|
|
|
u32 binding{};
|
2021-05-20 04:58:32 +03:00
|
|
|
for (const auto& desc : info.constant_buffer_descriptors) {
|
2021-05-21 08:12:58 +03:00
|
|
|
Add("layout(std140,binding={}) uniform cbuf_{}{{vec4 cbuf{}[{}];}};", binding, binding,
|
|
|
|
desc.index, 4 * 1024);
|
2021-05-21 06:38:38 +03:00
|
|
|
++binding;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmitContext::DefineStorageBuffers() {
|
|
|
|
if (info.storage_buffers_descriptors.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
u32 binding{};
|
|
|
|
for (const auto& desc : info.storage_buffers_descriptors) {
|
|
|
|
Add("layout(std430,binding={}) buffer buff_{}{{uint buff{}[];}};", binding, binding,
|
|
|
|
desc.cbuf_index, desc.count);
|
|
|
|
++binding;
|
2021-05-20 04:58:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Shader::Backend::GLSL
|