mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-31 14:35:19 +00:00
spirv: fix image sample lod/clamp translation
This commit is contained in:
parent
a8b6a55559
commit
c7286d7889
@ -53,13 +53,13 @@ Id EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst* inst, u32 handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, u32 handle, Id coords, Id dref,
|
Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, u32 handle, Id coords, Id dref,
|
||||||
Id bias_lc, Id offset) {
|
Id lod, Id offset) {
|
||||||
const auto& texture = ctx.images[handle & 0xFFFF];
|
const auto& texture = ctx.images[handle & 0xFFFF];
|
||||||
const Id image = ctx.OpLoad(texture.image_type, texture.id);
|
const Id image = ctx.OpLoad(texture.image_type, texture.id);
|
||||||
const Id sampler = ctx.OpLoad(ctx.sampler_type, ctx.samplers[handle >> 16]);
|
const Id sampler = ctx.OpLoad(ctx.sampler_type, ctx.samplers[handle >> 16]);
|
||||||
const Id sampled_image = ctx.OpSampledImage(texture.sampled_type, image, sampler);
|
const Id sampled_image = ctx.OpSampledImage(texture.sampled_type, image, sampler);
|
||||||
return ctx.OpImageSampleDrefExplicitLod(ctx.F32[1], sampled_image, coords, dref,
|
return ctx.OpImageSampleDrefExplicitLod(ctx.F32[1], sampled_image, coords, dref,
|
||||||
spv::ImageOperandsMask::Lod, ctx.ConstF32(0.f));
|
spv::ImageOperandsMask::Lod, lod);
|
||||||
}
|
}
|
||||||
|
|
||||||
Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, u32 handle, Id coords, Id offset, Id offset2) {
|
Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, u32 handle, Id coords, Id offset, Id offset2) {
|
||||||
|
@ -168,18 +168,17 @@ void Translator::IMAGE_SAMPLE(const GcnInst& inst) {
|
|||||||
|
|
||||||
// Issue IR instruction, leaving unknown fields blank to patch later.
|
// Issue IR instruction, leaving unknown fields blank to patch later.
|
||||||
const IR::Value texel = [&]() -> IR::Value {
|
const IR::Value texel = [&]() -> IR::Value {
|
||||||
const IR::F32 lod = flags.test(MimgModifier::Level0) ? ir.Imm32(0.f) : IR::F32{};
|
|
||||||
if (!flags.test(MimgModifier::Pcf)) {
|
if (!flags.test(MimgModifier::Pcf)) {
|
||||||
if (explicit_lod) {
|
if (explicit_lod) {
|
||||||
return ir.ImageSampleExplicitLod(handle, body, lod, offset, info);
|
return ir.ImageSampleExplicitLod(handle, body, offset, info);
|
||||||
} else {
|
} else {
|
||||||
return ir.ImageSampleImplicitLod(handle, body, bias, offset, {}, info);
|
return ir.ImageSampleImplicitLod(handle, body, bias, offset, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (explicit_lod) {
|
if (explicit_lod) {
|
||||||
return ir.ImageSampleDrefExplicitLod(handle, body, dref, lod, offset, info);
|
return ir.ImageSampleDrefExplicitLod(handle, body, dref, offset, info);
|
||||||
}
|
}
|
||||||
return ir.ImageSampleDrefImplicitLod(handle, body, dref, bias, offset, {}, info);
|
return ir.ImageSampleDrefImplicitLod(handle, body, dref, bias, offset, info);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
for (u32 i = 0; i < 4; i++) {
|
for (u32 i = 0; i < 4; i++) {
|
||||||
|
@ -16,18 +16,6 @@ namespace {
|
|||||||
UNREACHABLE_MSG("Invalid type = {}, functionName = {}, line = {}", u32(type), functionName,
|
UNREACHABLE_MSG("Invalid type = {}, functionName = {}, line = {}", u32(type), functionName,
|
||||||
lineNumber);
|
lineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value MakeLodClampPair(IREmitter& ir, const F32& bias_lod, const F32& lod_clamp) {
|
|
||||||
if (!bias_lod.IsEmpty() && !lod_clamp.IsEmpty()) {
|
|
||||||
return ir.CompositeConstruct(bias_lod, lod_clamp);
|
|
||||||
} else if (!bias_lod.IsEmpty()) {
|
|
||||||
return bias_lod;
|
|
||||||
} else if (!lod_clamp.IsEmpty()) {
|
|
||||||
return lod_clamp;
|
|
||||||
} else {
|
|
||||||
return Value{};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
U1 IREmitter::Imm1(bool value) const {
|
U1 IREmitter::Imm1(bool value) const {
|
||||||
@ -1386,31 +1374,26 @@ Value IREmitter::ImageAtomicExchange(const Value& handle, const Value& coords, c
|
|||||||
return Inst(Opcode::ImageAtomicExchange32, Flags{info}, handle, coords, value);
|
return Inst(Opcode::ImageAtomicExchange32, Flags{info}, handle, coords, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value IREmitter::ImageSampleImplicitLod(const Value& handle, const Value& coords, const F32& bias,
|
Value IREmitter::ImageSampleImplicitLod(const Value& handle, const Value& body, const F32& bias,
|
||||||
const Value& offset, const F32& lod_clamp,
|
|
||||||
TextureInstInfo info) {
|
|
||||||
const Value bias_lc{MakeLodClampPair(*this, bias, lod_clamp)};
|
|
||||||
return Inst(Opcode::ImageSampleImplicitLod, Flags{info}, handle, coords, bias_lc, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
Value IREmitter::ImageSampleExplicitLod(const Value& handle, const Value& coords, const F32& lod,
|
|
||||||
const Value& offset, TextureInstInfo info) {
|
const Value& offset, TextureInstInfo info) {
|
||||||
return Inst(Opcode::ImageSampleExplicitLod, Flags{info}, handle, coords, lod, offset);
|
return Inst(Opcode::ImageSampleImplicitLod, Flags{info}, handle, body, bias, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
F32 IREmitter::ImageSampleDrefImplicitLod(const Value& handle, const Value& coords, const F32& dref,
|
Value IREmitter::ImageSampleExplicitLod(const Value& handle, const Value& body, const Value& offset,
|
||||||
|
TextureInstInfo info) {
|
||||||
|
return Inst(Opcode::ImageSampleExplicitLod, Flags{info}, handle, body, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
F32 IREmitter::ImageSampleDrefImplicitLod(const Value& handle, const Value& body, const F32& dref,
|
||||||
const F32& bias, const Value& offset,
|
const F32& bias, const Value& offset,
|
||||||
const F32& lod_clamp, TextureInstInfo info) {
|
TextureInstInfo info) {
|
||||||
const Value bias_lc{MakeLodClampPair(*this, bias, lod_clamp)};
|
return Inst<F32>(Opcode::ImageSampleDrefImplicitLod, Flags{info}, handle, body, dref, bias,
|
||||||
return Inst<F32>(Opcode::ImageSampleDrefImplicitLod, Flags{info}, handle, coords, dref, bias_lc,
|
|
||||||
offset);
|
offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
F32 IREmitter::ImageSampleDrefExplicitLod(const Value& handle, const Value& coords, const F32& dref,
|
F32 IREmitter::ImageSampleDrefExplicitLod(const Value& handle, const Value& body, const F32& dref,
|
||||||
const F32& lod, const Value& offset,
|
const Value& offset, TextureInstInfo info) {
|
||||||
TextureInstInfo info) {
|
return Inst<F32>(Opcode::ImageSampleDrefExplicitLod, Flags{info}, handle, body, dref, offset);
|
||||||
return Inst<F32>(Opcode::ImageSampleDrefExplicitLod, Flags{info}, handle, coords, dref, lod,
|
|
||||||
offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value IREmitter::ImageGather(const Value& handle, const Value& coords, const Value& offset,
|
Value IREmitter::ImageGather(const Value& handle, const Value& coords, const Value& offset,
|
||||||
|
@ -241,19 +241,21 @@ public:
|
|||||||
[[nodiscard]] Value ImageAtomicExchange(const Value& handle, const Value& coords,
|
[[nodiscard]] Value ImageAtomicExchange(const Value& handle, const Value& coords,
|
||||||
const Value& value, TextureInstInfo info);
|
const Value& value, TextureInstInfo info);
|
||||||
|
|
||||||
[[nodiscard]] Value ImageSampleImplicitLod(const Value& handle, const Value& coords,
|
[[nodiscard]] Value ImageSampleImplicitLod(const Value& handle, const Value& body,
|
||||||
const F32& bias, const Value& offset,
|
const F32& bias, const Value& offset,
|
||||||
const F32& lod_clamp, TextureInstInfo info);
|
|
||||||
[[nodiscard]] Value ImageSampleExplicitLod(const Value& handle, const Value& coords,
|
|
||||||
const F32& lod, const Value& offset,
|
|
||||||
TextureInstInfo info);
|
TextureInstInfo info);
|
||||||
[[nodiscard]] F32 ImageSampleDrefImplicitLod(const Value& handle, const Value& coords,
|
|
||||||
|
[[nodiscard]] Value ImageSampleExplicitLod(const Value& handle, const Value& body,
|
||||||
|
const Value& offset, TextureInstInfo info);
|
||||||
|
|
||||||
|
[[nodiscard]] F32 ImageSampleDrefImplicitLod(const Value& handle, const Value& body,
|
||||||
const F32& dref, const F32& bias,
|
const F32& dref, const F32& bias,
|
||||||
const Value& offset, const F32& lod_clamp,
|
|
||||||
TextureInstInfo info);
|
|
||||||
[[nodiscard]] F32 ImageSampleDrefExplicitLod(const Value& handle, const Value& coords,
|
|
||||||
const F32& dref, const F32& lod,
|
|
||||||
const Value& offset, TextureInstInfo info);
|
const Value& offset, TextureInstInfo info);
|
||||||
|
|
||||||
|
[[nodiscard]] F32 ImageSampleDrefExplicitLod(const Value& handle, const Value& body,
|
||||||
|
const F32& dref, const Value& offset,
|
||||||
|
TextureInstInfo info);
|
||||||
|
|
||||||
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod,
|
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod,
|
||||||
const IR::U1& skip_mips);
|
const IR::U1& skip_mips);
|
||||||
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod,
|
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod,
|
||||||
|
@ -298,10 +298,10 @@ OPCODE(ConvertU16U32, U16, U32,
|
|||||||
OPCODE(ConvertU32U16, U32, U16, )
|
OPCODE(ConvertU32U16, U32, U16, )
|
||||||
|
|
||||||
// Image operations
|
// Image operations
|
||||||
OPCODE(ImageSampleImplicitLod, F32x4, Opaque, Opaque, Opaque, Opaque, )
|
OPCODE(ImageSampleImplicitLod, F32x4, Opaque, Opaque, F32, Opaque, )
|
||||||
OPCODE(ImageSampleExplicitLod, F32x4, Opaque, Opaque, Opaque, Opaque, )
|
OPCODE(ImageSampleExplicitLod, F32x4, Opaque, Opaque, Opaque, )
|
||||||
OPCODE(ImageSampleDrefImplicitLod, F32, Opaque, Opaque, F32, Opaque, Opaque, )
|
OPCODE(ImageSampleDrefImplicitLod, F32, Opaque, Opaque, F32, F32, Opaque, )
|
||||||
OPCODE(ImageSampleDrefExplicitLod, F32, Opaque, Opaque, F32, Opaque, Opaque, )
|
OPCODE(ImageSampleDrefExplicitLod, F32, Opaque, Opaque, F32, Opaque, )
|
||||||
OPCODE(ImageGather, F32x4, Opaque, Opaque, Opaque, Opaque, )
|
OPCODE(ImageGather, F32x4, Opaque, Opaque, Opaque, Opaque, )
|
||||||
OPCODE(ImageGatherDref, F32x4, Opaque, Opaque, Opaque, Opaque, F32, )
|
OPCODE(ImageGatherDref, F32x4, Opaque, Opaque, Opaque, Opaque, F32, )
|
||||||
OPCODE(ImageFetch, F32x4, Opaque, Opaque, Opaque, U32, Opaque, )
|
OPCODE(ImageFetch, F32x4, Opaque, Opaque, Opaque, U32, Opaque, )
|
||||||
|
@ -593,7 +593,8 @@ void PatchImageInstruction(IR::Block& block, IR::Inst& inst, Info& info, Descrip
|
|||||||
inst.GetOpcode() == IR::Opcode::ImageSampleExplicitLod ||
|
inst.GetOpcode() == IR::Opcode::ImageSampleExplicitLod ||
|
||||||
inst.GetOpcode() == IR::Opcode::ImageSampleDrefExplicitLod);
|
inst.GetOpcode() == IR::Opcode::ImageSampleDrefExplicitLod);
|
||||||
const u32 pos = inst.GetOpcode() == IR::Opcode::ImageSampleExplicitLod ? 2 : 3;
|
const u32 pos = inst.GetOpcode() == IR::Opcode::ImageSampleExplicitLod ? 2 : 3;
|
||||||
inst.SetArg(pos, arg);
|
const IR::Value value = inst_info.force_level0 ? ir.Imm32(0.f) : arg;
|
||||||
|
inst.SetArg(pos, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user