Make binding expose the preferred format
This commit is contained in:
parent
405dcd636a
commit
2e31e8f0bf
|
@ -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
|
||||
|
|
|
@ -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<nxtTextureFormat>(GetPreferredSwapChainTextureFormat()),
|
||||
NXT_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT, 640, 480);
|
||||
|
||||
const char* vs =
|
||||
"#version 450\n"
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -116,6 +116,10 @@ uint64_t GetSwapChainImplementation() {
|
|||
return binding->GetSwapChainImplementation();
|
||||
}
|
||||
|
||||
nxt::TextureFormat GetPreferredSwapChainTextureFormat() {
|
||||
return static_cast<nxt::TextureFormat>(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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<nxt::TextureFormat>(binding->GetPreferredSwapChainTextureFormat()),
|
||||
nxt::TextureUsageBit::OutputAttachment, 400, 400);
|
||||
|
||||
device.SetErrorCallback(DeviceErrorCauseTestFailure, 0);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -275,6 +275,10 @@ namespace utils {
|
|||
return reinterpret_cast<uint64_t>(&swapchainImpl);
|
||||
}
|
||||
|
||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
|
||||
}
|
||||
|
||||
private:
|
||||
nxtDevice backendDevice = nullptr;
|
||||
nxtSwapChainImplementation swapchainImpl = {};
|
||||
|
|
|
@ -136,6 +136,10 @@ namespace utils {
|
|||
return reinterpret_cast<uint64_t>(&swapchainImpl);
|
||||
}
|
||||
|
||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
|
||||
}
|
||||
|
||||
private:
|
||||
id<MTLDevice> metalDevice = nil;
|
||||
nxtDevice backendDevice = nullptr;
|
||||
|
|
|
@ -32,6 +32,9 @@ namespace utils {
|
|||
uint64_t GetSwapChainImplementation() override {
|
||||
return 0;
|
||||
}
|
||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -132,6 +132,10 @@ namespace utils {
|
|||
return reinterpret_cast<uint64_t>(&swapchainImpl);
|
||||
}
|
||||
|
||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
|
||||
}
|
||||
|
||||
private:
|
||||
nxtDevice backendDevice = nullptr;
|
||||
nxtSwapChainImplementation swapchainImpl = {};
|
||||
|
|
|
@ -32,6 +32,9 @@ namespace utils {
|
|||
uint64_t GetSwapChainImplementation() override {
|
||||
return 0;
|
||||
}
|
||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue