Commit 5c883d3c by Corentin Wallez Committed by Corentin Wallez

Clamp _SNORM formats to -1.0

Following the Vulkan 1.1 specification Section 2.9.1. "Conversion from Normalized Fixed-Point to Floating-Point": Note that while zero is exactly expressible in this representation, one value (-128 in the example) is outside the representable range, and must be clamped before use. https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#fundamentals-fixedfpconv Bug: dawn:283 Change-Id: Id548c6d67132ac36f33bc020954c5511de624ffc Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43648 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarCorentin Wallez <cwallez@google.com>
parent 3cfa8e28
...@@ -183,10 +183,10 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 uvw[4], Float ...@@ -183,10 +183,10 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 uvw[4], Float
case VK_FORMAT_R8G8_SNORM: case VK_FORMAT_R8G8_SNORM:
case VK_FORMAT_R8G8B8A8_SNORM: case VK_FORMAT_R8G8B8A8_SNORM:
case VK_FORMAT_A8B8G8R8_SNORM_PACK32: case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
c.x *= Float4(1.0f / 0x7F00); c.x = Max(c.x * Float4(1.0f / 0x7F00), Float4(-1.0f));
c.y *= Float4(1.0f / 0x7F00); c.y = Max(c.y * Float4(1.0f / 0x7F00), Float4(-1.0f));
c.z *= Float4(1.0f / 0x7F00); c.z = Max(c.z * Float4(1.0f / 0x7F00), Float4(-1.0f));
c.w *= Float4(1.0f / 0x7F00); c.w = Max(c.w * Float4(1.0f / 0x7F00), Float4(-1.0f));
break; break;
case VK_FORMAT_R8_UNORM: case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R8G8_UNORM: case VK_FORMAT_R8G8_UNORM:
...@@ -237,10 +237,10 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 uvw[4], Float ...@@ -237,10 +237,10 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 uvw[4], Float
case VK_FORMAT_R8G8_SNORM: case VK_FORMAT_R8G8_SNORM:
case VK_FORMAT_R8G8B8A8_SNORM: case VK_FORMAT_R8G8B8A8_SNORM:
case VK_FORMAT_A8B8G8R8_SNORM_PACK32: case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
c.x = Float4(cs.x) * Float4(1.0f / 0x7F00); c.x = Max(Float4(cs.x) * Float4(1.0f / 0x7F00), Float4(-1.0f));
c.y = Float4(cs.y) * Float4(1.0f / 0x7F00); c.y = Max(Float4(cs.y) * Float4(1.0f / 0x7F00), Float4(-1.0f));
c.z = Float4(cs.z) * Float4(1.0f / 0x7F00); c.z = Max(Float4(cs.z) * Float4(1.0f / 0x7F00), Float4(-1.0f));
c.w = Float4(cs.w) * Float4(1.0f / 0x7F00); c.w = Max(Float4(cs.w) * Float4(1.0f / 0x7F00), Float4(-1.0f));
break; break;
case VK_FORMAT_R8_UNORM: case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R8G8_UNORM: case VK_FORMAT_R8G8_UNORM:
......
...@@ -269,10 +269,10 @@ Vector4f VertexRoutine::readStream(Pointer<Byte> &buffer, UInt &stride, const St ...@@ -269,10 +269,10 @@ Vector4f VertexRoutine::readStream(Pointer<Byte> &buffer, UInt &stride, const St
transpose4xN(v.x, v.y, v.z, v.w, componentCount); transpose4xN(v.x, v.y, v.z, v.w, componentCount);
if(componentCount >= 1) v.x *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)); if(componentCount >= 1) v.x = Max(v.x * *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)), Float4(-1.0f));
if(componentCount >= 2) v.y *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)); if(componentCount >= 2) v.y = Max(v.y * *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)), Float4(-1.0f));
if(componentCount >= 3) v.z *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)); if(componentCount >= 3) v.z = Max(v.z * *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)), Float4(-1.0f));
if(componentCount >= 4) v.w *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)); if(componentCount >= 4) v.w = Max(v.w * *Pointer<Float4>(constants + OFFSET(Constants, unscaleSByte)), Float4(-1.0f));
break; break;
case VK_FORMAT_R8_SINT: case VK_FORMAT_R8_SINT:
case VK_FORMAT_R8G8_SINT: case VK_FORMAT_R8G8_SINT:
...@@ -295,10 +295,10 @@ Vector4f VertexRoutine::readStream(Pointer<Byte> &buffer, UInt &stride, const St ...@@ -295,10 +295,10 @@ Vector4f VertexRoutine::readStream(Pointer<Byte> &buffer, UInt &stride, const St
transpose4xN(v.x, v.y, v.z, v.w, componentCount); transpose4xN(v.x, v.y, v.z, v.w, componentCount);
if(componentCount >= 1) v.x *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)); if(componentCount >= 1) v.x = Max(v.x * *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)), Float4(-1.0f));
if(componentCount >= 2) v.y *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)); if(componentCount >= 2) v.y = Max(v.y * *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)), Float4(-1.0f));
if(componentCount >= 3) v.z *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)); if(componentCount >= 3) v.z = Max(v.z * *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)), Float4(-1.0f));
if(componentCount >= 4) v.w *= *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)); if(componentCount >= 4) v.w = Max(v.w * *Pointer<Float4>(constants + OFFSET(Constants, unscaleShort)), Float4(-1.0f));
break; break;
case VK_FORMAT_R16_SINT: case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16G16_SINT: case VK_FORMAT_R16G16_SINT:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment