mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 14:52:45 +01:00
generate shader output in msl
This commit is contained in:
parent
16986bf42f
commit
042788cd71
5 changed files with 14 additions and 12 deletions
|
@ -215,7 +215,7 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
|||
case IR::Attribute::PositionW: {
|
||||
const bool is_array{IsInputArray(ctx.stage)};
|
||||
const auto input_decorator{is_array ? fmt::format("gl_in[{}].", vertex) : ""};
|
||||
ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle);
|
||||
ctx.AddF32("{}={}{}.{};", inst, input_decorator, "__out.position", swizzle);
|
||||
break;
|
||||
}
|
||||
case IR::Attribute::PointSpriteS:
|
||||
|
@ -326,7 +326,7 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val
|
|||
case IR::Attribute::PositionY:
|
||||
case IR::Attribute::PositionZ:
|
||||
case IR::Attribute::PositionW:
|
||||
ctx.Add("gl_Position.{}={};", swizzle, value);
|
||||
ctx.Add("__out.position.{}={};", swizzle, value);
|
||||
break;
|
||||
case IR::Attribute::ClipDistance0:
|
||||
case IR::Attribute::ClipDistance1:
|
||||
|
@ -337,7 +337,7 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val
|
|||
case IR::Attribute::ClipDistance6:
|
||||
case IR::Attribute::ClipDistance7: {
|
||||
const u32 index{static_cast<u32>(attr) - static_cast<u32>(IR::Attribute::ClipDistance0)};
|
||||
ctx.Add("gl_ClipDistance[{}]={};", index, value);
|
||||
ctx.Add("IMPLEMENT(gl_ClipDistance)[{}]={};", index, value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -9,16 +9,18 @@
|
|||
|
||||
namespace Shader::Backend::MSL {
|
||||
namespace {
|
||||
// TODO
|
||||
std::string_view OutputVertexIndex(EmitContext& ctx) {
|
||||
return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : "";
|
||||
return ctx.stage == Stage::TessellationControl ? "[IMPLEMENT(gl_InvocationID)]" : "";
|
||||
}
|
||||
|
||||
void InitializeOutputVaryings(EmitContext& ctx) {
|
||||
if (ctx.uses_geometry_passthrough) {
|
||||
return;
|
||||
}
|
||||
ctx.Add("__Output __out;");
|
||||
if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
|
||||
ctx.Add("gl_Position=vec4(0,0,0,1);");
|
||||
ctx.Add("__out.position=vec4(0,0,0,1);");
|
||||
}
|
||||
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (!ctx.info.stores.Generic(index)) {
|
||||
|
@ -29,7 +31,7 @@ void InitializeOutputVaryings(EmitContext& ctx) {
|
|||
size_t element{};
|
||||
while (element < info_array.size()) {
|
||||
const auto& info{info_array.at(element)};
|
||||
const auto varying_name{fmt::format("{}{}", info.name, output_decorator)};
|
||||
const auto varying_name{fmt::format("__out.{}{}", info.name, output_decorator)};
|
||||
switch (info.num_components) {
|
||||
case 1: {
|
||||
const char value{element == 3 ? '1' : '0'};
|
||||
|
@ -39,15 +41,15 @@ void InitializeOutputVaryings(EmitContext& ctx) {
|
|||
case 2:
|
||||
case 3:
|
||||
if (element + info.num_components < 4) {
|
||||
ctx.Add("{}=vec{}(0);", varying_name, info.num_components);
|
||||
ctx.Add("{}=vec<float, {}>(0);", varying_name, info.num_components);
|
||||
} else {
|
||||
// last element is the w component, must be initialized to 1
|
||||
const auto zeros{info.num_components == 3 ? "0,0," : "0,"};
|
||||
ctx.Add("{}=vec{}({}1);", varying_name, info.num_components, zeros);
|
||||
ctx.Add("{}=vec<float, {}>({}1);", varying_name, info.num_components, zeros);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
ctx.Add("{}=vec4(0,0,0,1);", varying_name);
|
||||
ctx.Add("{}=float4(0,0,0,1);", varying_name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -253,7 +253,6 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
|
|||
break;
|
||||
case Stage::Fragment:
|
||||
stage_name = "fs";
|
||||
position_name = "gl_FragCoord";
|
||||
if (runtime_info.force_early_z) {
|
||||
header += "layout(early_fragment_tests)in;";
|
||||
}
|
||||
|
@ -461,7 +460,7 @@ void EmitContext::DefineHelperFunctions() {
|
|||
const auto position_idx{is_array ? "gl_in[vertex]." : ""};
|
||||
func += fmt::format("case {}:return {}{}[masked_index];",
|
||||
static_cast<u32>(IR::Attribute::PositionX) >> 2, position_idx,
|
||||
position_name);
|
||||
"__out.position");
|
||||
}
|
||||
const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
|
||||
for (u32 index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
|
|
|
@ -144,7 +144,6 @@ public:
|
|||
|
||||
Stage stage{};
|
||||
std::string_view stage_name = "invalid";
|
||||
std::string_view position_name = "gl_Position";
|
||||
|
||||
std::vector<TextureImageDefinition> texture_buffers;
|
||||
std::vector<TextureImageDefinition> image_buffers;
|
||||
|
|
|
@ -277,6 +277,8 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline(
|
|||
LOG_ERROR(Render_Metal, "failed to create library: {}",
|
||||
error->description()->cString(NS::ASCIIStringEncoding));
|
||||
// HACK
|
||||
std::cout << error->description()->cString(NS::ASCIIStringEncoding) << std::endl;
|
||||
// HACK
|
||||
throw;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue