Add pack/unpack snorm8/unorm8.
This commit is contained in:
Родитель
6c7c680d01
Коммит
719ba63416
|
@ -0,0 +1,66 @@
|
|||
static float4 FP32Out;
|
||||
static uint UNORM8;
|
||||
static uint SNORM8;
|
||||
static uint UNORM8Out;
|
||||
static float4 FP32;
|
||||
static uint SNORM8Out;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
nointerpolation uint SNORM8 : TEXCOORD0;
|
||||
nointerpolation uint UNORM8 : TEXCOORD1;
|
||||
nointerpolation float4 FP32 : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 FP32Out : SV_Target0;
|
||||
uint UNORM8Out : SV_Target1;
|
||||
uint SNORM8Out : SV_Target2;
|
||||
};
|
||||
|
||||
uint SPIRV_Cross_packUnorm4x8(float4 value)
|
||||
{
|
||||
uint4 Packed = uint4(round(saturate(value) * 255.0));
|
||||
return Packed.x | (Packed.y << 8) | (Packed.z << 16) | (Packed.w << 24);
|
||||
}
|
||||
|
||||
float4 SPIRV_Cross_unpackUnorm4x8(uint value)
|
||||
{
|
||||
uint4 Packed = uint4(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, value >> 24);
|
||||
return float4(Packed) / 255.0;
|
||||
}
|
||||
|
||||
uint SPIRV_Cross_packSnorm4x8(float4 value)
|
||||
{
|
||||
int4 Packed = int4(round(clamp(value, -1.0, 1.0) * 127.0)) & 0xff;
|
||||
return uint(Packed.x | (Packed.y << 8) | (Packed.z << 16) | (Packed.w << 24));
|
||||
}
|
||||
|
||||
float4 SPIRV_Cross_unpackSnorm4x8(uint value)
|
||||
{
|
||||
int SignedValue = int(value);
|
||||
int4 Packed = int4(SignedValue << 24, SignedValue << 16, SignedValue << 8, SignedValue) >> 24;
|
||||
return clamp(float4(Packed) / 127.0, -1.0, 1.0);
|
||||
}
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
FP32Out = SPIRV_Cross_unpackUnorm4x8(UNORM8);
|
||||
FP32Out = SPIRV_Cross_unpackSnorm4x8(SNORM8);
|
||||
UNORM8Out = SPIRV_Cross_packUnorm4x8(FP32);
|
||||
SNORM8Out = SPIRV_Cross_packSnorm4x8(FP32);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
UNORM8 = stage_input.UNORM8;
|
||||
SNORM8 = stage_input.SNORM8;
|
||||
FP32 = stage_input.FP32;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FP32Out = FP32Out;
|
||||
stage_output.UNORM8Out = UNORM8Out;
|
||||
stage_output.SNORM8Out = SNORM8Out;
|
||||
return stage_output;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
static float4 FP32Out;
|
||||
static uint UNORM8;
|
||||
static uint SNORM8;
|
||||
static uint UNORM8Out;
|
||||
static float4 FP32;
|
||||
static uint SNORM8Out;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
nointerpolation uint SNORM8 : TEXCOORD0;
|
||||
nointerpolation uint UNORM8 : TEXCOORD1;
|
||||
nointerpolation float4 FP32 : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 FP32Out : SV_Target0;
|
||||
uint UNORM8Out : SV_Target1;
|
||||
uint SNORM8Out : SV_Target2;
|
||||
};
|
||||
|
||||
uint SPIRV_Cross_packUnorm4x8(float4 value)
|
||||
{
|
||||
uint4 Packed = uint4(round(saturate(value) * 255.0));
|
||||
return Packed.x | (Packed.y << 8) | (Packed.z << 16) | (Packed.w << 24);
|
||||
}
|
||||
|
||||
float4 SPIRV_Cross_unpackUnorm4x8(uint value)
|
||||
{
|
||||
uint4 Packed = uint4(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, value >> 24);
|
||||
return float4(Packed) / 255.0;
|
||||
}
|
||||
|
||||
uint SPIRV_Cross_packSnorm4x8(float4 value)
|
||||
{
|
||||
int4 Packed = int4(round(clamp(value, -1.0, 1.0) * 127.0)) & 0xff;
|
||||
return uint(Packed.x | (Packed.y << 8) | (Packed.z << 16) | (Packed.w << 24));
|
||||
}
|
||||
|
||||
float4 SPIRV_Cross_unpackSnorm4x8(uint value)
|
||||
{
|
||||
int SignedValue = int(value);
|
||||
int4 Packed = int4(SignedValue << 24, SignedValue << 16, SignedValue << 8, SignedValue) >> 24;
|
||||
return clamp(float4(Packed) / 127.0, -1.0, 1.0);
|
||||
}
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
FP32Out = SPIRV_Cross_unpackUnorm4x8(UNORM8);
|
||||
FP32Out = SPIRV_Cross_unpackSnorm4x8(SNORM8);
|
||||
UNORM8Out = SPIRV_Cross_packUnorm4x8(FP32);
|
||||
SNORM8Out = SPIRV_Cross_packSnorm4x8(FP32);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
UNORM8 = stage_input.UNORM8;
|
||||
SNORM8 = stage_input.SNORM8;
|
||||
FP32 = stage_input.FP32;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FP32Out = FP32Out;
|
||||
stage_output.UNORM8Out = UNORM8Out;
|
||||
stage_output.SNORM8Out = SNORM8Out;
|
||||
return stage_output;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0) flat in uint SNORM8;
|
||||
layout(location = 1) flat in uint UNORM8;
|
||||
layout(location = 2) flat in vec4 FP32;
|
||||
layout(location = 0) out vec4 FP32Out;
|
||||
layout(location = 1) out uint UNORM8Out;
|
||||
layout(location = 2) out uint SNORM8Out;
|
||||
|
||||
void main()
|
||||
{
|
||||
FP32Out = unpackUnorm4x8(UNORM8);
|
||||
FP32Out = unpackSnorm4x8(SNORM8);
|
||||
UNORM8Out = packUnorm4x8(FP32);
|
||||
SNORM8Out = packSnorm4x8(FP32);
|
||||
}
|
|
@ -1186,6 +1186,7 @@ void CompilerHLSL::emit_resources()
|
|||
|
||||
if (requires_fp16_packing)
|
||||
{
|
||||
// HLSL does not pack into a single word sadly :(
|
||||
statement("uint SPIRV_Cross_packHalf2x16(float2 value)");
|
||||
begin_scope();
|
||||
statement("uint2 Packed = f32tof16(value);");
|
||||
|
@ -1199,6 +1200,41 @@ void CompilerHLSL::emit_resources()
|
|||
end_scope();
|
||||
statement("");
|
||||
}
|
||||
|
||||
if (requires_unorm8_packing)
|
||||
{
|
||||
statement("uint SPIRV_Cross_packUnorm4x8(float4 value)");
|
||||
begin_scope();
|
||||
statement("uint4 Packed = uint4(round(saturate(value) * 255.0));");
|
||||
statement("return Packed.x | (Packed.y << 8) | (Packed.z << 16) | (Packed.w << 24);");
|
||||
end_scope();
|
||||
statement("");
|
||||
|
||||
statement("float4 SPIRV_Cross_unpackUnorm4x8(uint value)");
|
||||
begin_scope();
|
||||
statement("uint4 Packed = uint4(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, value >> 24);");
|
||||
statement("return float4(Packed) / 255.0;");
|
||||
end_scope();
|
||||
statement("");
|
||||
}
|
||||
|
||||
if (requires_snorm8_packing)
|
||||
{
|
||||
statement("uint SPIRV_Cross_packSnorm4x8(float4 value)");
|
||||
begin_scope();
|
||||
statement("int4 Packed = int4(round(clamp(value, -1.0, 1.0) * 127.0)) & 0xff;");
|
||||
statement("return uint(Packed.x | (Packed.y << 8) | (Packed.z << 16) | (Packed.w << 24));");
|
||||
end_scope();
|
||||
statement("");
|
||||
|
||||
statement("float4 SPIRV_Cross_unpackSnorm4x8(uint value)");
|
||||
begin_scope();
|
||||
statement("int SignedValue = int(value);");
|
||||
statement("int4 Packed = int4(SignedValue << 24, SignedValue << 16, SignedValue << 8, SignedValue) >> 24;");
|
||||
statement("return clamp(float4(Packed) / 127.0, -1.0, 1.0);");
|
||||
end_scope();
|
||||
statement("");
|
||||
}
|
||||
}
|
||||
|
||||
string CompilerHLSL::layout_for_member(const SPIRType &type, uint32_t index)
|
||||
|
@ -2243,6 +2279,42 @@ void CompilerHLSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop,
|
|||
emit_unary_func_op(result_type, id, args[0], "SPIRV_Cross_unpackHalf2x16");
|
||||
break;
|
||||
|
||||
case GLSLstd450PackSnorm4x8:
|
||||
if (!requires_snorm8_packing)
|
||||
{
|
||||
requires_snorm8_packing = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
emit_unary_func_op(result_type, id, args[0], "SPIRV_Cross_packSnorm4x8");
|
||||
break;
|
||||
|
||||
case GLSLstd450UnpackSnorm4x8:
|
||||
if (!requires_snorm8_packing)
|
||||
{
|
||||
requires_snorm8_packing = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
emit_unary_func_op(result_type, id, args[0], "SPIRV_Cross_unpackSnorm4x8");
|
||||
break;
|
||||
|
||||
case GLSLstd450PackUnorm4x8:
|
||||
if (!requires_unorm8_packing)
|
||||
{
|
||||
requires_unorm8_packing = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
emit_unary_func_op(result_type, id, args[0], "SPIRV_Cross_packUnorm4x8");
|
||||
break;
|
||||
|
||||
case GLSLstd450UnpackUnorm4x8:
|
||||
if (!requires_unorm8_packing)
|
||||
{
|
||||
requires_unorm8_packing = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
emit_unary_func_op(result_type, id, args[0], "SPIRV_Cross_unpackUnorm4x8");
|
||||
break;
|
||||
|
||||
default:
|
||||
CompilerGLSL::emit_glsl_op(result_type, id, eop, args, count);
|
||||
break;
|
||||
|
|
|
@ -117,6 +117,8 @@ private:
|
|||
bool requires_op_fmod = false;
|
||||
bool requires_textureProj = false;
|
||||
bool requires_fp16_packing = false;
|
||||
bool requires_unorm8_packing = false;
|
||||
bool requires_snorm8_packing = false;
|
||||
uint64_t required_textureSizeVariants = 0;
|
||||
void require_texture_query_variant(const SPIRType &type);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче