2
0
Эх сурвалжийг харах

Fix a bug and move Ui shader to HLSL

Panagiotis Christopoulos Charitos 2 жил өмнө
parent
commit
c52cc6eb88

+ 5 - 0
AnKi/Core/GpuMemoryPools.cpp

@@ -29,6 +29,11 @@ void UnifiedGeometryMemoryPool::init(HeapMemoryPool* pool, GrManager* gr, const
 	}
 
 	m_pool.init(gr, pool, buffUsage, classes, poolSize, "UnifiedGeometry", false);
+
+	// Allocate something dummy to force creating the GPU buffer
+	SegregatedListsGpuMemoryPoolToken token;
+	allocate(16, 4, token);
+	free(token);
 }
 
 void GpuSceneMemoryPool::init(HeapMemoryPool* pool, GrManager* gr, const ConfigSet& cfg)

+ 35 - 27
AnKi/Shaders/Ui.ankiprog

@@ -3,60 +3,68 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma anki hlsl
+
 #pragma anki mutator TEXTURE_TYPE 0 1 // 0: no tex, 1: rgba tex
 
-#pragma anki start vert
-#include <AnKi/Shaders/Common.glsl>
+#include <AnKi/Shaders/Common.hlsl>
 
-layout(location = 0) in Vec2 in_pos;
-layout(location = 1) in Vec4 in_col;
+struct VertIn
+{
+	[[vk::location(0)]] Vec2 m_position : POSITION;
+	[[vk::location(1)]] RVec4 m_color : COLOR;
 #if TEXTURE_TYPE > 0
-layout(location = 2) in Vec2 in_uv;
+	[[vk::location(2)]] Vec2 m_uv : TEXCOORD;
 #endif
+};
 
+struct VertOut
+{
 #if TEXTURE_TYPE > 0
-layout(location = 0) out Vec2 out_uv;
+	Vec2 m_uv : TEXCOORD;
 #endif
-layout(location = 1) out Vec4 out_col;
+	RVec4 m_color : COLOR;
+	Vec4 m_svPosition : SV_POSITION;
+};
+
+#pragma anki start vert
 
-layout(push_constant) uniform b_pc
+struct Uniforms
 {
-	Vec4 u_transform; // x: x scale, y: y scale, z: x transl, w: y transl
+	Vec4 m_transform; // x: x scale, y: y scale, z: x transl, w: y transl
 };
 
-void main()
+[[vk::push_constant]] ConstantBuffer<Uniforms> g_uniforms;
+
+VertOut main(VertIn input)
 {
+	VertOut output;
+
 #if TEXTURE_TYPE > 0
-	out_uv = in_uv;
+	output.m_uv = input.m_uv;
 #endif
-	out_col = in_col;
+	output.m_color = input.m_color;
 
-	const Vec2 pos = u_transform.xy * in_pos + u_transform.zw;
-	gl_Position = Vec4(pos, 0.0, 1.0);
+	const Vec2 pos = g_uniforms.m_transform.xy * input.m_position + g_uniforms.m_transform.zw;
+	output.m_svPosition = Vec4(pos, 0.0, 1.0);
+
+	return output;
 }
 #pragma anki end
 
 #pragma anki start frag
-#include <AnKi/Shaders/Common.glsl>
-
-#if TEXTURE_TYPE > 0
-layout(location = 0) in Vec2 in_uv;
-#endif
-layout(location = 1) in Vec4 in_col;
-
-layout(location = 0) out Vec4 out_col;
 
 #if TEXTURE_TYPE > 0
-layout(set = 0, binding = 0) uniform sampler u_trilinearRepeatSampler;
-layout(set = 0, binding = 1) uniform texture2D u_tex;
+[[vk::binding(0)]] SamplerState g_trilinearRepeatSampler;
+[[vk::binding(1)]] Texture2D g_tex;
 #endif
 
-void main()
+RVec4 main(VertOut input) : SV_TARGET0
 {
 #if TEXTURE_TYPE == 0
-	out_col = in_col;
+	return input.m_color;
 #elif TEXTURE_TYPE == 1
-	out_col = in_col * texture(u_tex, u_trilinearRepeatSampler, in_uv);
+	return input.m_color * g_tex.Sample(g_trilinearRepeatSampler, input.m_uv);
 #endif
 }