ytgui / temp

0 stars 0 forks source link

Vulkan 2: Mali Internal Implementation #70

Closed ytgui closed 5 years ago

ytgui commented 5 years ago

Basic VS I/O

#version 450

precision highp float;
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inColor;
layout (location = 0) out vec3 outColor;

void main()
{
  gl_Position = vec4(inPosition, 0.0);
  outColor = inColor;
}
!4 = distinct !{!"_18_inPosition", ...}
!17 = !{!4, i32 1, i32 0}
!8 = distinct !{!"gl_mali_XFB_Position", ...}
!23 = !{!8, i32 1, i32 1}

define void @__start() !current_variant_flags !35 !target_variants_flags !36 {
entry:
  ; ld inPosition by current vertex index
  %_1_ = call i32 @llvm.bifroxt.get.attribute.index(metadata !17)
  %_2_ = call i32 @llvm.bifroxt.get.vertex.index()
  %_2_1 = call i32 @llvm.bifroxt.get.instance.index()
  %_2_2 = call nsrnd <3 x float> @llvm.bifroxt.ld.attr.dtsel.v3f32(i32 %_2_, i32 %_2_1, i32 %_1_, i32 -1), !tbaa !37

  ; vec3 -> vec4
  %_52_ = shufflevector <3 x float> %_2_2, <3 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
  %_53_ = shufflevector <4 x float> %_52_, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 7>

  ; gl_Position
  %_36_ = call i32 @llvm.bifroxt.get.attribute.index(metadata !23)
  %_37_ = call i32 @llvm.bifroxt.get.vertex.index()
  %_37_3 = call i32 @llvm.bifroxt.get.instance.index()
  %_37_4 = call <3 x i32> @llvm.bifroxt.lea.attr.dtsel.f32(i32 %_37_, i32 %_37_3, i32 %_36_, i32 -1)
  call void @llvm.bifroxt.st.cvt.v4f32(<4 x float> %_53_, <3 x i32> %_37_4)

  ; ignore inColor, outColor, Viewport and other hardware depended features
  ret void
}

Basic FS I/O

#version 450

precision highp float;
layout (location = 0) in vec3 inColor;
layout (location = 0) out vec4 fragColor;

void main()
{
  fragColor = vec4(inColor, 1.0);
}
!3 = distinct !{!"_12_inColor", ...}
!16 = !{!3, i32 1, i32 1}

define void @__start() !current_variant_flags !14 !target_variants_flags !15 {
entry:
  ; inColor
  %_1_ = call i32 @llvm.bifroxt.get.attribute.index(metadata !16)
  %0 = call <3 x float> @llvm.bifroxt.ld.var.center.t.v3f32(i64 0, i32 %_1_)

  ; vec3 -> vec4
  %_27_ = shufflevector <3 x float> %0, <3 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
  %_28_ = shufflevector <4 x float> %_27_, <4 x float> <float 1.00e+00, float 1.00e+00, float 1.00e+00, float 1.00e+00>, <4 x i32> <i32 0, i32 1, i32 2, i32 7>

  ; fragColor -> blend
  call void @llvm.bifroxt.atest.f32(float 1.000000e+00)
  call void @llvm.bifroxt.blend.v4f32(<4 x float> %_28_, i32 0), !tbaa !17
  ret void
}
ytgui commented 5 years ago

FS UBO

#version 450

precision highp float;
layout (set = 0, binding = 0) uniform UBO
{
  vec4 inColor;
} ubo;
layout (location = 0) out vec4 fragColor;

void main()
{
  fragColor = vec4(ubo.inColor);
}
define void @__start() !current_variant_flags !15 !target_variants_flags !16 {
entry:
  ; ld ubo
  %_1_ = call i32 @llvm.bifroxt.get.buffer.of(metadata !3, i32 1)
  %_3_ = call i32 @llvm.bifroxt.default.uniform.buffer(metadata !3)
  %_3_1 = call i32 @llvm.bifroxt.get.uniform.buffer.offset.i32(metadata !3, i32 16)
  %_3_2 = add i32 %_3_1, 0
  %_3_3 = call nsrnd <4 x float> @llvm.bifroxt.ld.uniform.dtsel.v4f32(i32 %_3_, i32 %_3_2, i32 -1)

  ; ignore fragColor out
  ret void
}

CS Push Constant

Push constants is a way to quickly provide a small amount of uniform data to shaders. It should be much quicker than UBOs but a huge limitation is the size of data - spec requires 128 bytes to be available for a push constant range. Hardware vendors may support more, but compared to other means it is still very little (for example 256 bytes).


#version 450

precision highp float; layout (push_constant) uniform PushConstant { vec4 inColor; } pc; layout (location = 0) out vec4 fragColor;

void main() { fragColor = vec4(pc.inColor); }

```LLVM
define void @__start() !current_variant_flags !15 !target_variants_flags !16 {
entry:
  ; mali do the same to UBO
  %_1_ = call i32 @llvm.bifroxt.get.buffer.of(metadata !3, i32 1)
  %_3_ = call i32 @llvm.bifroxt.default.uniform.buffer(metadata !3)
  %_3_1 = call i32 @llvm.bifroxt.get.uniform.buffer.offset.i32(metadata !3, i32 16)
  %_3_2 = add i32 %_3_1, 0
  %_3_3 = call nsrnd <4 x float> @llvm.bifroxt.ld.uniform.dtsel.v4f32(i32 %_3_, i32 %_3_2, i32 -1)
  ret void
}

CS Image

#version 450

precision highp float;
layout (binding = 0, r16f) uniform highp image2D srcImg;
layout (binding = 1, r16f) uniform highp image2D dstImg;

void main()
{
  ivec2 index = ivec2(gl_GlobalInvocationID.x,
                      gl_GlobalInvocationID.y);
  vec4 value = imageLoad(srcImg, index);
  imageStore(dstImg, index, value);
}
define void @__start() !current_variant_flags !15 !target_variants_flags !16 {
entry:
  ; ignore useless ir
  %1 = call i32 @llvm.bifroxt.ld.img.v2i32(...)
  call i32 @llvm.bifroxt.st.img.v2i32(%1, ...)
  ret void
}

CS Buffer

ytgui commented 5 years ago

goto https://github.com/bosskwei/temp/issues/71