yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

glsl: Implement ST{LS}

This commit is contained in:
ameerj 2021-05-29 23:31:58 -04:00
parent 57d354b02c
commit 181a4ffdc4
6 changed files with 106 additions and 69 deletions

View File

@ -118,11 +118,6 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
DefineStorageBuffers(bindings); DefineStorageBuffers(bindings);
SetupImages(bindings); SetupImages(bindings);
DefineHelperFunctions(); DefineHelperFunctions();
header += "void main(){\n";
if (stage == Stage::VertexA || stage == Stage::VertexB) {
Add("gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);");
}
} }
void EmitContext::SetupExtensions(std::string&) { void EmitContext::SetupExtensions(std::string&) {

View File

@ -180,6 +180,16 @@ std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR
EmitCode(ctx, program); EmitCode(ctx, program);
const std::string version{fmt::format("#version 450{}\n", GlslVersionSpecifier(ctx))}; const std::string version{fmt::format("#version 450{}\n", GlslVersionSpecifier(ctx))};
ctx.header.insert(0, version); ctx.header.insert(0, version);
if (program.local_memory_size > 0) {
ctx.header += fmt::format("uint lmem[{}];", program.local_memory_size / 4);
}
if (program.shared_memory_size > 0) {
ctx.header += fmt::format("shared uint smem[{}];", program.shared_memory_size / 4);
}
ctx.header += "void main(){\n";
if (program.stage == Stage::VertexA || program.stage == Stage::VertexB) {
ctx.header += "gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);";
}
for (size_t index = 0; index < ctx.reg_alloc.num_used_registers; ++index) { for (size_t index = 0; index < ctx.reg_alloc.num_used_registers; ++index) {
ctx.header += fmt::format("{} R{};", ctx.reg_alloc.reg_types[index], index); ctx.header += fmt::format("{} R{};", ctx.reg_alloc.reg_types[index], index);
} }

View File

@ -201,4 +201,12 @@ void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst) {
ctx.AddU32x3("{}=gl_LocalInvocationID;", inst); ctx.AddU32x3("{}=gl_LocalInvocationID;", inst);
} }
void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset) {
ctx.AddU32("{}=lmem[{}];", inst, word_offset);
}
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value) {
ctx.Add("lmem[{}]={};", word_offset, value);
}
} // namespace Shader::Backend::GLSL } // namespace Shader::Backend::GLSL

View File

@ -92,7 +92,7 @@ void EmitInvocationId(EmitContext& ctx, IR::Inst& inst);
void EmitSampleId(EmitContext& ctx, IR::Inst& inst); void EmitSampleId(EmitContext& ctx, IR::Inst& inst);
void EmitIsHelperInvocation(EmitContext& ctx); void EmitIsHelperInvocation(EmitContext& ctx);
void EmitYDirection(EmitContext& ctx, IR::Inst& inst); void EmitYDirection(EmitContext& ctx, IR::Inst& inst);
void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset); void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset);
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value); void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value);
void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); void EmitUndefU1(EmitContext& ctx, IR::Inst& inst);
void EmitUndefU8(EmitContext& ctx, IR::Inst& inst); void EmitUndefU8(EmitContext& ctx, IR::Inst& inst);
@ -141,13 +141,13 @@ void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Va
std::string_view value); std::string_view value);
void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
std::string_view value); std::string_view value);
void EmitLoadSharedU8(EmitContext& ctx, std::string_view offset); void EmitLoadSharedU8(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
void EmitLoadSharedS8(EmitContext& ctx, std::string_view offset); void EmitLoadSharedS8(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
void EmitLoadSharedU16(EmitContext& ctx, std::string_view offset); void EmitLoadSharedU16(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
void EmitLoadSharedS16(EmitContext& ctx, std::string_view offset); void EmitLoadSharedS16(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
void EmitLoadSharedU32(EmitContext& ctx, std::string_view offset); void EmitLoadSharedU32(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
void EmitLoadSharedU64(EmitContext& ctx, std::string_view offset); void EmitLoadSharedU64(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
void EmitLoadSharedU128(EmitContext& ctx, std::string_view offset); void EmitLoadSharedU128(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
void EmitWriteSharedU8(EmitContext& ctx, std::string_view offset, std::string_view value); void EmitWriteSharedU8(EmitContext& ctx, std::string_view offset, std::string_view value);
void EmitWriteSharedU16(EmitContext& ctx, std::string_view offset, std::string_view value); void EmitWriteSharedU16(EmitContext& ctx, std::string_view offset, std::string_view value);
void EmitWriteSharedU32(EmitContext& ctx, std::string_view offset, std::string_view value); void EmitWriteSharedU32(EmitContext& ctx, std::string_view offset, std::string_view value);

View File

@ -224,14 +224,6 @@ void EmitYDirection(EmitContext& ctx, IR::Inst& inst) {
ctx.AddF32("{}=gl_FrontMaterial.ambient.a;", inst); ctx.AddF32("{}=gl_FrontMaterial.ambient.a;", inst);
} }
void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset) {
NotImplemented();
}
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value) {
NotImplemented();
}
void EmitUndefU1(EmitContext& ctx, IR::Inst& inst) { void EmitUndefU1(EmitContext& ctx, IR::Inst& inst) {
ctx.AddU1("{}=false;", inst); ctx.AddU1("{}=false;", inst);
} }
@ -308,54 +300,6 @@ void EmitWriteGlobal128(EmitContext& ctx, std::string_view address, std::string_
NotImplemented(); NotImplemented();
} }
void EmitLoadSharedU8(EmitContext& ctx, std::string_view offset) {
NotImplemented();
}
void EmitLoadSharedS8(EmitContext& ctx, std::string_view offset) {
NotImplemented();
}
void EmitLoadSharedU16(EmitContext& ctx, std::string_view offset) {
NotImplemented();
}
void EmitLoadSharedS16(EmitContext& ctx, std::string_view offset) {
NotImplemented();
}
void EmitLoadSharedU32(EmitContext& ctx, std::string_view offset) {
NotImplemented();
}
void EmitLoadSharedU64(EmitContext& ctx, std::string_view offset) {
NotImplemented();
}
void EmitLoadSharedU128(EmitContext& ctx, std::string_view offset) {
NotImplemented();
}
void EmitWriteSharedU8(EmitContext& ctx, std::string_view offset, std::string_view value) {
NotImplemented();
}
void EmitWriteSharedU16(EmitContext& ctx, std::string_view offset, std::string_view value) {
NotImplemented();
}
void EmitWriteSharedU32(EmitContext& ctx, std::string_view offset, std::string_view value) {
NotImplemented();
}
void EmitWriteSharedU64(EmitContext& ctx, std::string_view offset, std::string_view value) {
NotImplemented();
}
void EmitWriteSharedU128(EmitContext& ctx, std::string_view offset, std::string_view value) {
NotImplemented();
}
void EmitGetZeroFromOp(EmitContext& ctx) { void EmitGetZeroFromOp(EmitContext& ctx) {
NotImplemented(); NotImplemented();
} }

View File

@ -0,0 +1,80 @@
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <string_view>
#include "shader_recompiler/backend/glsl/emit_context.h"
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
#include "shader_recompiler/frontend/ir/value.h"
namespace Shader::Backend::GLSL {
void EmitLoadSharedU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view offset) {
ctx.AddU32("{}=bitfieldExtract(smem[{}/4],int({}%4)*8,8);", inst, offset, offset);
}
void EmitLoadSharedS8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view offset) {
ctx.AddS32("{}=bitfieldExtract(int(smem[{}/4]),int({}%4)*8,8);", inst, offset, offset);
}
void EmitLoadSharedU16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view offset) {
ctx.AddU32("{}=bitfieldExtract(smem[{}/4],int(({}/2)%2)*16,16);", inst, offset, offset);
}
void EmitLoadSharedS16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view offset) {
ctx.AddS32("{}=bitfieldExtract(int(smem[{}/4]),int(({}/2)%2)*16,16);", inst, offset, offset);
}
void EmitLoadSharedU32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view offset) {
ctx.AddU32("{}=smem[{}/4];", inst, offset);
}
void EmitLoadSharedU64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view offset) {
ctx.AddU32x2("{}=uvec2(smem[{}/4],smem[({}+4)/4]);", inst, offset, offset);
}
void EmitLoadSharedU128([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view offset) {
ctx.AddU32x4("{}=uvec4(smem[{}/4],smem[({}+4)/4],smem[({}+8)/4],smem[({}+12)/4]);", inst,
offset, offset, offset, offset);
}
void EmitWriteSharedU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view value) {
ctx.Add("smem[{}/4]=bitfieldInsert(smem[{}/4],{},int({}%4)*8,8);", offset, offset, value,
offset);
}
void EmitWriteSharedU16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view value) {
ctx.Add("smem[{}/4]=bitfieldInsert(smem[{}/4],{},int(({}/2)%2)*16,16);", offset, offset, value,
offset);
}
void EmitWriteSharedU32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view value) {
ctx.Add("smem[{}/4]={};", offset, value);
}
void EmitWriteSharedU64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view value) {
ctx.Add("smem[{}/4]={}.x;", offset, value);
ctx.Add("smem[({}+4)/4]={}.y;", offset, value);
}
void EmitWriteSharedU128([[maybe_unused]] EmitContext& ctx,
[[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view value) {
ctx.Add("smem[{}/4]={}.x;", offset, value);
ctx.Add("smem[({}+4)/4]={}.y;", offset, value);
ctx.Add("smem[({}+8)/4]={}.z;", offset, value);
ctx.Add("smem[({}+12)/4]={}.w;", offset, value);
}
} // namespace Shader::Backend::GLSL