early-access version 3501
This commit is contained in:
@@ -152,7 +152,8 @@ std::string ImageGatherSubpixelOffset(const IR::TextureInstInfo& info, std::stri
|
||||
return fmt::format("{}+vec2(0.001953125)/vec2(textureSize({}, 0))", coords, texture);
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::ColorCube:
|
||||
return fmt::format("vec3({0}.xy+vec2(0.001953125)/vec2(textureSize({1}, 0)),{0}.z)", coords, texture);
|
||||
return fmt::format("vec3({0}.xy+vec2(0.001953125)/vec2(textureSize({1}, 0)),{0}.z)", coords,
|
||||
texture);
|
||||
default:
|
||||
return std::string{coords};
|
||||
}
|
||||
|
@@ -266,30 +266,21 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info,
|
||||
Id coords) {
|
||||
// Apply a subpixel offset of 1/512 the texel size of the texture to ensure same rounding on
|
||||
// AMD hardware as on Maxwell or other Nvidia architectures.
|
||||
const auto calculate_offset{[&](size_t dim) -> std::array<Id, 2> {
|
||||
const auto calculate_coords{[&](size_t dim) {
|
||||
const Id nudge{ctx.Const(0x1p-9f)};
|
||||
const Id image_size{ctx.OpImageQuerySizeLod(ctx.U32[dim], texture, ctx.u32_zero_value)};
|
||||
const Id offset_x{ctx.OpFDiv(
|
||||
ctx.F32[1], nudge,
|
||||
ctx.OpConvertUToF(ctx.F32[1], ctx.OpCompositeExtract(ctx.U32[1], image_size, 0)))};
|
||||
const Id offset_y{ctx.OpFDiv(
|
||||
ctx.F32[1], nudge,
|
||||
ctx.OpConvertUToF(ctx.F32[1], ctx.OpCompositeExtract(ctx.U32[1], image_size, 1)))};
|
||||
return {ctx.OpFAdd(ctx.F32[1], ctx.OpCompositeExtract(ctx.F32[1], coords, 0), offset_x),
|
||||
ctx.OpFAdd(ctx.F32[1], ctx.OpCompositeExtract(ctx.F32[1], coords, 1), offset_y)};
|
||||
Id offset{dim == 2 ? ctx.ConstantComposite(ctx.F32[dim], nudge, nudge)
|
||||
: ctx.ConstantComposite(ctx.F32[dim], nudge, nudge, ctx.f32_zero_value)};
|
||||
offset = ctx.OpFDiv(ctx.F32[dim], offset, ctx.OpConvertUToF(ctx.F32[dim], image_size));
|
||||
return ctx.OpFAdd(ctx.F32[dim], coords, offset);
|
||||
}};
|
||||
switch (info.type) {
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect: {
|
||||
const auto offset{calculate_offset(2)};
|
||||
return ctx.OpCompositeConstruct(ctx.F32[2], offset[0], offset[1]);
|
||||
}
|
||||
case TextureType::Color2DRect:
|
||||
return calculate_coords(2);
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::ColorCube: {
|
||||
const auto offset{calculate_offset(3)};
|
||||
return ctx.OpCompositeConstruct(ctx.F32[3], offset[0], offset[1],
|
||||
ctx.OpCompositeExtract(ctx.F32[1], coords, 2));
|
||||
}
|
||||
case TextureType::ColorCube:
|
||||
return calculate_coords(3);
|
||||
default:
|
||||
return coords;
|
||||
}
|
||||
|
@@ -52,9 +52,9 @@ struct Profile {
|
||||
bool need_declared_frag_colors{};
|
||||
/// Prevents fast math optimizations that may cause inaccuracies
|
||||
bool need_fastmath_off{};
|
||||
/// Some GPU vendors use a lower fixed point format of 16.8 when calculating pixel coordinates
|
||||
/// in the ImageGather instruction than the Maxwell architecture does. Applying an offset does
|
||||
/// fix this mismatching rounding behaviour.
|
||||
/// Some GPU vendors use a different rounding precision when calculating texture pixel
|
||||
/// coordinates with the 16.8 format in the ImageGather instruction than the Maxwell
|
||||
/// architecture. Applying an offset does fix this mismatching rounding behaviour.
|
||||
bool need_gather_subpixel_offset{};
|
||||
|
||||
/// OpFClamp is broken and OpFMax + OpFMin should be used instead
|
||||
|
Reference in New Issue
Block a user