fix(texture): Apply F32 Adjustments for Proper Z-A Rendering

This commit is contained in:
collecting
2026-02-10 12:06:54 -05:00
parent 9b7e7b26aa
commit 9a8e6a20ca
2 changed files with 15 additions and 19 deletions

View File

@@ -201,10 +201,10 @@ Id Texture(EmitContext& ctx, IR::TextureInstInfo info, [[maybe_unused]] const IR
switch (def.component_type) { switch (def.component_type) {
case SamplerComponentType::Float: case SamplerComponentType::Float:
case SamplerComponentType::Depth: case SamplerComponentType::Depth:
case SamplerComponentType::Stencil:
return ctx.F32[4]; return ctx.F32[4];
case SamplerComponentType::Sint: case SamplerComponentType::Sint:
return ctx.S32[4]; return ctx.S32[4];
case SamplerComponentType::Stencil:
case SamplerComponentType::Uint: case SamplerComponentType::Uint:
return ctx.U32[4]; return ctx.U32[4];
} }
@@ -212,19 +212,16 @@ Id Texture(EmitContext& ctx, IR::TextureInstInfo info, [[maybe_unused]] const IR
} }
/// Convert texture sample result to float, handling integer and stencil types /// Convert texture sample result to float, handling integer and stencil types
[[nodiscard]] Id TextureSampleResultToFloat(EmitContext& ctx, const TextureDefinition& def, Id color) { [[nodiscard]] Id TextureSampleResultToFloat(EmitContext& ctx, const TextureDefinition& def,
Id color) {
switch (def.component_type) { switch (def.component_type) {
case SamplerComponentType::Float: case SamplerComponentType::Float:
case SamplerComponentType::Depth: case SamplerComponentType::Depth:
case SamplerComponentType::Stencil:
return color; return color;
case SamplerComponentType::Sint: case SamplerComponentType::Sint:
return ctx.OpConvertSToF(ctx.F32[4], color); return ctx.OpConvertSToF(ctx.F32[4], color);
case SamplerComponentType::Stencil: {
const Id converted{ctx.OpConvertUToF(ctx.F32[4], color)};
const Id inv255{ctx.Const(1.0f / 255.0f)};
const Id scale{ctx.ConstantComposite(ctx.F32[4], inv255, inv255, inv255, inv255)};
return ctx.OpFMul(ctx.F32[4], converted, scale);
}
case SamplerComponentType::Uint: case SamplerComponentType::Uint:
return ctx.OpConvertUToF(ctx.F32[4], color); return ctx.OpConvertUToF(ctx.F32[4], color);
} }
@@ -493,8 +490,8 @@ Id EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value&
const ImageOperands operands(ctx, info.has_bias != 0, false, info.has_lod_clamp != 0, const ImageOperands operands(ctx, info.has_bias != 0, false, info.has_lod_clamp != 0,
bias_lc, offset); bias_lc, offset);
color = Emit(&EmitContext::OpImageSparseSampleImplicitLod, color = Emit(&EmitContext::OpImageSparseSampleImplicitLod,
&EmitContext::OpImageSampleImplicitLod, ctx, inst, color_type, texture, &EmitContext::OpImageSampleImplicitLod, ctx, inst, color_type, texture, coords,
coords, operands.MaskOptional(), operands.Span()); operands.MaskOptional(), operands.Span());
} else { } else {
// We can't use implicit lods on non-fragment stages on SPIR-V. Maxwell hardware behaves as // 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 // if the lod was explicitly zero. This may change on Turing with implicit compute
@@ -502,8 +499,8 @@ Id EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value&
const Id lod{ctx.Const(0.0f)}; const Id lod{ctx.Const(0.0f)};
const ImageOperands operands(ctx, false, true, info.has_lod_clamp != 0, lod, offset); const ImageOperands operands(ctx, false, true, info.has_lod_clamp != 0, lod, offset);
color = Emit(&EmitContext::OpImageSparseSampleExplicitLod, color = Emit(&EmitContext::OpImageSparseSampleExplicitLod,
&EmitContext::OpImageSampleExplicitLod, ctx, inst, color_type, texture, &EmitContext::OpImageSampleExplicitLod, ctx, inst, color_type, texture, coords,
coords, operands.Mask(), operands.Span()); operands.Mask(), operands.Span());
} }
return TextureSampleResultToFloat(ctx, def, color); return TextureSampleResultToFloat(ctx, def, color);
} }
@@ -560,10 +557,9 @@ Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id
if (ctx.profile.need_gather_subpixel_offset) { if (ctx.profile.need_gather_subpixel_offset) {
coords = ImageGatherSubpixelOffset(ctx, info, TextureImage(ctx, info, index), coords); coords = ImageGatherSubpixelOffset(ctx, info, TextureImage(ctx, info, index), coords);
} }
const Id color{ const Id color{Emit(&EmitContext::OpImageSparseGather, &EmitContext::OpImageGather, ctx, inst,
Emit(&EmitContext::OpImageSparseGather, &EmitContext::OpImageGather, ctx, inst, color_type, color_type, texture, coords, ctx.Const(info.gather_component),
texture, coords, ctx.Const(info.gather_component), operands.MaskOptional(), operands.MaskOptional(), operands.Span())};
operands.Span())};
return TextureSampleResultToFloat(ctx, def, color); return TextureSampleResultToFloat(ctx, def, color);
} }

View File

@@ -33,17 +33,18 @@ enum class Operation {
case SamplerComponentType::Depth: case SamplerComponentType::Depth:
return ctx.F32[1]; return ctx.F32[1];
case SamplerComponentType::Sint: case SamplerComponentType::Sint:
case SamplerComponentType::Stencil:
return ctx.S32[1]; return ctx.S32[1];
case SamplerComponentType::Uint: case SamplerComponentType::Uint:
return ctx.U32[1]; return ctx.U32[1];
case SamplerComponentType::Stencil:
return ctx.F32[1];
} }
throw InvalidArgument("Invalid sampler component type {}", component_type); throw InvalidArgument("Invalid sampler component type {}", component_type);
} }
Id ImageType(EmitContext& ctx, const TextureDescriptor& desc, Id sampled_type) { Id ImageType(EmitContext& ctx, const TextureDescriptor& desc, Id sampled_type) {
const spv::ImageFormat format{spv::ImageFormat::Unknown}; const spv::ImageFormat format{spv::ImageFormat::Unknown};
>>>>>>> f8de99641 (feat(spirv): implement texture component type handling in SPIR-V backend)
const bool depth{desc.is_depth}; const bool depth{desc.is_depth};
const bool ms{desc.is_multisample}; const bool ms{desc.is_multisample};
switch (desc.type) { switch (desc.type) {
@@ -1406,7 +1407,6 @@ void EmitContext::DefineTextures(const Info& info, u32& binding, u32& scaling_in
.count = desc.count, .count = desc.count,
.is_multisample = desc.is_multisample, .is_multisample = desc.is_multisample,
.component_type = desc.component_type, .component_type = desc.component_type,
>>>>>>> f8de99641 (feat(spirv): implement texture component type handling in SPIR-V backend)
}); });
if (profile.supported_spirv >= 0x00010400) { if (profile.supported_spirv >= 0x00010400) {
interfaces.push_back(id); interfaces.push_back(id);