Resolving conflicts
This commit is contained in:
committed by
Jeremy Nelson
parent
f44d1cbfe4
commit
2cfae31e9a
@@ -259,7 +259,7 @@ Handle<HwSwapChain> WebGPUDriver::createSwapChainS() noexcept {
|
||||
}
|
||||
|
||||
Handle<HwSwapChain> WebGPUDriver::createSwapChainHeadlessS() noexcept {
|
||||
return Handle<HwSwapChain>((Handle<HwSwapChain>::HandleId) mNextFakeHandle++);
|
||||
return allocHandle<WebGPUSwapChain>();
|
||||
}
|
||||
|
||||
Handle<HwTexture> WebGPUDriver::createTextureS() noexcept {
|
||||
@@ -343,8 +343,8 @@ void WebGPUDriver::createSwapChainR(Handle<HwSwapChain> sch, void* nativeWindow,
|
||||
assert_invariant(!mSwapChain);
|
||||
wgpu::Surface surface = mPlatform.createSurface(nativeWindow, flags);
|
||||
|
||||
wgpu::Extent2D surfaceSize = mPlatform.getSurfaceExtent(mNativeWindow);
|
||||
mSwapChain = constructHandle<WebGPUSwapChain>(sch, std::move(surface), surfaceSize, mAdapter,
|
||||
wgpu::Extent2D extent = mPlatform.getSurfaceExtent(mNativeWindow);
|
||||
mSwapChain = constructHandle<WebGPUSwapChain>(sch, std::move(surface), extent, mAdapter,
|
||||
mDevice, flags);
|
||||
assert_invariant(mSwapChain);
|
||||
|
||||
@@ -360,7 +360,12 @@ void WebGPUDriver::createSwapChainR(Handle<HwSwapChain> sch, void* nativeWindow,
|
||||
}
|
||||
|
||||
void WebGPUDriver::createSwapChainHeadlessR(Handle<HwSwapChain> sch, uint32_t width,
|
||||
uint32_t height, uint64_t flags) {}
|
||||
uint32_t height, uint64_t flags) {
|
||||
wgpu::Extent2D extent = { width, height};
|
||||
mSwapChain = constructHandle<WebGPUSwapChain>(sch, extent, mAdapter,
|
||||
mDevice, flags);
|
||||
assert_invariant(mSwapChain);
|
||||
}
|
||||
|
||||
void WebGPUDriver::createVertexBufferInfoR(Handle<HwVertexBufferInfo> vertexBufferInfoHandle,
|
||||
const uint8_t bufferCount, const uint8_t attributeCount, const AttributeArray attributes) {
|
||||
@@ -991,7 +996,7 @@ void WebGPUDriver::makeCurrent(Handle<HwSwapChain> drawSch, Handle<HwSwapChain>
|
||||
mSwapChain = swapChain;
|
||||
assert_invariant(mSwapChain);
|
||||
wgpu::Extent2D surfaceSize = mPlatform.getSurfaceExtent(mNativeWindow);
|
||||
mTextureView = mSwapChain->getCurrentSurfaceTextureView(surfaceSize);
|
||||
mTextureView = mSwapChain->getCurrentTextureView(surfaceSize, mDevice);
|
||||
assert_invariant(mTextureView);
|
||||
|
||||
assert_invariant(mDefaultRenderTarget);
|
||||
|
||||
@@ -184,16 +184,14 @@ void printSurfaceConfiguration(wgpu::SurfaceConfiguration const& config,
|
||||
}
|
||||
|
||||
void initConfig(wgpu::SurfaceConfiguration& config, wgpu::Device const& device,
|
||||
wgpu::SurfaceCapabilities const& capabilities, wgpu::Extent2D const& surfaceSize,
|
||||
wgpu::SurfaceCapabilities const& capabilities, wgpu::Extent2D const& extent,
|
||||
bool useSRGBColorSpace) {
|
||||
config.device = device;
|
||||
config.usage = wgpu::TextureUsage::RenderAttachment;
|
||||
config.width = surfaceSize.width;
|
||||
config.height = surfaceSize.height;
|
||||
config.format =
|
||||
selectColorFormat(capabilities.formatCount, capabilities.formats, useSRGBColorSpace);
|
||||
config.presentMode =
|
||||
selectPresentMode(capabilities.presentModeCount, capabilities.presentModes);
|
||||
config.width = extent.width;
|
||||
config.height = extent.height;
|
||||
config.format = selectColorFormat(capabilities.formatCount, capabilities.formats, useSRGBColorSpace);
|
||||
config.presentMode = selectPresentMode(capabilities.presentModeCount, capabilities.presentModes);
|
||||
config.alphaMode = selectAlphaMode(capabilities.alphaModeCount, capabilities.alphaModes);
|
||||
}
|
||||
|
||||
@@ -249,8 +247,11 @@ void initConfig(wgpu::SurfaceConfiguration& config, wgpu::Device const& device,
|
||||
|
||||
WebGPUSwapChain::WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& surfaceSize,
|
||||
wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags)
|
||||
: mDevice(device),
|
||||
mSurface(surface),
|
||||
: mSurface(surface),
|
||||
mType(SwapChainType::SURFACE),
|
||||
mHeadlessWidth(0),
|
||||
mHeadlessHeight(0),
|
||||
mDevice(device),
|
||||
mNeedStencil((flags & SWAP_CHAIN_HAS_STENCIL_BUFFER) != 0),
|
||||
mDepthFormat(selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
|
||||
mNeedStencil)),
|
||||
@@ -265,14 +266,58 @@ WebGPUSwapChain::WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const&
|
||||
#endif
|
||||
}
|
||||
const bool useSRGBColorSpace = (flags & SWAP_CHAIN_CONFIG_SRGB_COLORSPACE) != 0;
|
||||
initConfig(mConfig, device, capabilities, surfaceSize, useSRGBColorSpace);
|
||||
const bool needStencil = (flags & SWAP_CHAIN_HAS_STENCIL_BUFFER) != 0;
|
||||
initConfig(mConfig, device, capabilities, extent, useSRGBColorSpace);
|
||||
mDepthFormat = selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
|
||||
needStencil);
|
||||
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
|
||||
printSurfaceConfiguration(mConfig, mDepthFormat);
|
||||
#endif
|
||||
mSurface.Configure(&mConfig);
|
||||
}
|
||||
|
||||
WebGPUSwapChain::~WebGPUSwapChain() { mSurface.Unconfigure(); }
|
||||
WebGPUSwapChain::~WebGPUSwapChain() {
|
||||
mSurface.Unconfigure();
|
||||
}
|
||||
|
||||
WebGPUSwapChain::WebGPUSwapChain(wgpu::Extent2D const& extent,
|
||||
wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags)
|
||||
: mType(SwapChainType::HEADLESS),
|
||||
mHeadlessWidth(extent.width),
|
||||
mHeadlessHeight(extent.height){
|
||||
|
||||
//TODO: review these initializations as webgpu pipeline gets mature
|
||||
const wgpu::TextureFormat renderTargetFormat = wgpu::TextureFormat::RGBA8Unorm;
|
||||
const wgpu::TextureDescriptor textureDescriptor = createRenderTargetDescriptor(mHeadlessWidth, mHeadlessHeight, renderTargetFormat);
|
||||
|
||||
//TODO: eventually merge with handles
|
||||
mRenderTargetTextures.fill(nullptr);
|
||||
mRenderTargetViews.fill(nullptr);
|
||||
|
||||
for (size_t i = 0; i < mHeadlessBufferCount; ++i) {
|
||||
mRenderTargetTextures[i] = device.CreateTexture(&textureDescriptor);
|
||||
wgpu::TextureViewDescriptor viewDesc{};
|
||||
viewDesc.format = textureDescriptor.format;
|
||||
viewDesc.dimension = wgpu::TextureViewDimension::e2D;
|
||||
viewDesc.baseMipLevel = 0;
|
||||
viewDesc.mipLevelCount = 1;
|
||||
viewDesc.baseArrayLayer = 0;
|
||||
viewDesc.arrayLayerCount = 1;
|
||||
viewDesc.aspect = wgpu::TextureAspect::All;
|
||||
mRenderTargetViews[i] = mRenderTargetTextures[i].CreateView(&viewDesc);
|
||||
}
|
||||
}
|
||||
|
||||
WebGPUSwapChain::~WebGPUSwapChain() {
|
||||
if (isHeadless()) {
|
||||
for (auto& texture: mRenderTargetTextures) {
|
||||
if (texture) texture.Destroy();
|
||||
}
|
||||
} else {
|
||||
mSurface.Unconfigure();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WebGPUSwapChain::setExtent(wgpu::Extent2D const& currentSurfaceSize) {
|
||||
FILAMENT_CHECK_POSTCONDITION(currentSurfaceSize.width > 0 || currentSurfaceSize.height > 0)
|
||||
@@ -293,16 +338,20 @@ void WebGPUSwapChain::setExtent(wgpu::Extent2D const& currentSurfaceSize) {
|
||||
}
|
||||
}
|
||||
|
||||
wgpu::TextureView WebGPUSwapChain::getCurrentSurfaceTextureView(
|
||||
wgpu::Extent2D const& currentSurfaceSize) {
|
||||
setExtent(currentSurfaceSize);
|
||||
wgpu::TextureView WebGPUSwapChain::getCurrentTextureView( wgpu::Extent2D const& extent, wgpu::Device const& device) {
|
||||
|
||||
if(isHeadless()){
|
||||
return mRenderTargetViews[mHeadlessBufferIndex];
|
||||
}
|
||||
|
||||
setExtent(extent);
|
||||
wgpu::SurfaceTexture surfaceTexture;
|
||||
mSurface.GetCurrentTexture(&surfaceTexture);
|
||||
if (surfaceTexture.status != wgpu::SurfaceGetCurrentTextureStatus::SuccessOptimal) {
|
||||
return nullptr;
|
||||
}
|
||||
// Create a view for this surface texture
|
||||
// TODO: review these initiliazations as webgpu pipeline gets mature
|
||||
|
||||
// TODO: review these initializations as webgpu pipeline gets mature
|
||||
wgpu::TextureViewDescriptor textureViewDescriptor = {
|
||||
.label = "surface_texture_view",
|
||||
.format = surfaceTexture.texture.GetFormat(),
|
||||
@@ -315,8 +364,22 @@ wgpu::TextureView WebGPUSwapChain::getCurrentSurfaceTextureView(
|
||||
return surfaceTexture.texture.CreateView(&textureViewDescriptor);
|
||||
}
|
||||
|
||||
wgpu::TextureDescriptor WebGPUSwapChain::createRenderTargetDescriptor(uint32_t width,
|
||||
uint32_t height, wgpu::TextureFormat format) {
|
||||
wgpu::TextureDescriptor desc;
|
||||
desc.size = { width, height, 1 };
|
||||
desc.format = format;
|
||||
desc.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc;
|
||||
desc.mipLevelCount = 1;
|
||||
desc.sampleCount = 1;
|
||||
desc.dimension = wgpu::TextureDimension::e2D;
|
||||
return desc;
|
||||
}
|
||||
|
||||
void WebGPUSwapChain::present() {
|
||||
assert_invariant(mSurface);
|
||||
if(isHeadless()){
|
||||
mHeadlessBufferIndex = (mHeadlessBufferIndex + 1) % mHeadlessBufferCount;
|
||||
}
|
||||
mSurface.Present();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,30 +28,53 @@ namespace filament::backend {
|
||||
|
||||
class WebGPUSwapChain final : public Platform::SwapChain, HwSwapChain {
|
||||
public:
|
||||
WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& surfaceSize,
|
||||
WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& extent,
|
||||
wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags);
|
||||
|
||||
WebGPUSwapChain( wgpu::Extent2D const& extent,
|
||||
wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags);
|
||||
|
||||
~WebGPUSwapChain();
|
||||
|
||||
[[nodiscard]] wgpu::TextureFormat getColorFormat() const { return mConfig.format; }
|
||||
|
||||
[[nodiscard]] wgpu::TextureFormat getDepthFormat() const { return mDepthFormat; }
|
||||
|
||||
[[nodiscard]] wgpu::TextureView getCurrentSurfaceTextureView(wgpu::Extent2D const&);
|
||||
[[nodiscard]] wgpu::TextureView getCurrentTextureView(wgpu::Extent2D const& extent, wgpu::Device const& device );
|
||||
|
||||
[[nodiscard]] wgpu::TextureDescriptor createRenderTargetDescriptor(uint32_t width, uint32_t height, wgpu::TextureFormat format);
|
||||
|
||||
[[nodiscard]] wgpu::TextureView getDepthTextureView() const { return mDepthTextureView; }
|
||||
|
||||
void present();
|
||||
|
||||
private:
|
||||
|
||||
[[nodiscard]] bool isHeadless() const { return mType == SwapChainType::HEADLESS; }
|
||||
|
||||
void setExtent(wgpu::Extent2D const&);
|
||||
|
||||
wgpu::Device mDevice = nullptr;
|
||||
enum class SwapChainType {
|
||||
HEADLESS,
|
||||
SURFACE
|
||||
};
|
||||
|
||||
wgpu::Surface mSurface = {};
|
||||
wgpu::SurfaceConfiguration mConfig = {};
|
||||
bool mNeedStencil = false;
|
||||
wgpu::TextureFormat mDepthFormat = wgpu::TextureFormat::Undefined;
|
||||
wgpu::Texture mDepthTexture = nullptr;
|
||||
wgpu::TextureView mDepthTextureView = nullptr;
|
||||
const SwapChainType mType;
|
||||
const uint32_t mHeadlessWidth;
|
||||
const uint32_t mHeadlessHeight;
|
||||
|
||||
///TODO: eventually config for double or triple buffering
|
||||
const uint32_t mHeadlessBufferCount = 3;
|
||||
uint32_t mHeadlessBufferIndex = 0;
|
||||
std::array<wgpu::Texture, 3> mRenderTargetTextures;
|
||||
std::array<wgpu::TextureView, 3> mRenderTargetViews;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
Reference in New Issue
Block a user