#version 450
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require
#extension GL_EXT_shader_8bit_storage : require
#if defined(GL_AMD_gpu_shader_half_float)
#extension GL_AMD_gpu_shader_half_float : require
#elif defined(GL_EXT_shader_explicit_arithmetic_types_float16)
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
#else
#error No extension available for FP16.
#endif
#extension GL_EXT_shader_16bit_storage : require
#extension GL_EXT_float_e5m2 : require
#extension GL_EXT_float_e4m3 : require
#extension GL_KHR_cooperative_matrix : require
#extension GL_KHR_memory_scope_semantics : require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(constant_id = 0) const floate5m2_t SPEC0 = floate5m2_t(5.0);
layout(constant_id = 1) const floate4m3_t SPEC1 = floate4m3_t(2.5);
layout(constant_id = 2) const floate4m3_t SPEC2 = floate4m3_t(-448.0);
layout(constant_id = 3) const floate4m3_t SPEC3 = floate4m3_t(448.0);
layout(constant_id = 4) const floate5m2_t SPEC4 = floate5m2_t(-57344.0);
layout(constant_id = 5) const floate5m2_t SPEC5 = floate5m2_t(57344.0);

layout(set = 0, binding = 0, std430) buffer SSBO
{
    floate5m2_t e5m2[4];
    floate4m3_t e4m3[4];
    fe5m2vec4 e5m2x4;
    fe5m2vec3 e5m2x3;
    fe5m2vec2 e5m2x2;
    fe4m3vec4 e4m3x4;
    fe4m3vec3 e4m3x3;
    fe4m3vec2 e4m3x2;
} ssbo;

void bitcasts()
{
    int8_t i8 = floate5m2BitsToIntEXT(ssbo.e5m2[0]);
    uint8_t u8 = floate5m2BitsToUintEXT(ssbo.e5m2[1]);
    i8 = floate4m3BitsToIntEXT(ssbo.e4m3[2]);
    u8 = floate4m3BitsToUintEXT(ssbo.e4m3[3]);
    floate5m2_t e5m2 = intBitsToFloate5m2EXT(i8);
    e5m2 = uintBitsToFloate5m2EXT(u8);
    floate4m3_t e4m3 = intBitsToFloate4m3EXT(i8);
    e4m3 = uintBitsToFloate4m3EXT(u8);
}

void conversions()
{
    int8_t i8 = int8_t(ssbo.e5m2[0]);
    uint8_t u8 = uint8_t(ssbo.e4m3[0]);
    float16_t f16 = float16_t(ssbo.e5m2x4.x);
    float f32 = float(ssbo.e4m3x4.y);
}

void saturated_conversions()
{
    floate5m2_t _89;
    saturatedConvertEXT(_89, float16_t(500.0));
    floate5m2_t e5m2 = _89;
    floate4m3_t _92;
    saturatedConvertEXT(_92, 500.0);
    floate4m3_t e4m3 = _92;
    coopmat<float16_t, gl_ScopeSubgroup, 16u, 16u, gl_MatrixUseA> m1;
    coopmat<floate4m3_t, gl_ScopeSubgroup, 16u, 16u, gl_MatrixUseA> _102;
    saturatedConvertEXT(_102, m1);
    coopmat<floate4m3_t, gl_ScopeSubgroup, 16u, 16u, gl_MatrixUseA> m0 = _102;
}

void main()
{
    bitcasts();
    conversions();
    saturated_conversions();
}

