diff --git a/examples/Animometer.cpp b/examples/Animometer.cpp index 1511192664..1ee720705d 100644 --- a/examples/Animometer.cpp +++ b/examples/Animometer.cpp @@ -49,7 +49,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( #version 450 diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp index 19f727ee2b..405282091e 100644 --- a/examples/CHelloTriangle.cpp +++ b/examples/CHelloTriangle.cpp @@ -39,7 +39,8 @@ void init() { swapchain = nxtSwapChainBuilderGetResult(builder); nxtSwapChainBuilderRelease(builder); } - nxtSwapChainConfigure(swapchain, NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM, NXT_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT, 640, 480); + nxtSwapChainConfigure(swapchain, static_cast(GetPreferredSwapChainTextureFormat()), + NXT_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT, 640, 480); const char* vs = "#version 450\n" diff --git a/examples/ComputeBoids.cpp b/examples/ComputeBoids.cpp index 5434c68a1e..1b874fa75c 100644 --- a/examples/ComputeBoids.cpp +++ b/examples/ComputeBoids.cpp @@ -291,7 +291,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); initBuffers(); initRender(); diff --git a/examples/HelloCompute.cpp b/examples/HelloCompute.cpp index 7b6a5937fb..9dcafc0dc9 100644 --- a/examples/HelloCompute.cpp +++ b/examples/HelloCompute.cpp @@ -35,7 +35,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); struct {uint32_t a; float b;} s; memset(&s, 0, sizeof(s)); diff --git a/examples/HelloDepthStencil.cpp b/examples/HelloDepthStencil.cpp index 81c49c2216..6d3fbb8ab2 100644 --- a/examples/HelloDepthStencil.cpp +++ b/examples/HelloDepthStencil.cpp @@ -116,7 +116,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); initBuffers(); diff --git a/examples/HelloIndices.cpp b/examples/HelloIndices.cpp index 691263d869..1e56a0533b 100644 --- a/examples/HelloIndices.cpp +++ b/examples/HelloIndices.cpp @@ -49,7 +49,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); initBuffers(); diff --git a/examples/HelloInstancing.cpp b/examples/HelloInstancing.cpp index c26e7ef36f..3c09e90eaf 100644 --- a/examples/HelloInstancing.cpp +++ b/examples/HelloInstancing.cpp @@ -52,7 +52,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); initBuffers(); diff --git a/examples/HelloTriangle.cpp b/examples/HelloTriangle.cpp index f540fc3468..18821d333e 100644 --- a/examples/HelloTriangle.cpp +++ b/examples/HelloTriangle.cpp @@ -83,7 +83,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); initBuffers(); initTextures(); diff --git a/examples/HelloUBO.cpp b/examples/HelloUBO.cpp index edd92d65e6..cda8767e92 100644 --- a/examples/HelloUBO.cpp +++ b/examples/HelloUBO.cpp @@ -33,7 +33,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( #version 450 diff --git a/examples/HelloVertices.cpp b/examples/HelloVertices.cpp index 6e4adabb27..585fbc5942 100644 --- a/examples/HelloVertices.cpp +++ b/examples/HelloVertices.cpp @@ -43,7 +43,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); initBuffers(); diff --git a/examples/RenderToTexture.cpp b/examples/RenderToTexture.cpp index 7e75b36565..4b48b01d72 100644 --- a/examples/RenderToTexture.cpp +++ b/examples/RenderToTexture.cpp @@ -167,7 +167,8 @@ void init() { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); initBuffers(); initTextures(); diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp index 0760d870a5..c641dc0c02 100644 --- a/examples/SampleUtils.cpp +++ b/examples/SampleUtils.cpp @@ -116,6 +116,10 @@ uint64_t GetSwapChainImplementation() { return binding->GetSwapChainImplementation(); } +nxt::TextureFormat GetPreferredSwapChainTextureFormat() { + return static_cast(binding->GetPreferredSwapChainTextureFormat()); +} + nxt::SwapChain GetSwapChain(const nxt::Device &device) { return device.CreateSwapChainBuilder() .SetImplementation(GetSwapChainImplementation()) @@ -125,7 +129,7 @@ nxt::SwapChain GetSwapChain(const nxt::Device &device) { nxt::RenderPass CreateDefaultRenderPass(const nxt::Device& device) { return device.CreateRenderPassBuilder() .SetAttachmentCount(2) - .AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm) + .AttachmentSetFormat(0, GetPreferredSwapChainTextureFormat()) .AttachmentSetColorLoadOp(0, nxt::LoadOp::Clear) .AttachmentSetFormat(1, nxt::TextureFormat::D32FloatS8Uint) .AttachmentSetDepthStencilLoadOps(1, nxt::LoadOp::Clear, nxt::LoadOp::Clear) diff --git a/examples/SampleUtils.h b/examples/SampleUtils.h index 22bf5c883a..e9d08d911c 100644 --- a/examples/SampleUtils.h +++ b/examples/SampleUtils.h @@ -24,6 +24,7 @@ struct GLFWwindow* GetGLFWWindow(); nxt::Device CreateCppNXTDevice(); uint64_t GetSwapChainImplementation(); +nxt::TextureFormat GetPreferredSwapChainTextureFormat(); nxt::SwapChain GetSwapChain(const nxt::Device& device); nxt::RenderPass CreateDefaultRenderPass(const nxt::Device& device); nxt::TextureView CreateDefaultDepthStencilView(const nxt::Device& device); diff --git a/examples/glTFViewer/glTFViewer.cpp b/examples/glTFViewer/glTFViewer.cpp index 37f637d6ff..dc94faa1ba 100644 --- a/examples/glTFViewer/glTFViewer.cpp +++ b/examples/glTFViewer/glTFViewer.cpp @@ -465,7 +465,8 @@ namespace { queue = device.CreateQueueBuilder().GetResult(); swapchain = GetSwapChain(device); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 640, 480); + swapchain.Configure(GetPreferredSwapChainTextureFormat(), + nxt::TextureUsageBit::OutputAttachment, 640, 480); renderpass = CreateDefaultRenderPass(device); depthStencilView = CreateDefaultDepthStencilView(device); diff --git a/src/tests/NXTTest.cpp b/src/tests/NXTTest.cpp index 61851a0143..f8fc4506b5 100644 --- a/src/tests/NXTTest.cpp +++ b/src/tests/NXTTest.cpp @@ -142,7 +142,8 @@ void NXTTest::SetUp() { swapchain = device.CreateSwapChainBuilder() .SetImplementation(binding->GetSwapChainImplementation()) .GetResult(); - swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::OutputAttachment, 400, 400); + swapchain.Configure(static_cast(binding->GetPreferredSwapChainTextureFormat()), + nxt::TextureUsageBit::OutputAttachment, 400, 400); device.SetErrorCallback(DeviceErrorCauseTestFailure, 0); } diff --git a/src/utils/BackendBinding.h b/src/utils/BackendBinding.h index b40b21793e..f8cdba1c8e 100644 --- a/src/utils/BackendBinding.h +++ b/src/utils/BackendBinding.h @@ -38,6 +38,7 @@ namespace utils { virtual void SetupGLFWWindowHints() = 0; virtual void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) = 0; virtual uint64_t GetSwapChainImplementation() = 0; + virtual nxtTextureFormat GetPreferredSwapChainTextureFormat() = 0; void SetWindow(GLFWwindow* window); diff --git a/src/utils/D3D12Binding.cpp b/src/utils/D3D12Binding.cpp index 3e99eac52e..dcd22ee12f 100644 --- a/src/utils/D3D12Binding.cpp +++ b/src/utils/D3D12Binding.cpp @@ -275,6 +275,10 @@ namespace utils { return reinterpret_cast(&swapchainImpl); } + nxtTextureFormat GetPreferredSwapChainTextureFormat() override { + return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; + } + private: nxtDevice backendDevice = nullptr; nxtSwapChainImplementation swapchainImpl = {}; diff --git a/src/utils/MetalBinding.mm b/src/utils/MetalBinding.mm index e5953b1af3..a0119aacb6 100644 --- a/src/utils/MetalBinding.mm +++ b/src/utils/MetalBinding.mm @@ -136,6 +136,10 @@ namespace utils { return reinterpret_cast(&swapchainImpl); } + nxtTextureFormat GetPreferredSwapChainTextureFormat() override { + return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; + } + private: id metalDevice = nil; nxtDevice backendDevice = nullptr; diff --git a/src/utils/NullBinding.cpp b/src/utils/NullBinding.cpp index 74ae78a7a4..aaec0a74dd 100644 --- a/src/utils/NullBinding.cpp +++ b/src/utils/NullBinding.cpp @@ -32,6 +32,9 @@ namespace utils { uint64_t GetSwapChainImplementation() override { return 0; } + nxtTextureFormat GetPreferredSwapChainTextureFormat() override { + return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; + } }; diff --git a/src/utils/OpenGLBinding.cpp b/src/utils/OpenGLBinding.cpp index 62e8bbb101..5618dcebdf 100644 --- a/src/utils/OpenGLBinding.cpp +++ b/src/utils/OpenGLBinding.cpp @@ -132,6 +132,10 @@ namespace utils { return reinterpret_cast(&swapchainImpl); } + nxtTextureFormat GetPreferredSwapChainTextureFormat() override { + return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; + } + private: nxtDevice backendDevice = nullptr; nxtSwapChainImplementation swapchainImpl = {}; diff --git a/src/utils/VulkanBinding.cpp b/src/utils/VulkanBinding.cpp index 869ac2c020..0caacce870 100644 --- a/src/utils/VulkanBinding.cpp +++ b/src/utils/VulkanBinding.cpp @@ -32,6 +32,9 @@ namespace utils { uint64_t GetSwapChainImplementation() override { return 0; } + nxtTextureFormat GetPreferredSwapChainTextureFormat() override { + return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; + } };