diff --git a/src/xenia/gpu/spirv_shader_translator.cc b/src/xenia/gpu/spirv_shader_translator.cc index bff854a87..9fd4ba10d 100644 --- a/src/xenia/gpu/spirv_shader_translator.cc +++ b/src/xenia/gpu/spirv_shader_translator.cc @@ -54,6 +54,7 @@ void SpirvShaderTranslator::StartTranslation() { bool_type_ = b.makeBoolType(); float_type_ = b.makeFloatType(32); + int_type_ = b.makeIntType(32); Id uint_type = b.makeUintType(32); vec2_float_type_ = b.makeVectorType(float_type_, 2); vec3_float_type_ = b.makeVectorType(float_type_, 3); @@ -961,6 +962,24 @@ void SpirvShaderTranslator::ProcessScalarAluInstruction( dest = b.makeFloatConstant(0.f); } break; + case AluScalarOpcode::kMaxAs: { + // a0 = clamp(floor(src0 + 0.5), -256, 255) + auto addr = b.createBinOp(spv::Op::OpFAdd, float_type_, sources[0], + b.makeFloatConstant(0.5f)); + addr = b.createUnaryOp(spv::Op::OpConvertFToS, int_type_, addr); + addr = CreateGlslStd450InstructionCall( + spv::Decoration::DecorationInvariant, int_type_, + spv::GLSLstd450::kSClamp, + {addr, b.makeIntConstant(-256), b.makeIntConstant(255)}); + b.createStore(addr, a0_); + + // dest = src0 >= src1 ? src0 : src1 + auto cond = b.createBinOp(spv::Op::OpFOrdGreaterThanEqual, bool_type_, + sources[0], sources[1]); + dest = b.createTriOp(spv::Op::OpSelect, float_type_, cond, sources[0], + sources[1]); + } break; + case AluScalarOpcode::kMaxs: { // dest = max(src0, src1) dest = CreateGlslStd450InstructionCall( @@ -1050,6 +1069,11 @@ void SpirvShaderTranslator::ProcessScalarAluInstruction( b.makeFloatConstant(1.f), b.makeFloatConstant(0.f)); } break; + case AluScalarOpcode::kSetpClr: { + b.createStore(b.makeBoolConstant(false), p0_); + dest = b.makeFloatConstant(FLT_MAX); + } break; + case AluScalarOpcode::kSetpEq: { auto cond = b.createBinOp(spv::Op::OpFOrdEqual, bool_type_, sources[0], b.makeFloatConstant(0.f)); diff --git a/src/xenia/gpu/spirv_shader_translator.h b/src/xenia/gpu/spirv_shader_translator.h index 1ec006d50..31894a901 100644 --- a/src/xenia/gpu/spirv_shader_translator.h +++ b/src/xenia/gpu/spirv_shader_translator.h @@ -104,7 +104,7 @@ class SpirvShaderTranslator : public ShaderTranslator { spv::Function* translated_main_ = 0; // Types. - spv::Id float_type_ = 0, bool_type_ = 0; + spv::Id float_type_ = 0, bool_type_ = 0, int_type_ = 0; spv::Id vec2_float_type_ = 0, vec3_float_type_ = 0, vec4_float_type_ = 0; spv::Id vec4_uint_type_ = 0; spv::Id vec4_bool_type_ = 0;