forked from suyu/suyu
glsl: Implement derivatives and YDirection
plus some other misc additions/changed
This commit is contained in:
parent
ed14d31f66
commit
a752ec88d0
8 changed files with 87 additions and 81 deletions
|
@ -22,9 +22,10 @@ std::string_view InterpDecorator(Interpolation interp) {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_)
|
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
||||||
: info{program.info}, profile{profile_} {
|
const RuntimeInfo& runtime_info_)
|
||||||
std::string header = "#version 450\n";
|
: info{program.info}, profile{profile_}, runtime_info{runtime_info_} {
|
||||||
|
std::string header = "";
|
||||||
SetupExtensions(header);
|
SetupExtensions(header);
|
||||||
stage = program.stage;
|
stage = program.stage;
|
||||||
switch (program.stage) {
|
switch (program.stage) {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
namespace Shader {
|
namespace Shader {
|
||||||
struct Info;
|
struct Info;
|
||||||
struct Profile;
|
struct Profile;
|
||||||
|
struct RuntimeInfo;
|
||||||
} // namespace Shader
|
} // namespace Shader
|
||||||
|
|
||||||
namespace Shader::Backend {
|
namespace Shader::Backend {
|
||||||
|
@ -31,7 +32,8 @@ namespace Shader::Backend::GLSL {
|
||||||
|
|
||||||
class EmitContext {
|
class EmitContext {
|
||||||
public:
|
public:
|
||||||
explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_);
|
explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
||||||
|
const RuntimeInfo& runtime_info_);
|
||||||
|
|
||||||
template <Type type, typename... Args>
|
template <Type type, typename... Args>
|
||||||
void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
|
void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||||
|
@ -121,6 +123,7 @@ public:
|
||||||
RegAlloc reg_alloc;
|
RegAlloc reg_alloc;
|
||||||
const Info& info;
|
const Info& info;
|
||||||
const Profile& profile;
|
const Profile& profile;
|
||||||
|
const RuntimeInfo& runtime_info;
|
||||||
|
|
||||||
Stage stage{};
|
Stage stage{};
|
||||||
std::string_view stage_name = "invalid";
|
std::string_view stage_name = "invalid";
|
||||||
|
@ -131,6 +134,8 @@ public:
|
||||||
std::vector<u32> texture_bindings;
|
std::vector<u32> texture_bindings;
|
||||||
std::vector<u32> image_bindings;
|
std::vector<u32> image_bindings;
|
||||||
|
|
||||||
|
bool uses_y_direction{};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetupExtensions(std::string& header);
|
void SetupExtensions(std::string& header);
|
||||||
void DefineConstantBuffers();
|
void DefineConstantBuffers();
|
||||||
|
|
|
@ -42,25 +42,19 @@ void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie
|
||||||
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertU32x3([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertU32x4([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertU32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
|
||||||
|
@ -153,25 +147,19 @@ void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie
|
||||||
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertF32x2([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertF32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertF32x3([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertF32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertF32x4([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertF32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
|
void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
|
||||||
|
@ -198,24 +186,18 @@ void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
|
||||||
throw NotImplementedException("GLSL Instruction");
|
throw NotImplementedException("GLSL Instruction");
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertF64x2([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertF64x3([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitCompositeInsertF64x4([[maybe_unused]] EmitContext& ctx,
|
void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||||
[[maybe_unused]] std::string_view composite,
|
u32 index) {
|
||||||
[[maybe_unused]] std::string_view object,
|
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||||
[[maybe_unused]] u32 index) {
|
|
||||||
throw NotImplementedException("GLSL Instruction");
|
|
||||||
}
|
}
|
||||||
} // namespace Shader::Backend::GLSL
|
} // namespace Shader::Backend::GLSL
|
||||||
|
|
|
@ -124,16 +124,16 @@ void EmitFPLog2(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||||
ctx.AddF32("{}=1/{};", inst, value);
|
ctx.AddF32("{}=(1.0f)/{};", inst, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||||
ctx.AddF64("{}=1/{};", inst, value);
|
ctx.AddF64("{}=1.0/{};", inst, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||||
[[maybe_unused]] std::string_view value) {
|
[[maybe_unused]] std::string_view value) {
|
||||||
ctx.AddF32("{}=1/sqrt({});", inst, value);
|
ctx.AddF32("{}=(1.0f)/sqrt({});", inst, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||||
|
|
|
@ -37,6 +37,9 @@ void EmitImageSampleImplicitLod([[maybe_unused]] EmitContext& ctx, [[maybe_unuse
|
||||||
if (!offset.IsEmpty()) {
|
if (!offset.IsEmpty()) {
|
||||||
throw NotImplementedException("Offset");
|
throw NotImplementedException("Offset");
|
||||||
}
|
}
|
||||||
|
if (info.type != TextureType::Color2D) {
|
||||||
|
throw NotImplementedException("Texture type: {}", info.type.Value());
|
||||||
|
}
|
||||||
const auto texture{Texture(ctx, info, index)};
|
const auto texture{Texture(ctx, info, index)};
|
||||||
ctx.AddF32x4("{}=texture({},{});", inst, texture, coords);
|
ctx.AddF32x4("{}=texture({},{});", inst, texture, coords);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ void EmitLocalInvocationId(EmitContext& ctx);
|
||||||
void EmitInvocationId(EmitContext& ctx);
|
void EmitInvocationId(EmitContext& ctx);
|
||||||
void EmitSampleId(EmitContext& ctx);
|
void EmitSampleId(EmitContext& ctx);
|
||||||
void EmitIsHelperInvocation(EmitContext& ctx);
|
void EmitIsHelperInvocation(EmitContext& ctx);
|
||||||
void EmitYDirection(EmitContext& ctx);
|
void EmitYDirection(EmitContext& ctx, IR::Inst& inst);
|
||||||
void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset);
|
void EmitLoadLocal(EmitContext& ctx, 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);
|
||||||
|
@ -692,11 +692,11 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||||
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||||
std::string_view index, std::string_view clamp,
|
std::string_view index, std::string_view clamp,
|
||||||
std::string_view segmentation_mask);
|
std::string_view segmentation_mask);
|
||||||
void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b,
|
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||||
std::string_view swizzle);
|
std::string_view swizzle);
|
||||||
void EmitDPdxFine(EmitContext& ctx, std::string_view op_a);
|
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||||
void EmitDPdyFine(EmitContext& ctx, std::string_view op_a);
|
void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||||
void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a);
|
void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||||
void EmitDPdyCoarse(EmitContext& ctx, std::string_view op_a);
|
void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||||
|
|
||||||
} // namespace Shader::Backend::GLSL
|
} // namespace Shader::Backend::GLSL
|
||||||
|
|
|
@ -224,8 +224,9 @@ void EmitIsHelperInvocation(EmitContext& ctx) {
|
||||||
NotImplemented();
|
NotImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitYDirection(EmitContext& ctx) {
|
void EmitYDirection(EmitContext& ctx, IR::Inst& inst) {
|
||||||
NotImplemented();
|
ctx.uses_y_direction = true;
|
||||||
|
ctx.AddF32("{}=gl_FrontMaterial.ambient.a;", inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset) {
|
void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset) {
|
||||||
|
@ -650,25 +651,4 @@ void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view val
|
||||||
NotImplemented();
|
NotImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b,
|
|
||||||
std::string_view swizzle) {
|
|
||||||
NotImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmitDPdxFine(EmitContext& ctx, std::string_view op_a) {
|
|
||||||
NotImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmitDPdyFine(EmitContext& ctx, std::string_view op_a) {
|
|
||||||
NotImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a) {
|
|
||||||
NotImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmitDPdyCoarse(EmitContext& ctx, std::string_view op_a) {
|
|
||||||
NotImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Shader::Backend::GLSL
|
} // namespace Shader::Backend::GLSL
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
// 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/modifiers.h"
|
||||||
|
#include "shader_recompiler/frontend/ir/value.h"
|
||||||
|
#include "shader_recompiler/profile.h"
|
||||||
|
|
||||||
|
namespace Shader::Backend::GLSL {
|
||||||
|
void EmitFSwizzleAdd([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||||
|
[[maybe_unused]] std::string_view op_a, [[maybe_unused]] std::string_view op_b,
|
||||||
|
[[maybe_unused]] std::string_view swizzle) {
|
||||||
|
throw NotImplementedException("GLSL Instruction");
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||||
|
ctx.AddF32("{}=dFdxFine({});", inst, op_a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||||
|
ctx.AddF32("{}=dFdyFine({});", inst, op_a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||||
|
ctx.AddF32("{}=dFdxCoarse({});", inst, op_a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||||
|
ctx.AddF32("{}=dFdyCoarse({});", inst, op_a);
|
||||||
|
}
|
||||||
|
} // namespace Shader::Backend::GLSL
|
Loading…
Reference in a new issue