Skip to content

Commit fc691b0

Browse files
committed
test: add tests for new semantics
1 parent 79889f7 commit fc691b0

File tree

7 files changed

+112
-8
lines changed

7 files changed

+112
-8
lines changed

librashader-runtime-d3d11/tests/hello_triangle/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub mod d3d11_hello_triangle {
295295
let filter = unsafe {
296296
FilterChainD3D11::load_from_path(
297297
filter,
298-
ShaderFeatures::NONE,
298+
ShaderFeatures::all(),
299299
&device,
300300
filter_options,
301301
)
@@ -583,13 +583,13 @@ pub mod d3d11_hello_triangle {
583583
None,
584584
&srv,
585585
&Viewport {
586-
x: 100f32,
587-
y: 100f32,
586+
x: 0f32,
587+
y: 0f32,
588588
output,
589589
mvp: None,
590590
size: Size {
591-
width: size.width - 200,
592-
height: size.height - 200,
591+
width: size.width,
592+
height: size.height,
593593
},
594594
},
595595
resources.frame_count,

librashader-runtime-d3d11/tests/triangle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use librashader_runtime_d3d11::options::FilterChainOptionsD3D11;
1717
// const FILTER_PATH: &str = "../test/slang-shaders/test/history.slangp";
1818
// const FILTER_PATH: &str = "../test/shaders_slang/test/feedback.slangp";
1919

20-
const FILTER_PATH: &str = "../test/shaders_slang/crt/crt-guest-advanced-ntsc.slangp";
20+
const FILTER_PATH: &str = "../test/aspect.slangp";
2121
const IMAGE_PATH: &str = "../triangle.png";
2222
#[test]
2323
fn triangle_d3d11_args() {

librashader-runtime-vk/tests/hello_triangle/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ impl VulkanWindow {
263263
current_subframe: 1,
264264
rotation: 0,
265265
total_subframes: 1,
266+
aspect_ratio: 0.0,
267+
..Default::default()
266268
}),
267269
)
268270
.unwrap();

librashader-runtime-vk/tests/triangle.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod hello_triangle;
22

33
use hello_triangle::vulkan_base::VulkanBase;
4+
use librashader_common::shader_features::ShaderFeatures;
45
use librashader_runtime_vk::options::FilterChainOptionsVulkan;
56
use librashader_runtime_vk::FilterChainVulkan;
67

@@ -11,7 +12,8 @@ fn triangle_vk() {
1112

1213
unsafe {
1314
let filter = FilterChainVulkan::load_from_path(
14-
"../test/shaders_slang/test/feedback.slangp",
15+
"../test/aspect.slangp",
16+
ShaderFeatures::all(),
1517
// "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
1618
// "../test/Mega_Bezel_Packs/Duimon-Mega-Bezel/Presets/Advanced/Nintendo_GBA_SP/GBA_SP-[ADV]-[LCD-GRID]-[Night].slangp",
1719
&base,

test/aspect.slang

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#version 450
2+
3+
layout(push_constant) uniform Push
4+
{
5+
vec4 SourceSize;
6+
vec4 OriginalSize;
7+
vec4 OutputSize;
8+
uint FrameCount;
9+
uint Rotation;
10+
#ifdef _HAS_ORIGINALASPECT_UNIFORMS
11+
float OriginalAspect;
12+
float OriginalAspectRotated;
13+
#endif
14+
15+
16+
17+
} params;
18+
19+
layout(std140, set = 0, binding = 0) uniform UBO
20+
{
21+
mat4 MVP;
22+
} global;
23+
24+
#pragma stage vertex
25+
layout(location = 0) in vec4 Position;
26+
layout(location = 1) in vec2 TexCoord;
27+
layout(location = 0) out vec2 vTexCoord;
28+
29+
void main()
30+
{
31+
gl_Position = global.MVP * Position;
32+
vTexCoord = TexCoord;
33+
}
34+
35+
#pragma stage fragment
36+
layout(location = 0) in vec2 vTexCoord;
37+
layout(location = 0) out vec4 FragColor;
38+
39+
float DigitBin( const int x )
40+
{
41+
return x==0?480599.0:x==1?139810.0:x==2?476951.0:x==3?476999.0:x==4?350020.0:x==5?464711.0:x==6?464727.0:x==7?476228.0:x==8?481111.0:x==9?481095.0:0.0;
42+
}
43+
44+
float PrintValue( vec2 vStringCoords, float fValue, float fMaxDigits, float fDecimalPlaces )
45+
{
46+
if ((vStringCoords.y < 0.0) || (vStringCoords.y >= 1.0)) return 0.0;
47+
48+
bool bNeg = ( fValue < 0.0 );
49+
fValue = abs(fValue);
50+
51+
float fLog10Value = log2(abs(fValue)) / log2(10.0);
52+
float fBiggestIndex = max(floor(fLog10Value), 0.0);
53+
float fDigitIndex = fMaxDigits - floor(vStringCoords.x);
54+
float fCharBin = 0.0;
55+
if(fDigitIndex > (-fDecimalPlaces - 1.01)) {
56+
if(fDigitIndex > fBiggestIndex) {
57+
if((bNeg) && (fDigitIndex < (fBiggestIndex+1.5))) fCharBin = 1792.0;
58+
} else {
59+
if(fDigitIndex == -1.0) {
60+
if(fDecimalPlaces > 0.0) fCharBin = 2.0;
61+
} else {
62+
float fReducedRangeValue = fValue;
63+
if(fDigitIndex < 0.0) { fReducedRangeValue = fract( fValue ); fDigitIndex += 1.0; }
64+
float fDigitValue = (abs(fReducedRangeValue / (pow(10.0, fDigitIndex))));
65+
fCharBin = DigitBin(int(floor(mod(fDigitValue, 10.0))));
66+
}
67+
}
68+
}
69+
return floor(mod((fCharBin / pow(2.0, floor(fract(vStringCoords.x) * 4.0) + (floor(vStringCoords.y * 5.0) * 4.0))), 2.0));
70+
}
71+
72+
vec3 PrintValueVec3( vec2 vStringCoords, vec2 FragCoord, float fValue, float fMaxDigits, float fDecimalPlaces ) {
73+
vec3 vColour = vec3(0.0);
74+
vec2 vFontSize = vec2(8.0, 15.0);
75+
vec2 vPixelCoord1 = vStringCoords;
76+
FragCoord.y = (vFontSize.y*2.0) - FragCoord.y;
77+
float customDigit = PrintValue( ( FragCoord - vPixelCoord1 ) / vFontSize, fValue, fMaxDigits, fDecimalPlaces);
78+
vColour = mix( vColour, vec3(0.0, 1.0, 1.0), customDigit);
79+
return vColour;
80+
}
81+
82+
83+
void main() {
84+
vec2 FragCoord = vTexCoord * params.OutputSize.xy;
85+
float f0 = float(params.Rotation);
86+
float f1 = -1 ;
87+
float f2 = -1 ;
88+
#ifdef _HAS_ORIGINALASPECT_UNIFORMS
89+
f1 = params.OriginalAspect;
90+
f2 = params.OriginalAspectRotated;
91+
#endif
92+
vec3 v0 = PrintValueVec3( vec2(50, -10) , FragCoord, f0, 3, 3);
93+
vec3 v1 = PrintValueVec3( vec2(100, -10), FragCoord, f1, 3, 3);
94+
vec3 v2 = PrintValueVec3( vec2(150, -10), FragCoord, f2, 3, 3);
95+
FragColor.rgb = v0+v1+v2;
96+
}

test/aspect.slangp

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
shaders = 1
2+
3+
shader0 = aspect.slang
4+
filter_linear0 = true

test/shaders_slang

Submodule shaders_slang updated 188 files

0 commit comments

Comments
 (0)