Browse Source

shader: Implement front face

nce_cpp
ReinUsesLisp 5 years ago
committed by ameerj
parent
commit
63ea42e0d5
  1. 3
      src/shader_recompiler/backend/spirv/emit_context.cpp
  2. 1
      src/shader_recompiler/backend/spirv/emit_context.h
  3. 4
      src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
  4. 3
      src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp
  5. 1
      src/shader_recompiler/shader_info.h

3
src/shader_recompiler/backend/spirv/emit_context.cpp

@ -302,6 +302,9 @@ void EmitContext::DefineInputs(const Info& info) {
base_vertex = DefineInput(*this, U32[1], spv::BuiltIn::BaseVertex); base_vertex = DefineInput(*this, U32[1], spv::BuiltIn::BaseVertex);
} }
} }
if (info.loads_front_face) {
front_face = DefineInput(*this, U1, spv::BuiltIn::FrontFacing);
}
for (size_t index = 0; index < info.loads_generics.size(); ++index) { for (size_t index = 0; index < info.loads_generics.size(); ++index) {
if (!info.loads_generics[index]) { if (!info.loads_generics[index]) {
continue; continue;

1
src/shader_recompiler/backend/spirv/emit_context.h

@ -94,6 +94,7 @@ public:
Id vertex_id{}; Id vertex_id{};
Id vertex_index{}; Id vertex_index{};
Id base_vertex{}; Id base_vertex{};
Id front_face{};
Id input_position{}; Id input_position{};
std::array<Id, 32> input_generics{}; std::array<Id, 32> input_generics{};

4
src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp

@ -156,6 +156,10 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr) {
return ctx.OpISub(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.vertex_index), return ctx.OpISub(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.vertex_index),
ctx.OpLoad(ctx.U32[1], ctx.base_vertex)); ctx.OpLoad(ctx.U32[1], ctx.base_vertex));
} }
case IR::Attribute::FrontFace:
return ctx.OpSelect(ctx.U32[1], ctx.OpLoad(ctx.U1, ctx.front_face),
ctx.Constant(ctx.U32[1], std::numeric_limits<u32>::max()),
ctx.u32_zero_value);
default: default:
throw NotImplementedException("Read attribute {}", attr); throw NotImplementedException("Read attribute {}", attr);
} }

3
src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp

@ -44,6 +44,9 @@ void GetAttribute(Info& info, IR::Attribute attribute) {
case IR::Attribute::VertexId: case IR::Attribute::VertexId:
info.loads_vertex_id = true; info.loads_vertex_id = true;
break; break;
case IR::Attribute::FrontFace:
info.loads_front_face = true;
break;
default: default:
throw NotImplementedException("Get attribute {}", attribute); throw NotImplementedException("Get attribute {}", attribute);
} }

1
src/shader_recompiler/shader_info.h

@ -62,6 +62,7 @@ struct Info {
bool loads_position{}; bool loads_position{};
bool loads_instance_id{}; bool loads_instance_id{};
bool loads_vertex_id{}; bool loads_vertex_id{};
bool loads_front_face{};
std::array<bool, 8> stores_frag_color{}; std::array<bool, 8> stores_frag_color{};
bool stores_frag_depth{}; bool stores_frag_depth{};

Loading…
Cancel
Save