mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-01-19 13:08:27 +00:00
d9873e30bc
* shader_recompiler: Add LDEXP * shader_recompiler: Add most image integer atomic ops * shader_recompiler: Implement shared memory load/store * shader_recompiler: More image atomics * externals: Update sirit * clang format * cmake: Add missing files * shader_recompiler: Fix some atomic bugs * shader_recompiler: Vs outputs * shader_recompiler: Shared mem has side-effects, fix format component order * shader_recompiler: Inline constant buffer impl * video_core: Fix regressions * Work * Fixup a few things
263 lines
7.3 KiB
C++
263 lines
7.3 KiB
C++
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h"
|
|
#include "shader_recompiler/backend/spirv/spirv_emit_context.h"
|
|
|
|
namespace Shader::Backend::SPIRV {
|
|
namespace {
|
|
Id ExtractU16(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpUConvert(ctx.U16, value);
|
|
} else {
|
|
return ctx.OpBitFieldUExtract(ctx.U32[1], value, ctx.u32_zero_value, ctx.ConstU32(16u));
|
|
}
|
|
}
|
|
|
|
Id ExtractS16(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpSConvert(ctx.S16, value);
|
|
} else {
|
|
return ctx.OpBitFieldSExtract(ctx.U32[1], value, ctx.u32_zero_value, ctx.ConstU32(16u));
|
|
}
|
|
}
|
|
|
|
Id ExtractU8(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int8) {
|
|
return ctx.OpUConvert(ctx.U8, value);
|
|
} else {
|
|
return ctx.OpBitFieldUExtract(ctx.U32[1], value, ctx.u32_zero_value, ctx.ConstU32(8u));
|
|
}
|
|
}
|
|
|
|
Id ExtractS8(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int8) {
|
|
return ctx.OpSConvert(ctx.S8, value);
|
|
} else {
|
|
return ctx.OpBitFieldSExtract(ctx.U32[1], value, ctx.u32_zero_value, ctx.ConstU32(8u));
|
|
}
|
|
}
|
|
} // Anonymous namespace
|
|
|
|
Id EmitConvertS16F16(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpSConvert(ctx.U32[1], ctx.OpConvertFToS(ctx.U16, value));
|
|
} else {
|
|
return ExtractS16(ctx, ctx.OpConvertFToS(ctx.U32[1], value));
|
|
}
|
|
}
|
|
|
|
Id EmitConvertS16F32(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpSConvert(ctx.U32[1], ctx.OpConvertFToS(ctx.U16, value));
|
|
} else {
|
|
return ExtractS16(ctx, ctx.OpConvertFToS(ctx.U32[1], value));
|
|
}
|
|
}
|
|
|
|
Id EmitConvertS16F64(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpSConvert(ctx.U32[1], ctx.OpConvertFToS(ctx.U16, value));
|
|
} else {
|
|
return ExtractS16(ctx, ctx.OpConvertFToS(ctx.U32[1], value));
|
|
}
|
|
}
|
|
|
|
Id EmitConvertS32F16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToS(ctx.U32[1], value);
|
|
}
|
|
|
|
Id EmitConvertS32F32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToS(ctx.U32[1], value);
|
|
}
|
|
|
|
Id EmitConvertS32F64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToS(ctx.U32[1], value);
|
|
}
|
|
|
|
Id EmitConvertS64F16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToS(ctx.U64, value);
|
|
}
|
|
|
|
Id EmitConvertS64F32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToS(ctx.U64, value);
|
|
}
|
|
|
|
Id EmitConvertS64F64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToS(ctx.U64, value);
|
|
}
|
|
|
|
Id EmitConvertU16F16(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpUConvert(ctx.U32[1], ctx.OpConvertFToU(ctx.U16, value));
|
|
} else {
|
|
return ExtractU16(ctx, ctx.OpConvertFToU(ctx.U32[1], value));
|
|
}
|
|
}
|
|
|
|
Id EmitConvertU16F32(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpUConvert(ctx.U32[1], ctx.OpConvertFToU(ctx.U16, value));
|
|
} else {
|
|
return ExtractU16(ctx, ctx.OpConvertFToU(ctx.U32[1], value));
|
|
}
|
|
}
|
|
|
|
Id EmitConvertU16F64(EmitContext& ctx, Id value) {
|
|
if (ctx.profile.support_int16) {
|
|
return ctx.OpUConvert(ctx.U32[1], ctx.OpConvertFToU(ctx.U16, value));
|
|
} else {
|
|
return ExtractU16(ctx, ctx.OpConvertFToU(ctx.U32[1], value));
|
|
}
|
|
}
|
|
|
|
Id EmitConvertU32F16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToU(ctx.U32[1], value);
|
|
}
|
|
|
|
Id EmitConvertU32F32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToU(ctx.U32[1], value);
|
|
}
|
|
|
|
Id EmitConvertU32F64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToU(ctx.U32[1], value);
|
|
}
|
|
|
|
Id EmitConvertU64F16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToU(ctx.U64, value);
|
|
}
|
|
|
|
Id EmitConvertU64F32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToU(ctx.U64, value);
|
|
}
|
|
|
|
Id EmitConvertU64F64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertFToU(ctx.U64, value);
|
|
}
|
|
|
|
Id EmitConvertU64U32(EmitContext& ctx, Id value) {
|
|
return ctx.OpUConvert(ctx.U64, value);
|
|
}
|
|
|
|
Id EmitConvertU32U64(EmitContext& ctx, Id value) {
|
|
return ctx.OpUConvert(ctx.U32[1], value);
|
|
}
|
|
|
|
Id EmitConvertF16F32(EmitContext& ctx, Id value) {
|
|
return ctx.OpFConvert(ctx.F16[1], value);
|
|
}
|
|
|
|
Id EmitConvertF32F16(EmitContext& ctx, Id value) {
|
|
return ctx.OpFConvert(ctx.F32[1], value);
|
|
}
|
|
|
|
Id EmitConvertF32F64(EmitContext& ctx, Id value) {
|
|
return ctx.OpFConvert(ctx.F32[1], value);
|
|
}
|
|
|
|
Id EmitConvertF64F32(EmitContext& ctx, Id value) {
|
|
return ctx.OpFConvert(ctx.F64[1], value);
|
|
}
|
|
|
|
Id EmitConvertF16S8(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F16[1], ExtractS8(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF16S16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F16[1], ExtractS16(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF16S32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F16[1], value);
|
|
}
|
|
|
|
Id EmitConvertF16S64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F16[1], value);
|
|
}
|
|
|
|
Id EmitConvertF16U8(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F16[1], ExtractU8(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF16U16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F16[1], ExtractU16(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF16U32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F16[1], value);
|
|
}
|
|
|
|
Id EmitConvertF16U64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F16[1], value);
|
|
}
|
|
|
|
Id EmitConvertF32S8(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F32[1], ExtractS8(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF32S16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F32[1], ExtractS16(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF32S32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F32[1], value);
|
|
}
|
|
|
|
Id EmitConvertF32S64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F32[1], value);
|
|
}
|
|
|
|
Id EmitConvertF32U8(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F32[1], ExtractU8(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF32U16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F32[1], ExtractU16(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF32U32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F32[1], value);
|
|
}
|
|
|
|
Id EmitConvertF32U64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F32[1], value);
|
|
}
|
|
|
|
Id EmitConvertF64S8(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F64[1], ExtractS8(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF64S16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F64[1], ExtractS16(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF64S32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F64[1], value);
|
|
}
|
|
|
|
Id EmitConvertF64S64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertSToF(ctx.F64[1], value);
|
|
}
|
|
|
|
Id EmitConvertF64U8(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F64[1], ExtractU8(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF64U16(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F64[1], ExtractU16(ctx, value));
|
|
}
|
|
|
|
Id EmitConvertF64U32(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F64[1], value);
|
|
}
|
|
|
|
Id EmitConvertF64U64(EmitContext& ctx, Id value) {
|
|
return ctx.OpConvertUToF(ctx.F64[1], value);
|
|
}
|
|
|
|
Id EmitConvertU16U32(EmitContext& ctx, Id value) {
|
|
return ctx.OpUConvert(ctx.U16, value);
|
|
}
|
|
|
|
} // namespace Shader::Backend::SPIRV
|