From 2330e93b16064a9f4a50acfff68cfc4991665a1a Mon Sep 17 00:00:00 2001 From: Matthew Hoffman Date: Wed, 24 Jan 2024 15:11:28 -0800 Subject: [PATCH 1/3] [SGS] Adds initial SGSR support. Brightness is not quite right, but otherwise seeems fine --- .../SnapdragonSuperResolution.h | 41 ++++ .../shaders/SnapdragonSuperResolution.dshl | 206 ++++++++++++++++++ samples/testGI/prog/shaders/shadersList.blk | 2 + samples/testGI/prog/test_app.cpp | 52 ++++- 4 files changed, 298 insertions(+), 3 deletions(-) create mode 100644 prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h create mode 100644 prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl diff --git a/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h b/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h new file mode 100644 index 000000000..2400541b1 --- /dev/null +++ b/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h @@ -0,0 +1,41 @@ +#pragma once +#include +#include +#include +#include +#include <3d/dag_drv3d.h> + +class SnapdragonSuperResolution : public PostFxRenderer +{ +public: + SnapdragonSuperResolution() : PostFxRenderer("SnapdragonSuperResolution") + { + viewport[0] = 0.f; + viewport[1] = 0.f; + viewport[2] = 0.f; + viewport[3] = 0.f; + } + + ~SnapdragonSuperResolution() {} + + inline void SetViewport(int32_t x, int32_t y) + { + viewport[0] = (float)x; + viewport[1] = (float)y; + viewport[2] = viewport[0] != 0.f ? (1.f / viewport[0]) : 0.f; + viewport[3] = viewport[1] != 0.f ? (1.f / viewport[1]) : 0.f; + } + + inline void render(const ManagedTex &input, BaseTexture* output) + { + Color4 viewportData = Color4(viewport); + + d3d::set_render_target(output, 0); + ShaderGlobal::set_texture(get_shader_variable_id("snapdragon_super_resolution_input"), input); + ShaderGlobal::set_color4(get_shader_variable_id("snapdragon_super_resolution_ViewportInfo"), viewportData); + PostFxRenderer::render(); + } + +private: + float viewport[4]; +}; diff --git a/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl b/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl new file mode 100644 index 000000000..def03c58a --- /dev/null +++ b/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl @@ -0,0 +1,206 @@ +//============================================================================================================ +// +// +// Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved. +// SPDX-License-Identifier: BSD-3-Clause +// +//============================================================================================================ + +include "shader_global.dshl" + +float4 snapdragon_super_resolution_ViewportInfo; +texture snapdragon_super_resolution_input; + +shader SnapdragonSuperResolution +{ + USE_POSTFX_VERTEX_POSITIONS() + z_test = false; + z_write = false; + cull_mode = none; + + hlsl { + struct VsOutput + { + VS_OUT_POSITION(pos) + float2 texcoord : TEXCOORD0; + }; + } + + hlsl(vs) { + VsOutput SnapdragonSUperResolution_vs(uint vertex_id : SV_VertexID) + { + VsOutput output; + float2 pos = getPostfxVertexPositionById(vertex_id); + output.pos = float4(pos.xy, 1, 1); + output.texcoord = pos*float2(0.5,-0.5) + float2(0.5, 0.5); + return output; + } + } + + (ps) + { + ViewportInfo@f4 = snapdragon_super_resolution_ViewportInfo; + snapdragon_super_resolution_input@smp2d = snapdragon_super_resolution_input; + } + + hlsl(ps) { + #include + //////////////////////// + // USER CONFIGURATION // + //////////////////////// + + /* + * Operation modes: + * RGBA -> 1 + * RGBY -> 3 + * LERP -> 4 + */ + #define OperationMode 1 + + #define EdgeThreshold 8.0/255.0 + + #define EdgeSharpness 2.0 + + half simple_luma_tonemap(half luma, half exposure) { return rcp(luma * exposure + 1.0); } + + half simple_luma_tonemap_inv(half luma, half exposure) { return rcp(max(1.0 - luma * exposure, 0.001)); } + + half fastLanczos2(half x) + { + half wA = x-4.0; + half wB = x*wA-wA; + wA *= wA; + return wB*wA; + } + + half2 weightY(half dx, half dy,half c, half std) + { + half x = ((dx*dx)+(dy* dy))* 0.55 + clamp(abs(c)*std, 0.0, 1.0); + half w = fastLanczos2(x); + return half2(w, w * c); + } + + half4 SGSRRH(float2 p) + { + half4 res = snapdragon_super_resolution_input.GatherRed(snapdragon_super_resolution_input_samplerstate, p); + return res; + } + half4 SGSRGH(float2 p) + { + half4 res = snapdragon_super_resolution_input.GatherGreen(snapdragon_super_resolution_input_samplerstate, p); + return res; + } + half4 SGSRBH(float2 p) + { + half4 res = snapdragon_super_resolution_input.GatherBlue(snapdragon_super_resolution_input_samplerstate, p); + return res; + } + half4 SGSRAH(float2 p) + { + half4 res = snapdragon_super_resolution_input.GatherAlpha(snapdragon_super_resolution_input_samplerstate, p); + return res; + } + half4 SGSRRGBH(float2 p) + { + half4 res = snapdragon_super_resolution_input.SampleLevel(snapdragon_super_resolution_input_samplerstate, p, 0); + return res; + } + + half4 SGSRH(float2 p, uint channel) + { + if (channel == 0) + return SGSRRH(p); + if (channel == 1) + return SGSRGH(p); + if (channel == 2) + return SGSRBH(p); + return SGSRAH(p); + } + + float4 SnapdragonSUperResolution_ps( VsOutput input) : SV_Target0 + { + int mode = OperationMode; + half edgeThreshold = EdgeThreshold; + half edgeSharpness = EdgeSharpness; + + half4 color = SGSRRGBH(input.texcoord.xy).xyzw; + half originalAlpha = color.w; + //if(mode == 1) + // color.xyz = SGSRRGBH(input.texcoord.xy).xyz; //tex2Dlod(snapdragon_super_resolution_input,input.texcoord.xy,0.0).xyz; + //else + // color.xyzw = SGSRRGBH(input.texcoord.xy).xyzw; //tex2Dlod(snapdragon_super_resolution_input,input.texcoord.xy,0.0).xyzw; + + float xCenter; + xCenter = abs(input.texcoord.x+-0.5); + float yCenter; + yCenter = abs(input.texcoord.y+-0.5); + + //todo: config the SR region based on needs + //if ( mode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4) + if ( mode!=4) + { + float2 imgCoord = ((input.texcoord.xy*ViewportInfo.zw)+half2(-0.5,0.5)); + float2 imgCoordPixel = floor(imgCoord); + float2 coord = (imgCoordPixel*ViewportInfo.xy); + half2 pl = (imgCoord+(-imgCoordPixel)); + half4 left = SGSRH(coord, mode); + + half edgeVote = abs(left.z - left.y) + abs(color[mode] - left.y) + abs(color[mode] - left.z) ; + if(edgeVote > edgeThreshold) + { + coord.x += ViewportInfo.x; + + half4 right = SGSRH(coord + float2(ViewportInfo.x, 0.0), mode); + half4 upDown; + upDown.xy = SGSRH(coord + float2(0.0, -ViewportInfo.y), mode).wz; + upDown.zw = SGSRH(coord + float2(0.0, ViewportInfo.y), mode).yx; + + half mean = (left.y+left.z+right.x+right.w)*0.25; + left = left - half4(mean, mean, mean, mean); + right = right - half4(mean, mean, mean, mean); + upDown = upDown - half4(mean, mean, mean, mean); + color.w =color[mode] - mean; + + half sum = (((((abs(left.x)+abs(left.y))+abs(left.z))+abs(left.w))+(((abs(right.x)+abs(right.y))+abs(right.z))+abs(right.w)))+(((abs(upDown.x)+abs(upDown.y))+abs(upDown.z))+abs(upDown.w))); + half std = 2.181818/sum; + + half2 aWY = weightY(pl.x, pl.y+1.0, upDown.x,std); + aWY += weightY(pl.x-1.0, pl.y+1.0, upDown.y,std); + aWY += weightY(pl.x-1.0, pl.y-2.0, upDown.z,std); + aWY += weightY(pl.x, pl.y-2.0, upDown.w,std); + aWY += weightY(pl.x+1.0, pl.y-1.0, left.x,std); + aWY += weightY(pl.x, pl.y-1.0, left.y,std); + aWY += weightY(pl.x, pl.y, left.z,std); + aWY += weightY(pl.x+1.0, pl.y, left.w,std); + aWY += weightY(pl.x-1.0, pl.y-1.0, right.x,std); + aWY += weightY(pl.x-2.0, pl.y-1.0, right.y,std); + aWY += weightY(pl.x-2.0, pl.y, right.z,std); + aWY += weightY(pl.x-1.0, pl.y, right.w,std); + + half finalY = aWY.y/aWY.x; + + half maxY = max(max(left.y,left.z),max(right.x,right.w)); + half minY = min(min(left.y,left.z),min(right.x,right.w)); + finalY = clamp(edgeSharpness*finalY, minY, maxY); + + half deltaY = finalY -color.w; + + //smooth high contrast input + deltaY = clamp(deltaY, -23.0 / 255.0, 23.0 / 255.0); + + color.x = clamp((color.x+deltaY),0.0,1.0); + color.y = clamp((color.y+deltaY),0.0,1.0); + color.z = clamp((color.z+deltaY),0.0,1.0); + } + } + + color.w = originalAlpha; //assume alpha channel is not used + return color; + } + } + + compile("target_ps", "SnapdragonSUperResolution_ps"); + compile("target_vs", "SnapdragonSUperResolution_vs"); + +} + diff --git a/samples/testGI/prog/shaders/shadersList.blk b/samples/testGI/prog/shaders/shadersList.blk index e6b1fbcee..483af6a83 100644 --- a/samples/testGI/prog/shaders/shadersList.blk +++ b/samples/testGI/prog/shaders/shadersList.blk @@ -17,3 +17,5 @@ file:t = "./source/sponza.dshl" //file:t = "./source/layered.dshl" file:t = "../../../engine/imgui/imgui.dshl" + file:t = "../../../3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl" + \ No newline at end of file diff --git a/samples/testGI/prog/test_app.cpp b/samples/testGI/prog/test_app.cpp index 084b46b05..096e5c3ad 100644 --- a/samples/testGI/prog/test_app.cpp +++ b/samples/testGI/prog/test_app.cpp @@ -93,6 +93,9 @@ #include "de3_benchmark.h" #include "lruCollision.h" +//#include <3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h> +#include + typedef BaseStreamingSceneHolder scene_type_t; #define SKY_GUI 1 @@ -153,6 +156,10 @@ enum NUM_METALLIC = 10 }; +static bool enable_taa_override = false; +static bool use_snapdragon_super_resolution = false; +static float snapdragon_super_resolution_scale = 0.75f; + static void init_webui(const DataBlock *debug_block) { if (!debug_block) @@ -381,6 +388,8 @@ class DemoGameScene : public DagorGameScene, public IRenderDynamicCubeFace2, pub eastl::unique_ptr gtao; DebugTexOverlay debugTexOverlay; + UniqueTex superResolutionOutput; + ///* void downsampleDepth(bool downsample_normals) { @@ -690,6 +699,11 @@ class DemoGameScene : public DagorGameScene, public IRenderDynamicCubeFace2, pub d3d::GpuAutoLock gpu_al; int w, h; d3d::get_target_size(w, h); + if (use_snapdragon_super_resolution) + { + w = (int)((float)w * snapdragon_super_resolution_scale); + h = (int)((float)h * snapdragon_super_resolution_scale); + } postfx.init("postfx"); target = eastl::make_unique("deferred_shadow_to_buffer", "main", w, h, DeferredRT::StereoMode::MonoOrMultipass, 0, gbuf_rt, gbuf_fmts, TEXFMT_DEPTH32); @@ -778,6 +792,14 @@ class DemoGameScene : public DagorGameScene, public IRenderDynamicCubeFace2, pub global_cls_drv_pnt->getDevice(0)->setClipRect(0, 0, w, h); localProbe = NULL; + if (use_snapdragon_super_resolution) + { + int fw, fh; + d3d::get_target_size(fw, fh); + superResolutionOutput = dag::create_tex(NULL, fw, fh, rtFmt | TEXCF_RTARGET, 1, "SuperResolutionOutput"); + snapdragonSuperResolutionRender.SetViewport(w, h); + } + #define VAR(a) a##VarId = get_shader_variable_id(#a); GLOBAL_VARS_LIST #undef VAR @@ -789,6 +811,7 @@ class DemoGameScene : public DagorGameScene, public IRenderDynamicCubeFace2, pub // center) } PostFxRenderer taaRender; + SnapdragonSuperResolution snapdragonSuperResolutionRender; enum { CLOUD_VOLUME_W = 32, @@ -983,7 +1006,8 @@ class DemoGameScene : public DagorGameScene, public IRenderDynamicCubeFace2, pub // set_shader_global_time(gameTime); set_shader_global_time(realTime); static int taaFrame = 0; - bool renderTaa = taa.get(); + bool renderTaa = taa.get() || enable_taa_override; + logwarn("[hmatthew] renderTaa = %s", renderTaa ? "TRUE" : "FALSE"); Driver3dPerspective p; d3d::getpersp(p); @@ -1051,6 +1075,13 @@ class DemoGameScene : public DagorGameScene, public IRenderDynamicCubeFace2, pub } else frame.setVar(); + + if (use_snapdragon_super_resolution) + { + snapdragonSuperResolutionRender.render(frame, superResolutionOutput.getTex2D()); + ShaderGlobal::set_texture(frame.getVarId(), superResolutionOutput); + } + if (::grs_draw_wire) d3d::setwire(0); @@ -1608,14 +1639,15 @@ class DemoGameScene : public DagorGameScene, public IRenderDynamicCubeFace2, pub float zn = 0.1, zf = 1000; for (int i = 0; i < 6; ++i) { + d3d::set_render_target(enviProbe.getCubeTex(), i, 0); + d3d::clearview(CLEAR_TARGET, 0, 0, 0); + target->setRt(); d3d::setpersp(Driver3dPerspective(1, 1, zn, zf, 0, 0)); TMatrix cameraMatrix = cube_matrix(TMatrix::IDENT, i); cameraMatrix.setcol(3, 0, 100, 0); d3d::settm(TM_VIEW, orthonormalized_inverse(cameraMatrix)); - d3d::set_render_target(enviProbe.getCubeTex(), i, 0); - d3d::clearview(CLEAR_TARGET, 0, 0, 0); renderLightProbeEnvi(); } enviProbe.getCubeTex()->generateMips(); @@ -2348,6 +2380,17 @@ void game_demo_init() const DataBlock &blk = *dgs_get_settings(); ::set_gameres_sys_ver(2); + DataBlock* global_settings_blk = new DataBlock; + global_settings_blk->load("settings.blk"); + enable_taa_override = global_settings_blk->getBlockByNameEx("render")->getBool("taa", false); + + auto sgsrBlock = global_settings_blk->getBlockByNameEx("SnapdragonSuperResolution"); + if (sgsrBlock) + { + use_snapdragon_super_resolution = sgsrBlock->getBool("enable", false); + snapdragon_super_resolution_scale = ((float)sgsrBlock->getInt("scale", 75) / 100.f); + } + #define LOAD_RES_PATCH(LOC_NAME) \ if (dd_file_exists("content/patch/" LOC_NAME "/grp_hdr.vromfs.bin") && \ (vrom = load_vromfs_dump("content/patch/" LOC_NAME "/grp_hdr.vromfs.bin", tmpmem)) != NULL) \ @@ -2391,3 +2434,6 @@ void game_demo_init() init_webui(NULL); dagor_select_game_scene(new DemoGameScene); } + +#include +DagorCurView grs_cur_view; From 5a065271282234d1bbd24e97aa68bb2072a65d24 Mon Sep 17 00:00:00 2001 From: Matthew Hoffman Date: Wed, 24 Jan 2024 16:31:05 -0800 Subject: [PATCH 2/3] [SGS] Fixes brightness issue with SGSR --- .../SnapdragonSuperResolution.h | 8 +- .../shaders/SnapdragonSuperResolution.dshl | 161 +++++++++--------- 2 files changed, 86 insertions(+), 83 deletions(-) diff --git a/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h b/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h index 2400541b1..39ab0a339 100644 --- a/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h +++ b/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h @@ -20,10 +20,10 @@ class SnapdragonSuperResolution : public PostFxRenderer inline void SetViewport(int32_t x, int32_t y) { - viewport[0] = (float)x; - viewport[1] = (float)y; - viewport[2] = viewport[0] != 0.f ? (1.f / viewport[0]) : 0.f; - viewport[3] = viewport[1] != 0.f ? (1.f / viewport[1]) : 0.f; + viewport[2] = (float)x; + viewport[3] = (float)y; + viewport[0] = viewport[2] != 0.f ? (1.f / viewport[2]) : 0.f; + viewport[1] = viewport[3] != 0.f ? (1.f / viewport[3]) : 0.f; } inline void render(const ManagedTex &input, BaseTexture* output) diff --git a/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl b/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl index def03c58a..500a4b340 100644 --- a/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl +++ b/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl @@ -27,7 +27,7 @@ shader SnapdragonSuperResolution } hlsl(vs) { - VsOutput SnapdragonSUperResolution_vs(uint vertex_id : SV_VertexID) + VsOutput SnapdragonSuperResolution_vs(uint vertex_id : SV_VertexID) { VsOutput output; float2 pos = getPostfxVertexPositionById(vertex_id); @@ -44,42 +44,6 @@ shader SnapdragonSuperResolution } hlsl(ps) { - #include - //////////////////////// - // USER CONFIGURATION // - //////////////////////// - - /* - * Operation modes: - * RGBA -> 1 - * RGBY -> 3 - * LERP -> 4 - */ - #define OperationMode 1 - - #define EdgeThreshold 8.0/255.0 - - #define EdgeSharpness 2.0 - - half simple_luma_tonemap(half luma, half exposure) { return rcp(luma * exposure + 1.0); } - - half simple_luma_tonemap_inv(half luma, half exposure) { return rcp(max(1.0 - luma * exposure, 0.001)); } - - half fastLanczos2(half x) - { - half wA = x-4.0; - half wB = x*wA-wA; - wA *= wA; - return wB*wA; - } - - half2 weightY(half dx, half dy,half c, half std) - { - half x = ((dx*dx)+(dy* dy))* 0.55 + clamp(abs(c)*std, 0.0, 1.0); - half w = fastLanczos2(x); - return half2(w, w * c); - } - half4 SGSRRH(float2 p) { half4 res = snapdragon_super_resolution_input.GatherRed(snapdragon_super_resolution_input_samplerstate, p); @@ -117,54 +81,85 @@ shader SnapdragonSuperResolution return SGSRAH(p); } - float4 SnapdragonSUperResolution_ps( VsOutput input) : SV_Target0 + //////////////////////// + // USER CONFIGURATION // + //////////////////////// + + /* + * Operation modes: + * RGBA -> 1 + * RGBY -> 3 + * LERP -> 4 + */ + #define OperationMode 1 + + #define EdgeThreshold 8.0/255.0 + + #define EdgeSharpness 2.0 + + //////////////////////// + //////////////////////// + //////////////////////// + + half fastLanczos2(half x) + { + half wA = x- half(4.0); + half wB = x*wA-wA; + wA *= wA; + return wB*wA; + } + half2 weightY(half dx, half dy, half c, half std) + { + half x = ((dx*dx)+(dy* dy))* half(0.5) + clamp(abs(c)*std, 0.0, 1.0); + half w = fastLanczos2(x); + return half2(w, w * c); + } + + void SgsrYuvH( + out half4 pix, + float2 uv, + float4 con1) { int mode = OperationMode; half edgeThreshold = EdgeThreshold; half edgeSharpness = EdgeSharpness; - - half4 color = SGSRRGBH(input.texcoord.xy).xyzw; - half originalAlpha = color.w; - //if(mode == 1) - // color.xyz = SGSRRGBH(input.texcoord.xy).xyz; //tex2Dlod(snapdragon_super_resolution_input,input.texcoord.xy,0.0).xyz; - //else - // color.xyzw = SGSRRGBH(input.texcoord.xy).xyzw; //tex2Dlod(snapdragon_super_resolution_input,input.texcoord.xy,0.0).xyzw; - + if(mode == 1) + pix.xyz = SGSRRGBH(uv).xyz; + else + pix.xyzw = SGSRRGBH(uv).xyzw; float xCenter; - xCenter = abs(input.texcoord.x+-0.5); + xCenter = abs(uv.x+-0.5); float yCenter; - yCenter = abs(input.texcoord.y+-0.5); - - //todo: config the SR region based on needs - //if ( mode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4) + yCenter = abs(uv.y+-0.5); + if ( mode!=4) { - float2 imgCoord = ((input.texcoord.xy*ViewportInfo.zw)+half2(-0.5,0.5)); + float2 imgCoord = ((uv.xy*con1.zw)+ float2(-0.5,0.5)); float2 imgCoordPixel = floor(imgCoord); - float2 coord = (imgCoordPixel*ViewportInfo.xy); + float2 coord = (imgCoordPixel*con1.xy); half2 pl = (imgCoord+(-imgCoordPixel)); half4 left = SGSRH(coord, mode); - - half edgeVote = abs(left.z - left.y) + abs(color[mode] - left.y) + abs(color[mode] - left.z) ; + + half edgeVote = abs(left.z - left.y) + abs(pix[mode] - left.y) + abs(pix[mode] - left.z) ; if(edgeVote > edgeThreshold) { - coord.x += ViewportInfo.x; + coord.x += con1.x; - half4 right = SGSRH(coord + float2(ViewportInfo.x, 0.0), mode); + half4 right = SGSRH(coord + float2(con1.x, 0.0), mode); half4 upDown; - upDown.xy = SGSRH(coord + float2(0.0, -ViewportInfo.y), mode).wz; - upDown.zw = SGSRH(coord + float2(0.0, ViewportInfo.y), mode).yx; + upDown.xy = SGSRH(coord + float2(0.0, -con1.y), mode).wz; + upDown.zw = SGSRH(coord + float2(0.0, con1.y), mode).yx; - half mean = (left.y+left.z+right.x+right.w)*0.25; - left = left - half4(mean, mean, mean, mean); + half mean = (left.y+left.z+right.x+right.w)* half(0.25); + left = left - half4(mean,mean,mean,mean); right = right - half4(mean, mean, mean, mean); upDown = upDown - half4(mean, mean, mean, mean); - color.w =color[mode] - mean; + pix.w =pix[mode] - mean; - half sum = (((((abs(left.x)+abs(left.y))+abs(left.z))+abs(left.w))+(((abs(right.x)+abs(right.y))+abs(right.z))+abs(right.w)))+(((abs(upDown.x)+abs(upDown.y))+abs(upDown.z))+abs(upDown.w))); - half std = 2.181818/sum; + half sum = (((((abs(left.x)+abs(left.y))+abs(left.z))+abs(left.w))+(((abs(right.x)+abs(right.y))+abs(right.z))+abs(right.w)))+(((abs(upDown.x)+abs(upDown.y))+abs(upDown.z))+abs(upDown.w))); + half std = half(2.181818)/sum; - half2 aWY = weightY(pl.x, pl.y+1.0, upDown.x,std); + half2 aWY = weightY(pl.x, pl.y+1.0, upDown.x,std); aWY += weightY(pl.x-1.0, pl.y+1.0, upDown.y,std); aWY += weightY(pl.x-1.0, pl.y-2.0, upDown.z,std); aWY += weightY(pl.x, pl.y-2.0, upDown.w,std); @@ -179,28 +174,36 @@ shader SnapdragonSuperResolution half finalY = aWY.y/aWY.x; - half maxY = max(max(left.y,left.z),max(right.x,right.w)); - half minY = min(min(left.y,left.z),min(right.x,right.w)); - finalY = clamp(edgeSharpness*finalY, minY, maxY); + half max4 = max(max(left.y,left.z),max(right.x,right.w)); + half min4 = min(min(left.y,left.z),min(right.x,right.w)); + finalY = clamp(edgeSharpness*finalY, min4, max4); - half deltaY = finalY -color.w; - - //smooth high contrast input - deltaY = clamp(deltaY, -23.0 / 255.0, 23.0 / 255.0); + half deltaY = finalY -pix.w; - color.x = clamp((color.x+deltaY),0.0,1.0); - color.y = clamp((color.y+deltaY),0.0,1.0); - color.z = clamp((color.z+deltaY),0.0,1.0); + pix.x = saturate((pix.x+deltaY)); + pix.y = saturate((pix.y+deltaY)); + pix.z = saturate((pix.z+deltaY)); } } + pix.w = 1.0; //assume alpha channel is not used + + } - color.w = originalAlpha; //assume alpha channel is not used - return color; + // ===================================================================================== + // + // SNAPDRAGON GAME SUPER RESOLUTION + // + // ===================================================================================== + half4 SnapdragonSuperResolution_ps(VsOutput input) : SV_Target0 + { + half4 OutColor = half4(0, 0, 0, 1); + SgsrYuvH(OutColor, input.texcoord, ViewportInfo); + return OutColor; } } - compile("target_ps", "SnapdragonSUperResolution_ps"); - compile("target_vs", "SnapdragonSUperResolution_vs"); + compile("target_ps", "SnapdragonSuperResolution_ps"); + compile("target_vs", "SnapdragonSuperResolution_vs"); } From bba6936f92fdfbaea2326e7519d8b74a81f32f1e Mon Sep 17 00:00:00 2001 From: Matthew Hoffman Date: Tue, 21 May 2024 10:17:48 -0700 Subject: [PATCH 3/3] [SGS] Code and licenses cleanup for SGSR --- .../SnapdragonSuperResolution/LICENSE.txt | 29 +++++++++++++++++++ .../SnapdragonSuperResolution.h | 12 ++++++++ .../shaders/SnapdragonSuperResolution.dshl | 12 ++++++++ samples/testGI/prog/test_app.cpp | 4 --- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 prog/3rdPartyLibs/SnapdragonSuperResolution/LICENSE.txt diff --git a/prog/3rdPartyLibs/SnapdragonSuperResolution/LICENSE.txt b/prog/3rdPartyLibs/SnapdragonSuperResolution/LICENSE.txt new file mode 100644 index 000000000..d9d513c75 --- /dev/null +++ b/prog/3rdPartyLibs/SnapdragonSuperResolution/LICENSE.txt @@ -0,0 +1,29 @@ +Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +SPDX-License-Identifier: BSD-3-Clause \ No newline at end of file diff --git a/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h b/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h index 39ab0a339..f23b69fd2 100644 --- a/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h +++ b/prog/3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h @@ -1,3 +1,15 @@ +//============================================================================================================ +// DO NOT REMOVE THIS HEADER UNDER QUALCOMM PRODUCT KIT LICENSE AGREEMENT +// +// Copyright (c) 2023 QUALCOMM Technologies Inc. +// All Rights Reserved. +// +// Snapdragon™ Game Super Resolution +// Snapdragon™ GSR +// +// Developed by Snapdragon Studios™ (https://www.qualcomm.com/snapdragon-studios) +// +//============================================================================================================ #pragma once #include #include diff --git a/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl b/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl index 500a4b340..2bbd40dd0 100644 --- a/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl +++ b/prog/3rdPartyLibs/SnapdragonSuperResolution/shaders/SnapdragonSuperResolution.dshl @@ -1,4 +1,16 @@ //============================================================================================================ +// DO NOT REMOVE THIS HEADER UNDER QUALCOMM PRODUCT KIT LICENSE AGREEMENT +// +// Copyright (c) 2023 QUALCOMM Technologies Inc. +// All Rights Reserved. +// +// Snapdragon™ Game Super Resolution +// Snapdragon™ GSR +// +// Developed by Snapdragon Studios™ (https://www.qualcomm.com/snapdragon-studios) +// +//============================================================================================================ +//============================================================================================================ // // // Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved. diff --git a/samples/testGI/prog/test_app.cpp b/samples/testGI/prog/test_app.cpp index 096e5c3ad..b21ef8929 100644 --- a/samples/testGI/prog/test_app.cpp +++ b/samples/testGI/prog/test_app.cpp @@ -93,7 +93,6 @@ #include "de3_benchmark.h" #include "lruCollision.h" -//#include <3rdPartyLibs/SnapdragonSuperResolution/SnapdragonSuperResolution.h> #include typedef BaseStreamingSceneHolder scene_type_t; @@ -2434,6 +2433,3 @@ void game_demo_init() init_webui(NULL); dagor_select_game_scene(new DemoGameScene); } - -#include -DagorCurView grs_cur_view;