|
|
|
@ -1,3 +1,6 @@ |
|
|
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
@ -195,6 +198,34 @@ Id Texture(EmitContext& ctx, IR::TextureInstInfo info, [[maybe_unused]] const IR |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Id TextureColorResultType(EmitContext& ctx, const TextureDefinition& def) { |
|
|
|
switch (def.component_type) { |
|
|
|
case SamplerComponentType::Float: |
|
|
|
case SamplerComponentType::Depth: |
|
|
|
return ctx.F32[4]; |
|
|
|
case SamplerComponentType::Sint: |
|
|
|
case SamplerComponentType::Stencil: |
|
|
|
return ctx.S32[4]; |
|
|
|
case SamplerComponentType::Uint: |
|
|
|
return ctx.U32[4]; |
|
|
|
} |
|
|
|
throw InvalidArgument("Invalid sampler component type {}", def.component_type); |
|
|
|
} |
|
|
|
|
|
|
|
Id TextureSampleResultToFloat(EmitContext& ctx, const TextureDefinition& def, Id color) { |
|
|
|
switch (def.component_type) { |
|
|
|
case SamplerComponentType::Float: |
|
|
|
case SamplerComponentType::Depth: |
|
|
|
return color; |
|
|
|
case SamplerComponentType::Sint: |
|
|
|
case SamplerComponentType::Stencil: |
|
|
|
return ctx.OpConvertSToF(ctx.F32[4], color); |
|
|
|
case SamplerComponentType::Uint: |
|
|
|
return ctx.OpConvertUToF(ctx.F32[4], color); |
|
|
|
} |
|
|
|
throw InvalidArgument("Invalid sampler component type {}", def.component_type); |
|
|
|
} |
|
|
|
|
|
|
|
Id TextureImage(EmitContext& ctx, IR::TextureInstInfo info, const IR::Value& index) { |
|
|
|
if (!index.IsImmediate() || index.U32() != 0) { |
|
|
|
throw NotImplementedException("Indirect image indexing"); |
|
|
|
@ -449,31 +480,39 @@ Id EmitBoundImageWrite(EmitContext&) { |
|
|
|
Id EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
|
|
|
Id bias_lc, const IR::Value& offset) { |
|
|
|
const auto info{inst->Flags<IR::TextureInstInfo>()}; |
|
|
|
const TextureDefinition& def{ctx.textures.at(info.descriptor_index)}; |
|
|
|
const Id color_type{TextureColorResultType(ctx, def)}; |
|
|
|
const Id texture{Texture(ctx, info, index)}; |
|
|
|
Id color{}; |
|
|
|
if (ctx.stage == Stage::Fragment) { |
|
|
|
const ImageOperands operands(ctx, info.has_bias != 0, false, info.has_lod_clamp != 0, |
|
|
|
bias_lc, offset); |
|
|
|
return Emit(&EmitContext::OpImageSparseSampleImplicitLod, |
|
|
|
&EmitContext::OpImageSampleImplicitLod, ctx, inst, ctx.F32[4], |
|
|
|
Texture(ctx, info, index), coords, operands.MaskOptional(), operands.Span()); |
|
|
|
color = Emit(&EmitContext::OpImageSparseSampleImplicitLod, |
|
|
|
&EmitContext::OpImageSampleImplicitLod, ctx, inst, color_type, texture, |
|
|
|
coords, operands.MaskOptional(), operands.Span()); |
|
|
|
} else { |
|
|
|
// We can't use implicit lods on non-fragment stages on SPIR-V. Maxwell hardware behaves as
|
|
|
|
// if the lod was explicitly zero. This may change on Turing with implicit compute
|
|
|
|
// derivatives
|
|
|
|
const Id lod{ctx.Const(0.0f)}; |
|
|
|
const ImageOperands operands(ctx, false, true, info.has_lod_clamp != 0, lod, offset); |
|
|
|
return Emit(&EmitContext::OpImageSparseSampleExplicitLod, |
|
|
|
&EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4], |
|
|
|
Texture(ctx, info, index), coords, operands.Mask(), operands.Span()); |
|
|
|
color = Emit(&EmitContext::OpImageSparseSampleExplicitLod, |
|
|
|
&EmitContext::OpImageSampleExplicitLod, ctx, inst, color_type, texture, |
|
|
|
coords, operands.Mask(), operands.Span()); |
|
|
|
} |
|
|
|
return TextureSampleResultToFloat(ctx, def, color); |
|
|
|
} |
|
|
|
|
|
|
|
Id EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
|
|
|
Id lod, const IR::Value& offset) { |
|
|
|
const auto info{inst->Flags<IR::TextureInstInfo>()}; |
|
|
|
const TextureDefinition& def{ctx.textures.at(info.descriptor_index)}; |
|
|
|
const Id color_type{TextureColorResultType(ctx, def)}; |
|
|
|
const ImageOperands operands(ctx, false, true, false, lod, offset); |
|
|
|
return Emit(&EmitContext::OpImageSparseSampleExplicitLod, |
|
|
|
&EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4], |
|
|
|
Texture(ctx, info, index), coords, operands.Mask(), operands.Span()); |
|
|
|
const Id color{Emit(&EmitContext::OpImageSparseSampleExplicitLod, |
|
|
|
&EmitContext::OpImageSampleExplicitLod, ctx, inst, color_type, |
|
|
|
Texture(ctx, info, index), coords, operands.Mask(), operands.Span())}; |
|
|
|
return TextureSampleResultToFloat(ctx, def, color); |
|
|
|
} |
|
|
|
|
|
|
|
Id EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, |
|
|
|
@ -509,13 +548,18 @@ Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Va |
|
|
|
Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
|
|
|
const IR::Value& offset, const IR::Value& offset2) { |
|
|
|
const auto info{inst->Flags<IR::TextureInstInfo>()}; |
|
|
|
const TextureDefinition& def{ctx.textures.at(info.descriptor_index)}; |
|
|
|
const Id color_type{TextureColorResultType(ctx, def)}; |
|
|
|
const ImageOperands operands(ctx, offset, offset2); |
|
|
|
const Id texture{Texture(ctx, info, index)}; |
|
|
|
if (ctx.profile.need_gather_subpixel_offset) { |
|
|
|
coords = ImageGatherSubpixelOffset(ctx, info, TextureImage(ctx, info, index), coords); |
|
|
|
} |
|
|
|
return Emit(&EmitContext::OpImageSparseGather, &EmitContext::OpImageGather, ctx, inst, |
|
|
|
ctx.F32[4], Texture(ctx, info, index), coords, ctx.Const(info.gather_component), |
|
|
|
operands.MaskOptional(), operands.Span()); |
|
|
|
const Id color{ |
|
|
|
Emit(&EmitContext::OpImageSparseGather, &EmitContext::OpImageGather, ctx, inst, color_type, |
|
|
|
texture, coords, ctx.Const(info.gather_component), operands.MaskOptional(), |
|
|
|
operands.Span())}; |
|
|
|
return TextureSampleResultToFloat(ctx, def, color); |
|
|
|
} |
|
|
|
|
|
|
|
Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
|
|
|
@ -533,6 +577,9 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, |
|
|
|
Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, |
|
|
|
Id lod, Id ms) { |
|
|
|
const auto info{inst->Flags<IR::TextureInstInfo>()}; |
|
|
|
const TextureDefinition* def = |
|
|
|
info.type == TextureType::Buffer ? nullptr : &ctx.textures.at(info.descriptor_index); |
|
|
|
const Id result_type{def ? TextureColorResultType(ctx, *def) : ctx.F32[4]}; |
|
|
|
AddOffsetToCoordinates(ctx, info, coords, offset); |
|
|
|
if (info.type == TextureType::Buffer) { |
|
|
|
lod = Id{}; |
|
|
|
@ -542,8 +589,13 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c |
|
|
|
lod = Id{}; |
|
|
|
} |
|
|
|
const ImageOperands operands(lod, ms); |
|
|
|
return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], |
|
|
|
TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span()); |
|
|
|
Id color{Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, |
|
|
|
result_type, TextureImage(ctx, info, index), coords, operands.MaskOptional(), |
|
|
|
operands.Span())}; |
|
|
|
if (def) { |
|
|
|
color = TextureSampleResultToFloat(ctx, *def, color); |
|
|
|
} |
|
|
|
return color; |
|
|
|
} |
|
|
|
|
|
|
|
Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod, |
|
|
|
@ -588,14 +640,17 @@ Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, I |
|
|
|
Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
|
|
|
Id derivatives, const IR::Value& offset, Id lod_clamp) { |
|
|
|
const auto info{inst->Flags<IR::TextureInstInfo>()}; |
|
|
|
const TextureDefinition& def{ctx.textures.at(info.descriptor_index)}; |
|
|
|
const Id color_type{TextureColorResultType(ctx, def)}; |
|
|
|
const auto operands = info.num_derivatives == 3 |
|
|
|
? ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, |
|
|
|
ctx.Def(offset), {}, lod_clamp) |
|
|
|
: ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, |
|
|
|
info.num_derivatives, offset, lod_clamp); |
|
|
|
return Emit(&EmitContext::OpImageSparseSampleExplicitLod, |
|
|
|
&EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4], |
|
|
|
Texture(ctx, info, index), coords, operands.Mask(), operands.Span()); |
|
|
|
const Id color{Emit(&EmitContext::OpImageSparseSampleExplicitLod, |
|
|
|
&EmitContext::OpImageSampleExplicitLod, ctx, inst, color_type, |
|
|
|
Texture(ctx, info, index), coords, operands.Mask(), operands.Span())}; |
|
|
|
return TextureSampleResultToFloat(ctx, def, color); |
|
|
|
} |
|
|
|
|
|
|
|
Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords) { |
|
|
|
|