mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 22:56:09 +00:00
Update SwapChain to configure texture usage
Explicitly configure swap chain usage in bindings and examples Fix missing case in switch Make swap chain Present usage implicit Author: Austin Eng <enga@google.com>
This commit is contained in:
committed by
Kai Ninomiya
parent
08a0081c13
commit
ee7b6b1b62
@@ -34,17 +34,24 @@ namespace backend {
|
||||
return device;
|
||||
}
|
||||
|
||||
void SwapChainBase::Configure(nxt::TextureFormat format, uint32_t width, uint32_t height) {
|
||||
void SwapChainBase::Configure(nxt::TextureFormat format, nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit initialUsage, uint32_t width, uint32_t height) {
|
||||
if (width == 0 || height == 0) {
|
||||
device->HandleError("Swap chain cannot be configured to zero size");
|
||||
return;
|
||||
}
|
||||
allowedUsage |= nxt::TextureUsageBit::Present;
|
||||
if (!(HasZeroOrOneBits(initialUsage) && (initialUsage & allowedUsage))) {
|
||||
device->HandleError("Swap chain configured with invalid texture usage");
|
||||
return;
|
||||
}
|
||||
|
||||
this->format = format;
|
||||
this->allowedUsage = allowedUsage;
|
||||
this->initialUsage = initialUsage;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
implementation.Configure(implementation.userData,
|
||||
static_cast<nxtTextureFormat>(format), width, height);
|
||||
static_cast<nxtTextureFormat>(format), static_cast<nxtTextureUsageBit>(allowedUsage), static_cast<nxtTextureUsageBit>(initialUsage), width, height);
|
||||
}
|
||||
|
||||
TextureBase* SwapChainBase::GetNextTexture() {
|
||||
@@ -59,8 +66,8 @@ namespace backend {
|
||||
builder->SetExtent(width, height, 1);
|
||||
builder->SetFormat(format);
|
||||
builder->SetMipLevels(1);
|
||||
builder->SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::Present);
|
||||
builder->SetInitialUsage(nxt::TextureUsageBit::OutputAttachment);
|
||||
builder->SetAllowedUsage(allowedUsage);
|
||||
builder->SetInitialUsage(initialUsage);
|
||||
|
||||
auto* texture = GetNextTextureImpl(builder);
|
||||
lastNextTexture = texture;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace backend {
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
// NXT API
|
||||
void Configure(nxt::TextureFormat format, uint32_t width, uint32_t height);
|
||||
void Configure(nxt::TextureFormat format, nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit initialUsage, uint32_t width, uint32_t height);
|
||||
TextureBase* GetNextTexture();
|
||||
void Present(TextureBase* texture);
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace backend {
|
||||
DeviceBase* device = nullptr;
|
||||
nxtSwapChainImplementation implementation = {};
|
||||
nxt::TextureFormat format = {};
|
||||
nxt::TextureUsageBit allowedUsage;
|
||||
nxt::TextureUsageBit initialUsage;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
TextureBase* lastNextTexture = nullptr;
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace backend {
|
||||
bool TextureFormatHasDepthOrStencil(nxt::TextureFormat format) {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
return false;
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
return true;
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace opengl {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
return {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE};
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
return { GL_RGBA8UI, GL_RGBA, GL_UNSIGNED_INT };
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
return {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV};
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user