diff --git a/.gitignore b/.gitignore index e0d5ef3a8..9e577f498 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ VisualC/tests/testscale/sample.bmp VisualC/tests/testsprite/icon.bmp VisualC/tests/testyuv/testyuv.bmp VisualC-GDK/**/Layout +VisualC-GDK/shaders/*.h # for Android android-project/local.properties diff --git a/VisualC-GDK/SDL.sln b/VisualC-GDK/SDL.sln index 2cdfa0bd8..14289c287 100644 --- a/VisualC-GDK/SDL.sln +++ b/VisualC-GDK/SDL.sln @@ -11,6 +11,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL3_test", "SDL_test\SDL_test.vcxproj", "{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testcontroller", "tests\testcontroller\testcontroller.vcxproj", "{55812185-D13C-4022-9C81-32E0F4A08305}" + ProjectSection(ProjectDependencies) = postProject + {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgdk", "tests\testgdk\testgdk.vcxproj", "{1C9A3F71-35A5-4C56-B292-F4375B3C3649}" EndProject diff --git a/VisualC-GDK/SDL/SDL.vcxproj b/VisualC-GDK/SDL/SDL.vcxproj index b7b5a72c0..c7fa0a28d 100644 --- a/VisualC-GDK/SDL/SDL.vcxproj +++ b/VisualC-GDK/SDL/SDL.vcxproj @@ -130,7 +130,7 @@ OldStyle OnlyExplicitInline true - Use + NotUsing SDL_internal.h @@ -170,6 +170,12 @@ Windows true + + $(SolutionDir)\shaders\buildshaders.bat $(SolutionDir) + + + Building shader blobs (Xbox Series) + @@ -198,6 +204,12 @@ Windows true + + $(SolutionDir)\shaders\buildshaders.bat $(SolutionDir) one + + + Building shader blobs (Xbox One) + @@ -215,7 +227,7 @@ ProgramDatabase OnlyExplicitInline true - Use + NotUsing SDL_internal.h @@ -258,6 +270,12 @@ true true + + $(SolutionDir)\shaders\buildshaders.bat $(SolutionDir) + + + Building shader blobs (Xbox Series) + @@ -287,6 +305,12 @@ true true + + $(SolutionDir)\shaders\buildshaders.bat $(SolutionDir) one + + + Building shader blobs (Xbox One) + @@ -457,6 +481,12 @@ Create $(IntDir)$(TargetName)_cpp.pch + + true + true + true + true + $(IntDir)$(TargetName)_cpp.pch $(IntDir)$(TargetName)_cpp.pch @@ -589,7 +619,10 @@ - + + true + true + @@ -733,7 +766,7 @@ - + NotUsing @@ -776,6 +809,7 @@ + @@ -800,4 +834,4 @@ - + \ No newline at end of file diff --git a/VisualC-GDK/SDL/SDL.vcxproj.filters b/VisualC-GDK/SDL/SDL.vcxproj.filters index e9f4d52c5..4692d4684 100644 --- a/VisualC-GDK/SDL/SDL.vcxproj.filters +++ b/VisualC-GDK/SDL/SDL.vcxproj.filters @@ -1,1434 +1,436 @@  - - {395b3af0-33d0-411b-b153-de1676bf1ef8} - - - {5a3e3167-75be-414f-8947-a5306df372b2} - - - {546d9ed1-988e-49d3-b1a5-e5b3d19de6c1} - - - {a56247ff-5108-4960-ba6a-6814fd1554ec} - - - {8880dfad-2a06-4e84-ab6e-6583641ad2d1} - - - {2b996a7f-f3e9-4300-a97f-2c907bcd89a9} - - - {5713d682-2bc7-4da4-bcf0-262a98f142eb} - - - {5e27e19f-b3f8-4e2d-b323-b00b2040ec86} - - - {a3ab9cff-8495-4a5c-8af6-27e43199a712} - - - {377061e4-3856-4f05-b916-0d3b360df0f6} - - - {226a6643-1c65-4c7f-92aa-861313d974bb} - - - {ef859522-a7fe-4a00-a511-d6a9896adf5b} - - - {01fd2642-4493-4316-b548-fb829f4c9125} - - - {cce7558f-590a-4f0a-ac0d-e579f76e588e} - - - {7a53c9e4-d4bd-40ed-9265-1625df685121} - - - {4c7a051c-ce7c-426c-bf8c-9187827f9052} - - - {97e2f79f-311b-42ea-81b2-e801649fdd93} - - - {baf97c8c-7e90-41e5-bff8-14051b8d3956} - - - {45e50d3a-56c9-4352-b811-0c60c49a2431} - - - {9d86e0ef-d6f6-4db2-bfc5-b3529406fa8d} - - - {b35fa13c-6ed2-4680-8c56-c7d71b76ceab} - - - {61b61b31-9e26-4171-a3bb-b969f1889726} - - - {f63aa216-6ee7-4143-90d3-32be3787f276} - - - {90bee923-89df-417f-a6c3-3e260a7dd54d} - - - {4c8ad943-c2fb-4014-9ca3-041e0ad08426} - - - {3d68ae70-a9ff-46cf-be69-069f0b02aca0} - - - {ebc2fca3-3c26-45e3-815e-3e0581d5e226} - - - {47c445a2-7014-4e15-9660-7c89a27dddcf} - - - {d008487d-6ed0-4251-848b-79a68e3c1459} - - - {c9e8273e-13ae-47dc-bef8-8ad8e64c9a3d} - - - {0b8e136d-56ae-47e7-9981-e863a57ac616} - - - {bf3febd3-9328-43e8-b196-0fd3be8177dd} - - - {1a62dc68-52d2-4c07-9d81-d94dfe1d0d12} - - - {e9f01b22-34b3-4380-ade6-0e96c74e9c90} - - - {f674f22f-7841-4f3a-974e-c36b2d4823fc} - - - {d7ad92de-4e55-4202-9b2b-1bd9a35fe4dc} - - - {8311d79d-9ad5-4369-99fe-b2fb2659d402} - - - {6c4dfb80-fdf9-497c-a6ff-3cd8f22efde9} - - - {4810e35c-33cb-4da2-bfaf-452da20d3c9a} - - - {2cf93f1d-81fd-4bdc-998c-5e2fa43988bc} - - - {5752b7ab-2344-4f38-95ab-b5d3bc150315} - - - {7a0eae3d-f113-4914-b926-6816d1929250} - - - {ee602cbf-96a2-4b0b-92a9-51d38a727411} - - - {a812185b-9060-4a1c-8431-be4f66894626} - - - {31c16cdf-adc4-4950-8293-28ba530f3882} - - - {add61b53-8144-47d6-bd67-3420a87c4905} - - - {e7cdcf36-b462-49c7-98b7-07ea7b3687f4} - - - {82588eef-dcaa-4f69-b2a9-e675940ce54c} - - - {560239c3-8fa1-4d23-a81a-b8408b2f7d3f} - - - {81711059-7575-4ece-9e68-333b63e992c4} - - - {1e44970f-7535-4bfb-b8a5-ea0cea0349e0} - - - {1dd91224-1176-492b-a2cb-e26153394db0} - - - {e3ecfe50-cf22-41d3-8983-2fead5164b47} - - - {5521d22f-1e52-47a6-8c52-06a3b6bdefd7} - - - {4755f3a6-49ac-46d6-86be-21f5c21f2197} - - - {f48c2b17-1bee-4fec-a7c8-24cf619abe08} - - - {3ab60a46-e18e-450a-a916-328fb8547e59} - - - {3ad16a8a-0ed8-439c-a771-383af2e2867f} - - - {00002ddb6c5ea921181bf32d50e40000} - - - {00000a808f8ba6b489985f82a4e80000} - - - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - API Headers - - - main - - - - - - API Headers - - - API Headers - - - API Headers - - - audio - - - audio - - - audio - - - audio - - - audio - - - audio - - - core\windows - - - core\windows - - - core\windows - - - core\windows - - - core\windows - - - dynapi - - - dynapi - - - dynapi - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - haptic - - - haptic - - - joystick - - - joystick - - - joystick - - - joystick - - - joystick - - - joystick - - - joystick - - - libm - - - libm - - - hidapi\hidapi - - - locale - - - misc - - - audio\directsound - - - audio\disk - - - audio\dummy - - - audio\wasapi - - - haptic\windows - - - haptic\windows - - - haptic\windows - - - joystick\hidapi - - - joystick\hidapi - - - joystick\windows - - - joystick\windows - - - joystick\windows - - - joystick\windows - - - joystick\virtual - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video\dummy - - - video\dummy - - - video\dummy - - - video\yuv2rgb - - - video\yuv2rgb - - - video\yuv2rgb - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - timer - - - thread - - - thread - - - thread\windows - - - thread\windows - - - thread\generic - - - sensor - - - sensor - - - sensor\dummy - - - sensor\windows - - - render - - - render - - - render - - - render\direct3d - - - render\direct3d11 - - - render\opengl - - - render\opengl - - - render\opengles2 - - - render\opengles2 - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - power - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - video\khronos\vulkan - - - - - - - - render\direct3d12 - - - - core\gdk - - - render\direct3d12 - - - video\gdk - - - thread\generic - - - + + + + + + + + + + + + + + + + + + + + + + - - main\generic - - - main - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - audio - - - audio - - - audio - - - audio - - - audio - - - audio - - - audio - - - audio - - - atomic - - - atomic - - - core - - - core - - - core\windows - - - core\windows - - - core\windows - - - core\windows - - - cpuinfo - - - dynapi - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - events - - - file - - - filesystem\gdk - - - haptic - - - hidapi - - - joystick - - - joystick - - - joystick - - - joystick - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - libm - - - loadso\windows - - - misc - - - misc\windows - - - locale\windows - - - locale - - - audio\directsound - - - audio\disk - - - audio\dummy - - - audio\wasapi - - - audio\wasapi - - - haptic\windows - - - haptic\windows - - - haptic\windows - - - haptic\dummy - - - joystick\dummy - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\hidapi - - - joystick\windows - - - joystick\windows - - - joystick\windows - - - joystick\windows - - - joystick\windows - - - joystick\virtual - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video - - - video\dummy - - - video\dummy - - - video\dummy - - - video\yuv2rgb - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - video\windows - - - timer - - - timer\windows - - - thread - - - thread\windows - - - thread\windows - - - thread\windows - - - thread\windows - - - thread\windows - - - thread\generic - - - stdlib - - - stdlib - - - stdlib - - - stdlib - - - stdlib - - - stdlib - - - stdlib - - - stdlib - - - stdlib - - - sensor - - - sensor\dummy - - - sensor\windows - - - render - - - render - - - render - - - render - - - render\direct3d - - - render\direct3d - - - render\direct3d11 - - - render\direct3d11 - - - render\opengl - - - render\opengl - - - render\opengles2 - - - render\opengles2 - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - render\software - - - power - - - - power\windows - - - render\direct3d12 - - - render\direct3d12 - - - stdlib - - - stdlib - - - core\gdk - - - render\direct3d12 - - - render\direct3d12 - - - render\direct3d12 - - - core\windows - - - core\windows - - - video\gdk - - - thread\windows - - - thread\generic - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/VisualC-GDK/clean.sh b/VisualC-GDK/clean.sh index a026b71a3..235b79c49 100755 --- a/VisualC-GDK/clean.sh +++ b/VisualC-GDK/clean.sh @@ -4,3 +4,4 @@ find . -type f \( -name '*.bmp' -o -name '*.wav' -o -name '*.dat' \) -print -del find . -depth -type d \( -name Gaming.Desktop.x64 \) -exec rm -rv {} \; find . -depth -type d \( -name Gaming.Xbox.Scarlett.x64 \) -exec rm -rv {} \; find . -depth -type d \( -name Gaming.Xbox.XboxOne.x64 \) -exec rm -rv {} \; +rm shaders/*.h diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_Colors.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_Colors.hlsl new file mode 100644 index 000000000..47eff4cc2 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_Colors.hlsl @@ -0,0 +1,19 @@ +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define ColorRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + "DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + "DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + "DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0)" + +[RootSignature(ColorRS)] +float4 main(PixelShaderInput input) : SV_TARGET0 +{ + return input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601.hlsl new file mode 100644 index 000000000..cffbc2261 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601.hlsl @@ -0,0 +1,43 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureUV : register(t1); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define NVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(NVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.1644, 0.0000, 1.5960}; + const float3 Gcoeff = {1.1644, -0.3918, -0.8130}; + const float3 Bcoeff = {1.1644, 2.0172, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709.hlsl new file mode 100644 index 000000000..81d409c94 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709.hlsl @@ -0,0 +1,43 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureUV : register(t1); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define NVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(NVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.1644, 0.0000, 1.7927}; + const float3 Gcoeff = {1.1644, -0.2132, -0.5329}; + const float3 Bcoeff = {1.1644, 2.1124, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG.hlsl new file mode 100644 index 000000000..494bce519 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG.hlsl @@ -0,0 +1,43 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureUV : register(t1); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define NVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(NVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {0.0, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.0000, 0.0000, 1.4020}; + const float3 Gcoeff = {1.0000, -0.3441, -0.7141}; + const float3 Bcoeff = {1.0000, 1.7720, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601.hlsl new file mode 100644 index 000000000..794c76372 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601.hlsl @@ -0,0 +1,43 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureUV : register(t1); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define NVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(NVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.1644, 0.0000, 1.5960}; + const float3 Gcoeff = {1.1644, -0.3918, -0.8130}; + const float3 Bcoeff = {1.1644, 2.0172, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.yz = theTextureUV.Sample(theSampler, input.tex).gr; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709.hlsl new file mode 100644 index 000000000..f5b9522c0 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709.hlsl @@ -0,0 +1,43 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureUV : register(t1); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define NVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(NVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.1644, 0.0000, 1.7927}; + const float3 Gcoeff = {1.1644, -0.2132, -0.5329}; + const float3 Bcoeff = {1.1644, 2.1124, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.yz = theTextureUV.Sample(theSampler, input.tex).gr; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG.hlsl new file mode 100644 index 000000000..1b467b480 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG.hlsl @@ -0,0 +1,43 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureUV : register(t1); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define NVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(NVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {0.0, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.0000, 0.0000, 1.4020}; + const float3 Gcoeff = {1.0000, -0.3441, -0.7141}; + const float3 Bcoeff = {1.0000, 1.7720, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.yz = theTextureUV.Sample(theSampler, input.tex).gr; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_Textures.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_Textures.hlsl new file mode 100644 index 000000000..0dcdf89c6 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_Textures.hlsl @@ -0,0 +1,24 @@ +Texture2D theTexture : register(t0); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define TextureRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(TextureRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + return theTexture.Sample(theSampler, input.tex) * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601.hlsl new file mode 100644 index 000000000..09e58943a --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601.hlsl @@ -0,0 +1,46 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureU : register(t1); +Texture2D theTextureV : register(t2); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define YUVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(YUVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.1644, 0.0000, 1.5960}; + const float3 Gcoeff = {1.1644, -0.3918, -0.8130}; + const float3 Bcoeff = {1.1644, 2.0172, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.y = theTextureU.Sample(theSampler, input.tex).r; + yuv.z = theTextureV.Sample(theSampler, input.tex).r; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709.hlsl new file mode 100644 index 000000000..f5aa0cd7e --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709.hlsl @@ -0,0 +1,46 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureU : register(t1); +Texture2D theTextureV : register(t2); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define YUVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(YUVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {-0.0627451017, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.1644, 0.0000, 1.7927}; + const float3 Gcoeff = {1.1644, -0.2132, -0.5329}; + const float3 Bcoeff = {1.1644, 2.1124, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.y = theTextureU.Sample(theSampler, input.tex).r; + yuv.z = theTextureV.Sample(theSampler, input.tex).r; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG.hlsl b/VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG.hlsl new file mode 100644 index 000000000..84d09b8bf --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG.hlsl @@ -0,0 +1,46 @@ +Texture2D theTextureY : register(t0); +Texture2D theTextureU : register(t1); +Texture2D theTextureV : register(t2); +SamplerState theSampler : register(s0); + +struct PixelShaderInput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define YUVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(YUVRS)] +float4 main(PixelShaderInput input) : SV_TARGET +{ + const float3 offset = {0.0, -0.501960814, -0.501960814}; + const float3 Rcoeff = {1.0000, 0.0000, 1.4020}; + const float3 Gcoeff = {1.0000, -0.3441, -0.7141}; + const float3 Bcoeff = {1.0000, 1.7720, 0.0000}; + + float4 Output; + + float3 yuv; + yuv.x = theTextureY.Sample(theSampler, input.tex).r; + yuv.y = theTextureU.Sample(theSampler, input.tex).r; + yuv.z = theTextureV.Sample(theSampler, input.tex).r; + + yuv += offset; + Output.r = dot(yuv, Rcoeff); + Output.g = dot(yuv, Gcoeff); + Output.b = dot(yuv, Bcoeff); + Output.a = 1.0f; + + return Output * input.color; +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/D3D12_VertexShader.hlsl b/VisualC-GDK/shaders/D3D12_VertexShader.hlsl new file mode 100644 index 000000000..e10b48892 --- /dev/null +++ b/VisualC-GDK/shaders/D3D12_VertexShader.hlsl @@ -0,0 +1,95 @@ +#pragma pack_matrix( row_major ) + +struct VertexShaderConstants +{ + matrix model; + matrix projectionAndView; +}; +ConstantBuffer Constants : register(b0); + +struct VertexShaderInput +{ + float3 pos : POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +struct VertexShaderOutput +{ + float4 pos : SV_POSITION; + float2 tex : TEXCOORD0; + float4 color : COLOR0; +}; + +#define ColorRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + "DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + "DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + "DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0)" + +#define TextureRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +#define YUVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +#define NVRS \ + "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \ + " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \ + " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \ + " DENY_HULL_SHADER_ROOT_ACCESS )," \ + "RootConstants(num32BitConstants=32, b0),"\ + "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\ + "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )" + +[RootSignature(ColorRS)] +VertexShaderOutput mainColor(VertexShaderInput input) +{ + VertexShaderOutput output; + float4 pos = float4(input.pos, 1.0f); + + // Transform the vertex position into projected space. + pos = mul(pos, Constants.model); + pos = mul(pos, Constants.projectionAndView); + output.pos = pos; + + // Pass through texture coordinates and color values without transformation + output.tex = input.tex; + output.color = input.color; + + return output; +} + +[RootSignature(TextureRS)] +VertexShaderOutput mainTexture(VertexShaderInput input) +{ + return mainColor(input); +} + +[RootSignature(YUVRS)] +VertexShaderOutput mainYUV(VertexShaderInput input) +{ + return mainColor(input); +} + +[RootSignature(NVRS)] +VertexShaderOutput mainNV(VertexShaderInput input) +{ + return mainColor(input); +} \ No newline at end of file diff --git a/VisualC-GDK/shaders/buildshaders.bat b/VisualC-GDK/shaders/buildshaders.bat new file mode 100644 index 000000000..4447b5e2f --- /dev/null +++ b/VisualC-GDK/shaders/buildshaders.bat @@ -0,0 +1,35 @@ +if %2.==one. goto setxboxone +rem Xbox Series compile +set XBOXDXC="%GameDKLatest%\GXDK\bin\Scarlett\DXC.exe" +set SUFFIX=_Series.h +goto startbuild + +:setxboxone +set XBOXDXC="%GameDKLatest%\GXDK\bin\XboxOne\DXC.exe" +set SUFFIX=_One.h + +:startbuild +echo Building with %XBOXDXC% +cd "%1\shaders" +rem Root Signatures +%XBOXDXC% -E ColorRS -T rootsig_1_1 -rootsig-define ColorRS -Fh D3D12_RootSig_Color%SUFFIX% -Vn D3D12_RootSig_Color D3D12_VertexShader.hlsl +%XBOXDXC% -E TextureRS -T rootsig_1_1 -rootsig-define TextureRS -Fh D3D12_RootSig_Texture%SUFFIX% -Vn D3D12_RootSig_Texture D3D12_VertexShader.hlsl +%XBOXDXC% -E YUVRS -T rootsig_1_1 -rootsig-define YUVRS -Fh D3D12_RootSig_YUV%SUFFIX% -Vn D3D12_RootSig_YUV D3D12_VertexShader.hlsl +%XBOXDXC% -E NVRS -T rootsig_1_1 -rootsig-define NVRS -Fh D3D12_RootSig_NV%SUFFIX% -Vn D3D12_RootSig_NV D3D12_VertexShader.hlsl +rem Vertex Shaders +%XBOXDXC% -E mainColor -T vs_6_0 -Fh D3D12_VertexShader_Color%SUFFIX% -Vn D3D12_VertexShader_Color D3D12_VertexShader.hlsl +%XBOXDXC% -E mainTexture -T vs_6_0 -Fh D3D12_VertexShader_Texture%SUFFIX% -Vn D3D12_VertexShader_Texture D3D12_VertexShader.hlsl +%XBOXDXC% -E mainNV -T vs_6_0 -Fh D3D12_VertexShader_NV%SUFFIX% -Vn D3D12_VertexShader_NV D3D12_VertexShader.hlsl +%XBOXDXC% -E mainYUV -T vs_6_0 -Fh D3D12_VertexShader_YUV%SUFFIX% -Vn D3D12_VertexShader_YUV D3D12_VertexShader.hlsl +rem Pixel Shaders +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_Colors%SUFFIX% -Vn D3D12_PixelShader_Colors D3D12_PixelShader_Colors.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_NV12_BT601%SUFFIX% -Vn D3D12_PixelShader_NV12_BT601 D3D12_PixelShader_NV12_BT601.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_NV12_BT709%SUFFIX% -Vn D3D12_PixelShader_NV12_BT709 D3D12_PixelShader_NV12_BT709.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_NV12_JPEG%SUFFIX% -Vn D3D12_PixelShader_NV12_JPEG D3D12_PixelShader_NV12_JPEG.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_NV21_BT601%SUFFIX% -Vn D3D12_PixelShader_NV21_BT601 D3D12_PixelShader_NV21_BT601.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_NV21_BT709%SUFFIX% -Vn D3D12_PixelShader_NV21_BT709 D3D12_PixelShader_NV21_BT709.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_NV21_JPEG%SUFFIX% -Vn D3D12_PixelShader_NV21_JPEG D3D12_PixelShader_NV21_JPEG.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_Textures%SUFFIX% -Vn D3D12_PixelShader_Textures D3D12_PixelShader_Textures.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_YUV_BT601%SUFFIX% -Vn D3D12_PixelShader_YUV_BT601 D3D12_PixelShader_YUV_BT601.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_YUV_BT709%SUFFIX% -Vn D3D12_PixelShader_YUV_BT709 D3D12_PixelShader_YUV_BT709.hlsl +%XBOXDXC% -E main -T ps_6_0 -Fh D3D12_PixelShader_YUV_JPEG%SUFFIX% -Vn D3D12_PixelShader_YUV_JPEG D3D12_PixelShader_YUV_JPEG.hlsl \ No newline at end of file diff --git a/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj b/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj index 3f0156166..5680fe311 100644 --- a/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj +++ b/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj @@ -139,7 +139,7 @@ Windows - xgameruntime.lib;../Microsoft.Xbox.Services.141.GDK.C.Thunks.lib;%(AdditionalDependencies) + xgameruntime.lib;../Microsoft.Xbox.Services.GDK.C.Thunks.lib;%(AdditionalDependencies) @@ -211,7 +211,7 @@ true Windows - xgameruntime.lib;../Microsoft.Xbox.Services.141.GDK.C.Thunks.lib;%(AdditionalDependencies) + xgameruntime.lib;../Microsoft.Xbox.Services.GDK.C.Thunks.lib;%(AdditionalDependencies) @@ -273,6 +273,12 @@ false true + + {da956fd3-e143-46f2-9fe5-c77bebc56b1a} + false + false + true + @@ -298,7 +304,7 @@ - + Document true true @@ -330,4 +336,4 @@ - + \ No newline at end of file diff --git a/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj.filters b/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj.filters index e4e2413ef..90aec1b6a 100644 --- a/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj.filters +++ b/VisualC-GDK/tests/testcontroller/testcontroller.vcxproj.filters @@ -18,9 +18,6 @@ logos - - wingdk - wingdk @@ -34,6 +31,9 @@ logos + + wingdk + @@ -49,4 +49,4 @@ {e704dcb9-c83c-4c94-a139-b0f3e3f428f2} - + \ No newline at end of file diff --git a/VisualC-GDK/tests/testgdk/src/testgdk.cpp b/VisualC-GDK/tests/testgdk/src/testgdk.cpp index f65fd4b96..bc4895bdc 100644 --- a/VisualC-GDK/tests/testgdk/src/testgdk.cpp +++ b/VisualC-GDK/tests/testgdk/src/testgdk.cpp @@ -53,23 +53,14 @@ static struct int soundpos; /* Current play position */ } wave; -static SDL_AudioDeviceID device; - -static void -close_audio() -{ - if (device != 0) { - SDL_CloseAudioDevice(device); - device = 0; - } -} +static SDL_AudioStream *stream; /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void quit(int rc) { SDL_free(sprites); - close_audio(); + SDL_DestroyAudioStream(stream); SDL_free(wave.sound); SDLTest_CommonQuit(state); /* If rc is 0, just let main return normally rather than calling exit. @@ -80,49 +71,13 @@ quit(int rc) } } -static void -open_audio() +static int fillerup(void) { - /* Initialize fillerup() variables */ - device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &wave.spec, NULL, 0); - if (!device) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError()); - SDL_free(wave.sound); - quit(2); + const int minimum = (wave.soundlen / SDL_AUDIO_FRAMESIZE(wave.spec)) / 2; + if (SDL_GetAudioStreamQueued(stream) < minimum) { + SDL_PutAudioStreamData(stream, wave.sound, wave.soundlen); } - - /* Let the audio run */ - SDL_PlayAudioDevice(device); -} - -static void -reopen_audio() -{ - close_audio(); - open_audio(); -} - -void SDLCALL -fillerup(void *unused, Uint8 *stream, int len) -{ - Uint8 *waveptr; - int waveleft; - - /* Set up the pointers */ - waveptr = wave.sound + wave.soundpos; - waveleft = wave.soundlen - wave.soundpos; - - /* Go! */ - while (waveleft <= len) { - SDL_memcpy(stream, waveptr, waveleft); - stream += waveleft; - len -= waveleft; - waveptr = wave.sound; - waveleft = wave.soundlen; - wave.soundpos = 0; - } - SDL_memcpy(stream, waveptr, len); - wave.soundpos += len; + return 0; } void @@ -371,6 +326,7 @@ loop() } DrawSprites(state->renderers[i], sprites[i]); } + fillerup(); } int @@ -469,13 +425,11 @@ main(int argc, char *argv[]) } /* Load the wave file into memory */ - if (SDL_LoadWAV(soundname, &wave.spec, &wave.sound, &wave.soundlen) == NULL) { + if (SDL_LoadWAV(soundname, &wave.spec, &wave.sound, &wave.soundlen) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", soundname, SDL_GetError()); quit(1); } - wave.spec.callback = fillerup; - /* Show the list of available drivers */ SDL_Log("Available audio drivers:"); for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) { @@ -484,7 +438,12 @@ main(int argc, char *argv[]) SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); - open_audio(); + stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL); + if (!stream) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError()); + return -1; + } + SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); /* Main render loop */ done = 0; diff --git a/VisualC-GDK/tests/testgdk/testgdk.vcxproj b/VisualC-GDK/tests/testgdk/testgdk.vcxproj index c0e74e22e..c43e5f4d9 100644 --- a/VisualC-GDK/tests/testgdk/testgdk.vcxproj +++ b/VisualC-GDK/tests/testgdk/testgdk.vcxproj @@ -139,7 +139,7 @@ Windows - xgameruntime.lib;../Microsoft.Xbox.Services.141.GDK.C.Thunks.lib;%(AdditionalDependencies) + xgameruntime.lib;../Microsoft.Xbox.Services.GDK.C.Thunks.lib;%(AdditionalDependencies) @@ -223,7 +223,7 @@ true Windows - xgameruntime.lib;../Microsoft.Xbox.Services.141.GDK.C.Thunks.lib;%(AdditionalDependencies) + xgameruntime.lib;../Microsoft.Xbox.Services.GDK.C.Thunks.lib;%(AdditionalDependencies) @@ -346,7 +346,7 @@ copy "%(FullPath)" "$(OutDir)\" - + Document true true diff --git a/VisualC-GDK/tests/testgdk/testgdk.vcxproj.filters b/VisualC-GDK/tests/testgdk/testgdk.vcxproj.filters index b82a98985..1cbae8641 100644 --- a/VisualC-GDK/tests/testgdk/testgdk.vcxproj.filters +++ b/VisualC-GDK/tests/testgdk/testgdk.vcxproj.filters @@ -18,9 +18,6 @@ logos - - wingdk - wingdk @@ -35,6 +32,9 @@ logos + + wingdk + diff --git a/VisualC-GDK/tests/testsprite/testsprite.vcxproj b/VisualC-GDK/tests/testsprite/testsprite.vcxproj index 211f14cb9..9534f5b0b 100644 --- a/VisualC-GDK/tests/testsprite/testsprite.vcxproj +++ b/VisualC-GDK/tests/testsprite/testsprite.vcxproj @@ -139,7 +139,7 @@ Windows - xgameruntime.lib;../Microsoft.Xbox.Services.141.GDK.C.Thunks.lib;%(AdditionalDependencies) + xgameruntime.lib;../Microsoft.Xbox.Services.GDK.C.Thunks.lib;%(AdditionalDependencies) @@ -223,7 +223,7 @@ true Windows - xgameruntime.lib;../Microsoft.Xbox.Services.141.GDK.C.Thunks.lib;%(AdditionalDependencies) + xgameruntime.lib;../Microsoft.Xbox.Services.GDK.C.Thunks.lib;%(AdditionalDependencies) @@ -346,7 +346,7 @@ copy "%(FullPath)" "$(OutDir)\" - + Document true true diff --git a/VisualC-GDK/tests/testsprite/testsprite.vcxproj.filters b/VisualC-GDK/tests/testsprite/testsprite.vcxproj.filters index 3e0399e1f..ac1cda639 100644 --- a/VisualC-GDK/tests/testsprite/testsprite.vcxproj.filters +++ b/VisualC-GDK/tests/testsprite/testsprite.vcxproj.filters @@ -18,9 +18,6 @@ logos - - wingdk - xboxseries @@ -34,6 +31,9 @@ logos + + wingdk + diff --git a/docs/README-gdk.md b/docs/README-gdk.md index 6c242b5a0..f68908c39 100644 --- a/docs/README-gdk.md +++ b/docs/README-gdk.md @@ -3,15 +3,16 @@ GDK This port allows SDL applications to run via Microsoft's Game Development Kit (GDK). -Windows (GDK) and Xbox One/Xbox Series (GDKX) are supported. Although most of the Xbox code is included in the public SDL source code, NDA access is required for a small number of source files. If you have access to GDKX, these required Xbox files are posted on the GDK forums [here](https://forums.xboxlive.com/questions/130003/). +Windows (GDK) and Xbox One/Xbox Series (GDKX) are both supported and all the required code is included in this public SDL release. However, only licensed Xbox developers have access to the GDKX libraries which will allow you to build the Xbox targets. Requirements ------------ * Microsoft Visual Studio 2022 (in theory, it should also work in 2017 or 2019, but this has not been tested) -* Microsoft GDK June 2022 or newer (public release [here](https://github.com/microsoft/GDK/releases/tag/June_2022)) -* To publish a package or successfully authenticate a user, you will need to create an app id/configure services in Partner Center. However, for local testing purposes (without authenticating on Xbox Live), the identifiers used by the GDK test programs in the included solution will work. +* Microsoft GDK October 2023 Update 1 or newer (public release [here](https://github.com/microsoft/GDK/releases/tag/October_2023_Update_1)) +* For Xbox, you will need the corresponding GDKX version (licensed developers only) +* To publish a package or successfully authenticate a user, you will need to create an app id/configure services in Partner Center. However, for local testing purposes (without authenticating on Xbox Live), the test identifiers used by the GDK test programs in the included solution work. Windows GDK Status @@ -32,8 +33,8 @@ The Windows GDK port supports the full set of Win32 APIs, renderers, controllers * Single-player games have some additional features available: * Call `SDL_GDKGetDefaultUser` to get the default XUserHandle pointer. * `SDL_GetPrefPath` still works, but only for single-player titles. - -These functions mostly wrap around async APIs, and thus should be treated as synchronous alternatives. Also note that the single-player functions return on any OS errors, so be sure to validate the return values! + + These functions mostly wrap around async APIs, and thus should be treated as synchronous alternatives. Also note that the single-player functions return on any OS errors, so be sure to validate the return values! * What doesn't work: * Compilation with anything other than through the included Visual C++ solution file @@ -74,7 +75,7 @@ While the Gaming.Desktop.x64 configuration sets most of the required settings, t * Under Linker > Input > Additional Dependencies, you need the following: * `SDL3.lib` * `xgameruntime.lib` - * `../Microsoft.Xbox.Services.141.GDK.C.Thunks.lib` + * `../Microsoft.Xbox.Services.GDK.C.Thunks.lib` * Note that in general, the GDK libraries depend on the MSVC C/C++ runtime, so there is no way to remove this dependency from a GDK program that links against GDK. ### 4. Setting up SDL_main ### @@ -86,7 +87,7 @@ Rather than using your own implementation of `WinMain`, it's recommended that yo The game will not launch in the debugger unless required DLLs are included in the directory that contains the game's .exe file. You need to make sure that the following files are copied into the directory: * Your SDL3.dll -* "$(Console_GRDKExtLibRoot)Xbox.Services.API.C\DesignTime\CommonConfiguration\Neutral\Lib\Release\Microsoft.Xbox.Services.141.GDK.C.Thunks.dll" +* "$(Console_GRDKExtLibRoot)Xbox.Services.API.C\DesignTime\CommonConfiguration\Neutral\Lib\Release\Microsoft.Xbox.Services.GDK.C.Thunks.dll" * XCurl.dll You can either copy these in a post-build step, or you can add the dlls into the project and set its Configuration Properties > General > Item type to "Copy file," which will also copy them into the output directory. @@ -143,6 +144,20 @@ To create the package: 6. Once the package is installed, you can run it from the start menu. 7. As with when running from Visual Studio, if you need to test any Xbox Live functionality you must switch to the correct sandbox. +Xbox GDKX Setup +--------------------- +In general, the same process in the Windows GDK instructions work. There are just a few additional notes: +* For Xbox One consoles, use the Gaming.Xbox.XboxOne.x64 target +* For Xbox Series consoles, use the Gaming.Xbox.Scarlett.x64 target +* The Xbox One target sets the `__XBOXONE__` define and the Xbox Series target sets the `__XBOXSERIES__` define +* You don't need to link against the Xbox.Services Thunks lib nor include that dll in your package (it doesn't exist for Xbox) +* The shader blobs for Xbox are created in a pre-build step for the Xbox targets, rather than included in the source (due to NDA and version compatability reasons) +* To create a package, use: + `makepkg pack /f PackageLayout.xml /lt /d . /pd Package` +* To install the package, use: + `xbapp install [PACKAGE].xvc` +* For some reason, if you make changes that require SDL3.dll to build, and you are running through the debugger (instead of a package), you have to rebuild your .exe target for the debugger to recognize the dll has changed and needs to be transferred to the console again +* While there are successful releases of Xbox titles using this port, it is not as extensively tested as other targets Troubleshooting --------------- diff --git a/src/core/SDL_core_unsupported.c b/src/core/SDL_core_unsupported.c index d67dab04d..b9e339742 100644 --- a/src/core/SDL_core_unsupported.c +++ b/src/core/SDL_core_unsupported.c @@ -224,3 +224,12 @@ Sint32 JNI_OnLoad(void *vm, void *reserved) return -1; /* JNI_ERR */ } #endif + +#if defined(__XBOXONE__) || defined(__XBOXSERIES__) +char *SDL_GetUserFolder(SDL_Folder folder) +{ + (void)folder; + SDL_Unsupported(); + return NULL; +} +#endif diff --git a/src/filesystem/gdk/SDL_sysfilesystem.cpp b/src/filesystem/gdk/SDL_sysfilesystem.cpp index 1fb0ff9a5..26f515746 100644 --- a/src/filesystem/gdk/SDL_sysfilesystem.cpp +++ b/src/filesystem/gdk/SDL_sysfilesystem.cpp @@ -18,7 +18,7 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "../../SDL_internal.h" +#include "SDL_internal.h" #ifdef SDL_FILESYSTEM_XBOX @@ -26,9 +26,9 @@ /* System dependent filesystem routines */ #include "../../core/windows/SDL_windows.h" -#include "SDL_hints.h" -#include "SDL_system.h" -#include "SDL_filesystem.h" +#include +#include +#include #include char * diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c index 1f5dafd38..f87fcb917 100644 --- a/src/render/direct3d12/SDL_render_d3d12.c +++ b/src/render/direct3d12/SDL_render_d3d12.c @@ -1435,7 +1435,7 @@ static void D3D12_FreeSRVIndex(SDL_Renderer *renderer, SIZE_T index) static int GetTextureProperty(SDL_PropertiesID props, const char *name, ID3D12Resource **texture) { - IUnknown *unknown = SDL_GetProperty(props, name, NULL); + IUnknown *unknown = (IUnknown*)SDL_GetProperty(props, name, NULL); if (unknown) { HRESULT result = D3D_CALL(unknown, QueryInterface, D3D_GUID(SDL_IID_ID3D12Resource), (void **)texture); if (FAILED(result)) { diff --git a/src/render/direct3d12/SDL_render_d3d12_xbox.cpp b/src/render/direct3d12/SDL_render_d3d12_xbox.cpp index a7fbef192..0c4605561 100644 --- a/src/render/direct3d12/SDL_render_d3d12_xbox.cpp +++ b/src/render/direct3d12/SDL_render_d3d12_xbox.cpp @@ -19,9 +19,156 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_internal.h" -#if defined(SDL_VIDEO_RENDER_D3D12) && !defined(SDL_RENDER_DISABLED) && (defined(__XBOXONE__) || defined(__XBOXSERIES__)) +#include "../../SDL_internal.h" +#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && (defined(__XBOXONE__) || defined(__XBOXSERIES__)) #include "SDL_render_d3d12_xbox.h" +#include "../../core/windows/SDL_windows.h" +#include + +#if defined(_MSC_VER) && !defined(__clang__) +#define SDL_COMPOSE_ERROR(str) __FUNCTION__ ", " str +#else +#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str +#endif + +static const GUID SDL_IID_ID3D12Device1 = { 0x77acce80, 0x638e, 0x4e65, { 0x88, 0x95, 0xc1, 0xf2, 0x33, 0x86, 0x86, 0x3e } }; +static const GUID SDL_IID_ID3D12Resource = { 0x696442be, 0xa72e, 0x4059, { 0xbc, 0x79, 0x5b, 0x5c, 0x98, 0x04, 0x0f, 0xad } }; +static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; + +extern "C" HRESULT +D3D12_XBOX_CreateDevice(ID3D12Device **device, SDL_bool createDebug) +{ + HRESULT result; + D3D12XBOX_CREATE_DEVICE_PARAMETERS params; + IDXGIDevice1 *dxgiDevice; + IDXGIAdapter *dxgiAdapter; + IDXGIOutput *dxgiOutput; + SDL_zero(params); + + params.Version = D3D12_SDK_VERSION; + params.ProcessDebugFlags = createDebug ? D3D12_PROCESS_DEBUG_FLAG_DEBUG_LAYER_ENABLED : D3D12XBOX_PROCESS_DEBUG_FLAG_NONE; + params.GraphicsCommandQueueRingSizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES; + params.GraphicsScratchMemorySizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES; + params.ComputeScratchMemorySizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES; + + result = D3D12XboxCreateDevice(NULL, ¶ms, SDL_IID_ID3D12Device1, (void **) device); + if (FAILED(result)) { + WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] D3D12XboxCreateDevice"), result); + goto done; + } + + result = (*device)->QueryInterface(SDL_IID_IDXGIDevice1, (void **) &dxgiDevice); + if (FAILED(result)) { + WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] ID3D12Device to IDXGIDevice1"), result); + goto done; + } + + result = dxgiDevice->GetAdapter(&dxgiAdapter); + if (FAILED(result)) { + WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] dxgiDevice->GetAdapter"), result); + goto done; + } + + result = dxgiAdapter->EnumOutputs(0, &dxgiOutput); + if (FAILED(result)) { + WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] dxgiAdapter->EnumOutputs"), result); + goto done; + } + + /* Set frame interval */ + result = (*device)->SetFrameIntervalX(dxgiOutput, D3D12XBOX_FRAME_INTERVAL_60_HZ, 1, D3D12XBOX_FRAME_INTERVAL_FLAG_NONE); + if (FAILED(result)) { + WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] SetFrameIntervalX"), result); + goto done; + } + + result = (*device)->ScheduleFrameEventX(D3D12XBOX_FRAME_EVENT_ORIGIN, 0, NULL, D3D12XBOX_SCHEDULE_FRAME_EVENT_FLAG_NONE); + if (FAILED(result)) { + WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("[xbox] ScheduleFrameEventX"), result); + goto done; + } + +done: + return result; +} + +extern "C" HRESULT +D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, void **resource) +{ + + D3D12_HEAP_PROPERTIES heapProps; + D3D12_RESOURCE_DESC resourceDesc; + + SDL_zero(heapProps); + heapProps.Type = D3D12_HEAP_TYPE_DEFAULT; + heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; + heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; + heapProps.CreationNodeMask = 1; + heapProps.VisibleNodeMask = 1; + + SDL_zero(resourceDesc); + resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + resourceDesc.Alignment = 0; + resourceDesc.Width = width; + resourceDesc.Height = height; + resourceDesc.DepthOrArraySize = 1; + resourceDesc.MipLevels = 1; + resourceDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + resourceDesc.SampleDesc.Count = 1; + resourceDesc.SampleDesc.Quality = 0; + resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; + resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + + return device->CreateCommittedResource(&heapProps, + D3D12_HEAP_FLAG_ALLOW_DISPLAY, + &resourceDesc, + D3D12_RESOURCE_STATE_PRESENT, + NULL, + SDL_IID_ID3D12Resource, + resource + ); +} + +extern "C" HRESULT +D3D12_XBOX_StartFrame(ID3D12Device1 *device, UINT64 *outToken) +{ + *outToken = D3D12XBOX_FRAME_PIPELINE_TOKEN_NULL; + return device->WaitFrameEventX(D3D12XBOX_FRAME_EVENT_ORIGIN, INFINITE, NULL, D3D12XBOX_WAIT_FRAME_EVENT_FLAG_NONE, outToken); +} + +extern "C" HRESULT +D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Resource *renderTarget) +{ + D3D12XBOX_PRESENT_PLANE_PARAMETERS planeParameters; + SDL_zero(planeParameters); + planeParameters.Token = token; + planeParameters.ResourceCount = 1; + planeParameters.ppResources = &renderTarget; + return commandQueue->PresentX(1, &planeParameters, NULL); +} + +extern "C" void +D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height) +{ + switch (XSystemGetDeviceType()) { + case XSystemDeviceType::XboxScarlettLockhart: + *width = 2560; + *height = 1440; + break; + + case XSystemDeviceType::XboxOneX: + case XSystemDeviceType::XboxScarlettAnaconda: + case XSystemDeviceType::XboxOneXDevkit: + case XSystemDeviceType::XboxScarlettDevkit: + *width = 3840; + *height = 2160; + break; + + default: + *width = 1920; + *height = 1080; + break; + } +} -#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info." #endif diff --git a/src/render/direct3d12/SDL_render_d3d12_xbox.h b/src/render/direct3d12/SDL_render_d3d12_xbox.h index 4f5ee1fc0..6db955a42 100644 --- a/src/render/direct3d12/SDL_render_d3d12_xbox.h +++ b/src/render/direct3d12/SDL_render_d3d12_xbox.h @@ -19,4 +19,31 @@ 3. This notice may not be removed or altered from any source distribution. */ -#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info." +#ifndef SDL_render_d3d12_xbox_h_ +#define SDL_render_d3d12_xbox_h_ + +#include "../../SDL_internal.h" + +#if defined(__XBOXONE__) +#include +#else /* __XBOXSERIES__ */ +#include +#endif + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +extern HRESULT D3D12_XBOX_CreateDevice(ID3D12Device **device, SDL_bool createDebug); +extern HRESULT D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, void **resource); +extern HRESULT D3D12_XBOX_StartFrame(ID3D12Device1 *device, UINT64 *outToken); +extern HRESULT D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Resource *renderTarget); +extern void D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp b/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp index 90339bf23..e224ffc2b 100644 --- a/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp +++ b/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp @@ -18,10 +18,127 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_internal.h" +#include "../../SDL_internal.h" -#if defined(SDL_VIDEO_RENDER_D3D12) && !defined(SDL_RENDER_DISABLED) && defined(__XBOXONE__) +#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__) -#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info." +#include + +#include "../../core/windows/SDL_windows.h" +#include + +#include "SDL_shaders_d3d12.h" + +#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str + +/* Shader blob headers are generated with a pre-build step using buildshaders.bat */ +#include "../VisualC-GDK/shaders/D3D12_PixelShader_Colors_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_Textures_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709_One.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG_One.h" + +#include "../VisualC-GDK/shaders/D3D12_VertexShader_Color_One.h" +#include "../VisualC-GDK/shaders/D3D12_VertexShader_NV_One.h" +#include "../VisualC-GDK/shaders/D3D12_VertexShader_Texture_One.h" +#include "../VisualC-GDK/shaders/D3D12_VertexShader_YUV_One.h" + +#include "../VisualC-GDK/shaders/D3D12_RootSig_Color_One.h" +#include "../VisualC-GDK/shaders/D3D12_RootSig_NV_One.h" +#include "../VisualC-GDK/shaders/D3D12_RootSig_Texture_One.h" +#include "../VisualC-GDK/shaders/D3D12_RootSig_YUV_One.h" + +static struct +{ + const void *ps_shader_data; + SIZE_T ps_shader_size; + const void *vs_shader_data; + SIZE_T vs_shader_size; + D3D12_RootSignature root_sig; +} D3D12_shaders[NUM_SHADERS] = { + { D3D12_PixelShader_Colors, sizeof(D3D12_PixelShader_Colors), + D3D12_VertexShader_Color, sizeof(D3D12_VertexShader_Color), + ROOTSIG_COLOR }, + { D3D12_PixelShader_Textures, sizeof(D3D12_PixelShader_Textures), + D3D12_VertexShader_Texture, sizeof(D3D12_VertexShader_Texture), + ROOTSIG_TEXTURE }, +#if SDL_HAVE_YUV + { D3D12_PixelShader_YUV_JPEG, sizeof(D3D12_PixelShader_YUV_JPEG), + D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV), + ROOTSIG_YUV }, + { D3D12_PixelShader_YUV_BT601, sizeof(D3D12_PixelShader_YUV_BT601), + D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV), + ROOTSIG_YUV }, + { D3D12_PixelShader_YUV_BT709, sizeof(D3D12_PixelShader_YUV_BT709), + D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV), + ROOTSIG_YUV }, + { D3D12_PixelShader_NV12_JPEG, sizeof(D3D12_PixelShader_NV12_JPEG), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV12_BT601, sizeof(D3D12_PixelShader_NV12_BT601), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV12_BT709, sizeof(D3D12_PixelShader_NV12_BT709), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV21_JPEG, sizeof(D3D12_PixelShader_NV21_JPEG), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV21_BT601, sizeof(D3D12_PixelShader_NV21_BT601), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV21_BT709, sizeof(D3D12_PixelShader_NV21_BT709), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, +#endif +}; + +static struct +{ + const void *rs_shader_data; + SIZE_T rs_shader_size; +} D3D12_rootsigs[NUM_ROOTSIGS] = { + { D3D12_RootSig_Color, sizeof(D3D12_RootSig_Color) }, + { D3D12_RootSig_Texture, sizeof(D3D12_RootSig_Texture) }, +#if SDL_HAVE_YUV + { D3D12_RootSig_YUV, sizeof(D3D12_RootSig_YUV) }, + { D3D12_RootSig_NV, sizeof(D3D12_RootSig_NV) }, +#endif +}; + +extern "C" void +D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +{ + outBytecode->pShaderBytecode = D3D12_shaders[shader].vs_shader_data; + outBytecode->BytecodeLength = D3D12_shaders[shader].vs_shader_size; +} + +extern "C" void +D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +{ + outBytecode->pShaderBytecode = D3D12_shaders[shader].ps_shader_data; + outBytecode->BytecodeLength = D3D12_shaders[shader].ps_shader_size; +} + +extern "C" D3D12_RootSignature +D3D12_GetRootSignatureType(D3D12_Shader shader) +{ + return D3D12_shaders[shader].root_sig; +} + +extern "C" void +D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode) +{ + outBytecode->pShaderBytecode = D3D12_rootsigs[rootSig].rs_shader_data; + outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size; +} #endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__) */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp b/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp index beeefabbd..29c20cd69 100644 --- a/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp +++ b/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp @@ -18,10 +18,127 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_internal.h" +#include "../../SDL_internal.h" -#if defined(SDL_VIDEO_RENDER_D3D12) && !defined(SDL_RENDER_DISABLED) && defined(__XBOXSERIES__) +#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__) -#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info." +#include + +#include "../../core/windows/SDL_windows.h" +#include + +#include "SDL_shaders_d3d12.h" + +#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str + +/* Shader blob headers are generated with a pre-build step using buildshaders.bat */ +#include "../VisualC-GDK/shaders/D3D12_PixelShader_Colors_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_Textures_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709_Series.h" +#include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG_Series.h" + +#include "../VisualC-GDK/shaders/D3D12_VertexShader_Color_Series.h" +#include "../VisualC-GDK/shaders/D3D12_VertexShader_Texture_Series.h" +#include "../VisualC-GDK/shaders/D3D12_VertexShader_NV_Series.h" +#include "../VisualC-GDK/shaders/D3D12_VertexShader_YUV_Series.h" + +#include "../VisualC-GDK/shaders/D3D12_RootSig_Color_Series.h" +#include "../VisualC-GDK/shaders/D3D12_RootSig_Texture_Series.h" +#include "../VisualC-GDK/shaders/D3D12_RootSig_YUV_Series.h" +#include "../VisualC-GDK/shaders/D3D12_RootSig_NV_Series.h" + +static struct +{ + const void *ps_shader_data; + SIZE_T ps_shader_size; + const void *vs_shader_data; + SIZE_T vs_shader_size; + D3D12_RootSignature root_sig; +} D3D12_shaders[NUM_SHADERS] = { + { D3D12_PixelShader_Colors, sizeof(D3D12_PixelShader_Colors), + D3D12_VertexShader_Color, sizeof(D3D12_VertexShader_Color), + ROOTSIG_COLOR }, + { D3D12_PixelShader_Textures, sizeof(D3D12_PixelShader_Textures), + D3D12_VertexShader_Texture, sizeof(D3D12_VertexShader_Texture), + ROOTSIG_TEXTURE }, +#if SDL_HAVE_YUV + { D3D12_PixelShader_YUV_JPEG, sizeof(D3D12_PixelShader_YUV_JPEG), + D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV), + ROOTSIG_YUV }, + { D3D12_PixelShader_YUV_BT601, sizeof(D3D12_PixelShader_YUV_BT601), + D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV), + ROOTSIG_YUV }, + { D3D12_PixelShader_YUV_BT709, sizeof(D3D12_PixelShader_YUV_BT709), + D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV), + ROOTSIG_YUV }, + { D3D12_PixelShader_NV12_JPEG, sizeof(D3D12_PixelShader_NV12_JPEG), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV12_BT601, sizeof(D3D12_PixelShader_NV12_BT601), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV12_BT709, sizeof(D3D12_PixelShader_NV12_BT709), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV21_JPEG, sizeof(D3D12_PixelShader_NV21_JPEG), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV21_BT601, sizeof(D3D12_PixelShader_NV21_BT601), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, + { D3D12_PixelShader_NV21_BT709, sizeof(D3D12_PixelShader_NV21_BT709), + D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV), + ROOTSIG_NV }, +#endif +}; + +static struct +{ + const void *rs_shader_data; + SIZE_T rs_shader_size; +} D3D12_rootsigs[NUM_ROOTSIGS] = { + { D3D12_RootSig_Color, sizeof(D3D12_RootSig_Color) }, + { D3D12_RootSig_Texture, sizeof(D3D12_RootSig_Texture) }, +#if SDL_HAVE_YUV + { D3D12_RootSig_YUV, sizeof(D3D12_RootSig_YUV) }, + { D3D12_RootSig_NV, sizeof(D3D12_RootSig_NV) }, +#endif +}; + +extern "C" void +D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +{ + outBytecode->pShaderBytecode = D3D12_shaders[shader].vs_shader_data; + outBytecode->BytecodeLength = D3D12_shaders[shader].vs_shader_size; +} + +extern "C" void +D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +{ + outBytecode->pShaderBytecode = D3D12_shaders[shader].ps_shader_data; + outBytecode->BytecodeLength = D3D12_shaders[shader].ps_shader_size; +} + +extern "C" D3D12_RootSignature +D3D12_GetRootSignatureType(D3D12_Shader shader) +{ + return D3D12_shaders[shader].root_sig; +} + +extern "C" void +D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode) +{ + outBytecode->pShaderBytecode = D3D12_rootsigs[rootSig].rs_shader_data; + outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size; +} #endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__) */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_video_unsupported.c b/src/video/SDL_video_unsupported.c index 633e717e1..0731f0380 100644 --- a/src/video/SDL_video_unsupported.c +++ b/src/video/SDL_video_unsupported.c @@ -41,7 +41,7 @@ int SDL_Direct3D9GetAdapterIndex(SDL_DisplayID displayID) #endif -#ifndef SDL_GDK_TEXTINPUT +#ifndef __GDK__ DECLSPEC int SDLCALL SDL_GDKGetTaskQueue(void *outTaskQueue); int SDL_GDKGetTaskQueue(void *outTaskQueue) @@ -81,3 +81,11 @@ void SDL_iPhoneSetEventPump(SDL_bool enabled) SDL_Unsupported(); } #endif + +#if defined(__XBOXONE__) || defined(__XBOXSERIES__) +int SDL_Direct3D9GetAdapterIndex(SDL_DisplayID displayID) +{ + (void)displayID; + return SDL_Unsupported(); +} +#endif diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 777291cdd..250ef8413 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -169,9 +169,11 @@ static SDL_Scancode WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam) } else { Uint16 vkCode = LOWORD(wParam); +#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) /* Windows may not report scan codes for some buttons (multimedia buttons etc). * Get scan code from the VK code.*/ scanCode = LOWORD(MapVirtualKey(vkCode, MAPVK_VK_TO_VSC_EX)); +#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ /* Pause/Break key have a special scan code with 0xe1 prefix. * Use Pause scan code that is used in Win32. */ @@ -515,8 +517,6 @@ WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) return 1; } -#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ - static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_WindowData *data, RAWMOUSE *rawmouse) { SDL_MouseID mouseID; @@ -692,6 +692,7 @@ void WIN_PollRawMouseInput(void) data->last_rawinput_poll = now; } +#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 896eb8126..2cab61dce 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -264,7 +264,7 @@ int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi) #endif #if defined(__XBOXONE__) || defined(__XBOXSERIES__) - AdjustWindowRectEx(&rect, style, menu, styleEx); + AdjustWindowRectEx(lpRect, style, menu, styleEx); #else if (WIN_IsPerMonitorV2DPIAware(videodevice)) { /* With per-monitor v2, the window border/titlebar size depend on the DPI, so we need to call AdjustWindowRectExForDpi instead of AdjustWindowRectEx. */ @@ -490,6 +490,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd data->initializing = SDL_FALSE; +#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) if (window->flags & SDL_WINDOW_EXTERNAL) { /* Query the title from the existing window */ LPTSTR title; @@ -510,6 +511,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd SDL_small_free(title, isstack); } } +#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ SDL_PropertiesID props = SDL_GetWindowProperties(window); SDL_SetProperty(props, SDL_PROPERTY_WINDOW_WIN32_HWND_POINTER, data->hwnd); @@ -554,7 +556,9 @@ static void CleanupWindowData(SDL_VideoDevice *_this, SDL_Window *window) #endif } } +#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) SDL_free(data->rawinput); +#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ SDL_free(data); } window->driverdata = NULL; @@ -672,6 +676,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI } } +#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) /* FIXME: does not work on all hardware configurations with different renders (i.e. hybrid GPUs) */ if (window->flags & SDL_WINDOW_TRANSPARENT) { void *handle = SDL_LoadObject("dwmapi.dll"); @@ -739,6 +744,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI return SDL_SetError("Could not create GL window (WGL support not configured)"); #endif } +#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ return 0; } diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index 9de65c3cc..49659a106 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -67,11 +67,13 @@ struct SDL_WindowData SDL_bool windowed_mode_was_maximized; SDL_bool in_window_deactivation; RECT cursor_clipped_rect; +#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) RAWINPUT *rawinput; UINT rawinput_offset; UINT rawinput_size; UINT rawinput_count; Uint64 last_rawinput_poll; +#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ SDL_Point last_raw_mouse_position; SDL_bool mouse_tracked; SDL_bool destroy_parent_with_window;