Atlas - SDL_render_d3d12_xbox.cpp

Home / ext / SDL / src / render / direct3d12 Lines: 1 | Size: 6048 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "../../SDL_internal.h" 23#if defined(SDL_VIDEO_RENDER_D3D12) && (defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)) 24#include "SDL_render_d3d12_xbox.h" 25#include "../../core/windows/SDL_windows.h" 26#include <XGameRuntime.h> 27 28static const GUID SDL_IID_ID3D12Device1 = { 0x77acce80, 0x638e, 0x4e65, { 0x88, 0x95, 0xc1, 0xf2, 0x33, 0x86, 0x86, 0x3e } }; 29static const GUID SDL_IID_ID3D12Resource = { 0x696442be, 0xa72e, 0x4059, { 0xbc, 0x79, 0x5b, 0x5c, 0x98, 0x04, 0x0f, 0xad } }; 30static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; 31 32extern "C" 33HRESULT D3D12_XBOX_CreateDevice(ID3D12Device **device, bool createDebug) 34{ 35 HRESULT result; 36 D3D12XBOX_CREATE_DEVICE_PARAMETERS params; 37 IDXGIDevice1 *dxgiDevice; 38 IDXGIAdapter *dxgiAdapter; 39 IDXGIOutput *dxgiOutput; 40 SDL_zero(params); 41 42 params.Version = D3D12_SDK_VERSION; 43 params.ProcessDebugFlags = createDebug ? D3D12_PROCESS_DEBUG_FLAG_DEBUG_LAYER_ENABLED : D3D12XBOX_PROCESS_DEBUG_FLAG_NONE; 44 params.GraphicsCommandQueueRingSizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES; 45 params.GraphicsScratchMemorySizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES; 46 params.ComputeScratchMemorySizeBytes = D3D12XBOX_DEFAULT_SIZE_BYTES; 47 48 result = D3D12XboxCreateDevice(NULL, &params, SDL_IID_ID3D12Device1, (void **) device); 49 if (FAILED(result)) { 50 WIN_SetErrorFromHRESULT("D3D12XboxCreateDevice", result); 51 goto done; 52 } 53 54 result = (*device)->QueryInterface(SDL_IID_IDXGIDevice1, (void **) &dxgiDevice); 55 if (FAILED(result)) { 56 WIN_SetErrorFromHRESULT("ID3D12Device to IDXGIDevice1", result); 57 goto done; 58 } 59 60 result = dxgiDevice->GetAdapter(&dxgiAdapter); 61 if (FAILED(result)) { 62 WIN_SetErrorFromHRESULT("dxgiDevice->GetAdapter", result); 63 goto done; 64 } 65 66 result = dxgiAdapter->EnumOutputs(0, &dxgiOutput); 67 if (FAILED(result)) { 68 WIN_SetErrorFromHRESULT("dxgiAdapter->EnumOutputs", result); 69 goto done; 70 } 71 72 // Set frame interval 73 result = (*device)->SetFrameIntervalX(dxgiOutput, D3D12XBOX_FRAME_INTERVAL_60_HZ, 1, D3D12XBOX_FRAME_INTERVAL_FLAG_NONE); 74 if (FAILED(result)) { 75 WIN_SetErrorFromHRESULT("SetFrameIntervalX", result); 76 goto done; 77 } 78 79 result = (*device)->ScheduleFrameEventX(D3D12XBOX_FRAME_EVENT_ORIGIN, 0, NULL, D3D12XBOX_SCHEDULE_FRAME_EVENT_FLAG_NONE); 80 if (FAILED(result)) { 81 WIN_SetErrorFromHRESULT("ScheduleFrameEventX", result); 82 goto done; 83 } 84 85done: 86 return result; 87} 88 89extern "C" 90HRESULT D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, void **resource) 91{ 92 93 D3D12_HEAP_PROPERTIES heapProps; 94 D3D12_RESOURCE_DESC resourceDesc; 95 96 SDL_zero(heapProps); 97 heapProps.Type = D3D12_HEAP_TYPE_DEFAULT; 98 heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; 99 heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; 100 heapProps.CreationNodeMask = 1; 101 heapProps.VisibleNodeMask = 1; 102 103 SDL_zero(resourceDesc); 104 resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; 105 resourceDesc.Alignment = 0; 106 resourceDesc.Width = width; 107 resourceDesc.Height = height; 108 resourceDesc.DepthOrArraySize = 1; 109 resourceDesc.MipLevels = 1; 110 resourceDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 111 resourceDesc.SampleDesc.Count = 1; 112 resourceDesc.SampleDesc.Quality = 0; 113 resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; 114 resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; 115 116 return device->CreateCommittedResource(&heapProps, 117 D3D12_HEAP_FLAG_ALLOW_DISPLAY, 118 &resourceDesc, 119 D3D12_RESOURCE_STATE_PRESENT, 120 NULL, 121 SDL_IID_ID3D12Resource, 122 resource 123 ); 124} 125 126extern "C" 127HRESULT D3D12_XBOX_StartFrame(ID3D12Device1 *device, UINT64 *outToken) 128{ 129 *outToken = D3D12XBOX_FRAME_PIPELINE_TOKEN_NULL; 130 return device->WaitFrameEventX(D3D12XBOX_FRAME_EVENT_ORIGIN, INFINITE, NULL, D3D12XBOX_WAIT_FRAME_EVENT_FLAG_NONE, outToken); 131} 132 133extern "C" 134HRESULT D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Resource *renderTarget) 135{ 136 D3D12XBOX_PRESENT_PLANE_PARAMETERS planeParameters; 137 SDL_zero(planeParameters); 138 planeParameters.Token = token; 139 planeParameters.ResourceCount = 1; 140 planeParameters.ppResources = &renderTarget; 141 return commandQueue->PresentX(1, &planeParameters, NULL); 142} 143 144extern "C" 145void D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height) 146{ 147 switch (XSystemGetDeviceType()) { 148 case XSystemDeviceType::XboxScarlettLockhart: 149 *width = 2560; 150 *height = 1440; 151 break; 152 153 case XSystemDeviceType::XboxOneX: 154 case XSystemDeviceType::XboxScarlettAnaconda: 155 case XSystemDeviceType::XboxOneXDevkit: 156 case XSystemDeviceType::XboxScarlettDevkit: 157 *width = 3840; 158 *height = 2160; 159 break; 160 161 default: 162 *width = 1920; 163 *height = 1080; 164 break; 165 } 166} 167 168#endif // SDL_VIDEO_RENDER_D3D12 && (SDL_PLATFORM_XBOXONE || SDL_PLATFORM_XBOXSERIES) 169
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.