Skip to content

Commit

Permalink
test: add tests for new semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Nov 19, 2024
1 parent 5c23e58 commit 860d945
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 8 deletions.
10 changes: 5 additions & 5 deletions librashader-runtime-d3d11/tests/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub mod d3d11_hello_triangle {
let filter = unsafe {
FilterChainD3D11::load_from_path(
filter,
ShaderFeatures::NONE,
ShaderFeatures::all(),
&device,
filter_options,
)
Expand Down Expand Up @@ -583,13 +583,13 @@ pub mod d3d11_hello_triangle {
None,
&srv,
&Viewport {
x: 100f32,
y: 100f32,
x: 0f32,
y: 0f32,
output,
mvp: None,
size: Size {
width: size.width - 200,
height: size.height - 200,
width: size.width,
height: size.height,
},
},
resources.frame_count,
Expand Down
2 changes: 1 addition & 1 deletion librashader-runtime-d3d11/tests/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use librashader_runtime_d3d11::options::FilterChainOptionsD3D11;
// const FILTER_PATH: &str = "../test/slang-shaders/test/history.slangp";
// const FILTER_PATH: &str = "../test/shaders_slang/test/feedback.slangp";

const FILTER_PATH: &str = "../test/shaders_slang/crt/crt-guest-advanced-ntsc.slangp";
const FILTER_PATH: &str = "../test/aspect.slangp";
const IMAGE_PATH: &str = "../triangle.png";
#[test]
fn triangle_d3d11_args() {
Expand Down
2 changes: 2 additions & 0 deletions librashader-runtime-vk/tests/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ impl VulkanWindow {
current_subframe: 1,
rotation: 0,
total_subframes: 1,
aspect_ratio: 0.0,
..Default::default()
}),
)
.unwrap();
Expand Down
4 changes: 3 additions & 1 deletion librashader-runtime-vk/tests/triangle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod hello_triangle;

use hello_triangle::vulkan_base::VulkanBase;
use librashader_common::shader_features::ShaderFeatures;
use librashader_runtime_vk::options::FilterChainOptionsVulkan;
use librashader_runtime_vk::FilterChainVulkan;

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

unsafe {
let filter = FilterChainVulkan::load_from_path(
"../test/shaders_slang/test/feedback.slangp",
"../test/aspect.slangp",
ShaderFeatures::all(),
// "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
// "../test/Mega_Bezel_Packs/Duimon-Mega-Bezel/Presets/Advanced/Nintendo_GBA_SP/GBA_SP-[ADV]-[LCD-GRID]-[Night].slangp",
&base,
Expand Down
96 changes: 96 additions & 0 deletions test/aspect.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#version 450

layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
uint Rotation;
#ifdef _HAS_ORIGINALASPECT_UNIFORMS
float OriginalAspect;
float OriginalAspectRotated;
#endif



} params;

layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;

#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;

void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}

#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;

float DigitBin( const int x )
{
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;
}

float PrintValue( vec2 vStringCoords, float fValue, float fMaxDigits, float fDecimalPlaces )
{
if ((vStringCoords.y < 0.0) || (vStringCoords.y >= 1.0)) return 0.0;

bool bNeg = ( fValue < 0.0 );
fValue = abs(fValue);

float fLog10Value = log2(abs(fValue)) / log2(10.0);
float fBiggestIndex = max(floor(fLog10Value), 0.0);
float fDigitIndex = fMaxDigits - floor(vStringCoords.x);
float fCharBin = 0.0;
if(fDigitIndex > (-fDecimalPlaces - 1.01)) {
if(fDigitIndex > fBiggestIndex) {
if((bNeg) && (fDigitIndex < (fBiggestIndex+1.5))) fCharBin = 1792.0;
} else {
if(fDigitIndex == -1.0) {
if(fDecimalPlaces > 0.0) fCharBin = 2.0;
} else {
float fReducedRangeValue = fValue;
if(fDigitIndex < 0.0) { fReducedRangeValue = fract( fValue ); fDigitIndex += 1.0; }
float fDigitValue = (abs(fReducedRangeValue / (pow(10.0, fDigitIndex))));
fCharBin = DigitBin(int(floor(mod(fDigitValue, 10.0))));
}
}
}
return floor(mod((fCharBin / pow(2.0, floor(fract(vStringCoords.x) * 4.0) + (floor(vStringCoords.y * 5.0) * 4.0))), 2.0));
}

vec3 PrintValueVec3( vec2 vStringCoords, vec2 FragCoord, float fValue, float fMaxDigits, float fDecimalPlaces ) {
vec3 vColour = vec3(0.0);
vec2 vFontSize = vec2(8.0, 15.0);
vec2 vPixelCoord1 = vStringCoords;
FragCoord.y = (vFontSize.y*2.0) - FragCoord.y;
float customDigit = PrintValue( ( FragCoord - vPixelCoord1 ) / vFontSize, fValue, fMaxDigits, fDecimalPlaces);
vColour = mix( vColour, vec3(0.0, 1.0, 1.0), customDigit);
return vColour;
}


void main() {
vec2 FragCoord = vTexCoord * params.OutputSize.xy;
float f0 = float(params.Rotation);
float f1 = -1 ;
float f2 = -1 ;
#ifdef _HAS_ORIGINALASPECT_UNIFORMS
f1 = params.OriginalAspect;
f2 = params.OriginalAspectRotated;
#endif
vec3 v0 = PrintValueVec3( vec2(50, -10) , FragCoord, f0, 3, 3);
vec3 v1 = PrintValueVec3( vec2(100, -10), FragCoord, f1, 3, 3);
vec3 v2 = PrintValueVec3( vec2(150, -10), FragCoord, f2, 3, 3);
FragColor.rgb = v0+v1+v2;
}
4 changes: 4 additions & 0 deletions test/aspect.slangp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
shaders = 1

shader0 = aspect.slang
filter_linear0 = true
2 changes: 1 addition & 1 deletion test/shaders_slang
Submodule shaders_slang updated 188 files

0 comments on commit 860d945

Please sign in to comment.