Compare commits
1 Commits
pf/renderd
...
ebridgewat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31f96c9065 |
@@ -354,6 +354,17 @@ void WebGPUDriver::destroyProgram(Handle<HwProgram> ph) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::destroyRenderTarget(Handle<HwRenderTarget> rth) {
|
void WebGPUDriver::destroyRenderTarget(Handle<HwRenderTarget> rth) {
|
||||||
|
if (rth) {
|
||||||
|
WGPURenderTarget* rt = handleCast<WGPURenderTarget>(rth);
|
||||||
|
if (rt == mDefaultRenderTarget) {
|
||||||
|
mDefaultRenderTarget = nullptr;
|
||||||
|
}
|
||||||
|
// WGPURenderTarget destructor is trivial.
|
||||||
|
// The HwTexture handles stored within WGPURenderTarget (via MRT, TargetBufferInfo)
|
||||||
|
// are not owned by WGPURenderTarget, so they are not destroyed here.
|
||||||
|
// They are destroyed via WebGPUDriver::destroyTexture.
|
||||||
|
destructHandle<WGPURenderTarget>(rth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::destroySwapChain(Handle<HwSwapChain> sch) {
|
void WebGPUDriver::destroySwapChain(Handle<HwSwapChain> sch) {
|
||||||
@@ -580,7 +591,21 @@ void WebGPUDriver::createDefaultRenderTargetR(Handle<HwRenderTarget> rth, int) {
|
|||||||
|
|
||||||
void WebGPUDriver::createRenderTargetR(Handle<HwRenderTarget> rth, TargetBufferFlags targets,
|
void WebGPUDriver::createRenderTargetR(Handle<HwRenderTarget> rth, TargetBufferFlags targets,
|
||||||
uint32_t width, uint32_t height, uint8_t samples, uint8_t layerCount, MRT color,
|
uint32_t width, uint32_t height, uint8_t samples, uint8_t layerCount, MRT color,
|
||||||
TargetBufferInfo depth, TargetBufferInfo stencil) {}
|
TargetBufferInfo depth, TargetBufferInfo stencil) {
|
||||||
|
// The `targets` flags indicate which of the `color`, `depth`, `stencil` TargetBufferInfo
|
||||||
|
// are actually active for this render target.
|
||||||
|
// We'll pass all TargetBufferInfo to WGPURenderTarget; it will use them if their handles are valid.
|
||||||
|
|
||||||
|
// Ensure that textures intended for use as attachments were created with
|
||||||
|
// wgpu::TextureUsage::RenderAttachment. This check should ideally be in createTextureR
|
||||||
|
// or validated here if possible.
|
||||||
|
|
||||||
|
// The `layerCount` parameter might be for creating array textures that this RT targets.
|
||||||
|
// Individual attachments (color[i].layer, depth.layer, stencil.layer) specify which layer
|
||||||
|
// of an array texture to bind. For now, we assume textures are pre-configured.
|
||||||
|
|
||||||
|
constructHandle<WGPURenderTarget>(rth, width, height, samples, color, depth, stencil);
|
||||||
|
}
|
||||||
|
|
||||||
void WebGPUDriver::createFenceR(Handle<HwFence> fh, int) {}
|
void WebGPUDriver::createFenceR(Handle<HwFence> fh, int) {}
|
||||||
|
|
||||||
@@ -845,35 +870,74 @@ void WebGPUDriver::compilePrograms(CompilerPriorityQueue priority,
|
|||||||
|
|
||||||
void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, RenderPassParams const& params) {
|
void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, RenderPassParams const& params) {
|
||||||
assert_invariant(mCommandEncoder);
|
assert_invariant(mCommandEncoder);
|
||||||
|
|
||||||
auto* renderTarget = handleCast<WGPURenderTarget>(rth);
|
auto* renderTarget = handleCast<WGPURenderTarget>(rth);
|
||||||
// if (renderTarget == mDefaultRenderTarget) {
|
|
||||||
// FWGPU_LOGW << "Default render target"
|
|
||||||
// << utils::io::endl;
|
|
||||||
// } else {
|
|
||||||
// FWGPU_LOGW << "Non Default render target"
|
|
||||||
// << utils::io::endl;
|
|
||||||
// }
|
|
||||||
wgpu::RenderPassDescriptor renderPassDescriptor;
|
|
||||||
wgpu::RenderPassDepthStencilAttachment depthStencilAttachment{
|
|
||||||
.view = mSwapChain->getDepthTextureView(),
|
|
||||||
.depthLoadOp = WGPURenderTarget::getLoadOperation(params, TargetBufferFlags::DEPTH),
|
|
||||||
.depthStoreOp = WGPURenderTarget::getStoreOperation(params, TargetBufferFlags::DEPTH),
|
|
||||||
.depthClearValue = static_cast<float>(params.clearDepth),
|
|
||||||
.depthReadOnly = (params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH) > 0,
|
|
||||||
.stencilLoadOp = WGPURenderTarget::getLoadOperation(params, TargetBufferFlags::STENCIL),
|
|
||||||
.stencilStoreOp = WGPURenderTarget::getStoreOperation(params, TargetBufferFlags::STENCIL),
|
|
||||||
.stencilClearValue = params.clearStencil,
|
|
||||||
.stencilReadOnly = (params.readOnlyDepthStencil & RenderPassParams::READONLY_STENCIL) > 0
|
|
||||||
};
|
|
||||||
renderTarget->setUpRenderPassAttachments(renderPassDescriptor, mTextureView, params);
|
|
||||||
renderPassDescriptor.depthStencilAttachment = &depthStencilAttachment;
|
|
||||||
|
|
||||||
assert_invariant(mTextureView);
|
wgpu::RenderPassDescriptor renderPassDescriptor{};
|
||||||
|
wgpu::TextureView defaultColorView = nullptr;
|
||||||
|
wgpu::TextureView defaultDepthStencilView = nullptr;
|
||||||
|
|
||||||
|
std::array<wgpu::TextureView, MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT> customColorViews{};
|
||||||
|
uint32_t customColorViewCount = 0;
|
||||||
|
wgpu::TextureView customDepthView = nullptr;
|
||||||
|
wgpu::TextureView customStencilView = nullptr;
|
||||||
|
|
||||||
|
if (renderTarget->isDefaultRenderTarget()) {
|
||||||
|
assert_invariant(mSwapChain && mTextureView);
|
||||||
|
defaultColorView = mTextureView;
|
||||||
|
defaultDepthStencilView = mSwapChain->getDepthTextureView();
|
||||||
|
} else {
|
||||||
|
// Resolve views for custom render target
|
||||||
|
const auto& colorInfos = renderTarget->getColorAttachmentInfos();
|
||||||
|
for (int i = 0; i < MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT; ++i) {
|
||||||
|
if (colorInfos[i].handle) {
|
||||||
|
auto* hwTexture = handleCast<WGPUTexture>(colorInfos[i].handle);
|
||||||
|
if (hwTexture) {
|
||||||
|
// TODO: Consider colorInfos[i].level and colorInfos[i].layer for view creation
|
||||||
|
// if WGPUTexture::getTexView() isn't sufficient or needs parameters.
|
||||||
|
customColorViews[customColorViewCount++] = hwTexture->getTexView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& depthInfo = renderTarget->getDepthAttachmentInfo();
|
||||||
|
if (depthInfo.handle) {
|
||||||
|
auto* hwTexture = handleCast<WGPUTexture>(depthInfo.handle);
|
||||||
|
if (hwTexture) {
|
||||||
|
customDepthView = hwTexture->getTexView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& stencilInfo = renderTarget->getStencilAttachmentInfo();
|
||||||
|
if (stencilInfo.handle) {
|
||||||
|
// If depth and stencil use the same texture handle, this will re-cast but that's fine.
|
||||||
|
auto* hwTexture = handleCast<WGPUTexture>(stencilInfo.handle);
|
||||||
|
if (hwTexture) {
|
||||||
|
customStencilView = hwTexture->getTexView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTarget->setUpRenderPassAttachments(renderPassDescriptor,
|
||||||
|
params,
|
||||||
|
defaultColorView,
|
||||||
|
defaultDepthStencilView,
|
||||||
|
customColorViews.data(),
|
||||||
|
customColorViewCount,
|
||||||
|
customDepthView,
|
||||||
|
customStencilView);
|
||||||
|
|
||||||
mRenderPassEncoder = mCommandEncoder.BeginRenderPass(&renderPassDescriptor);
|
mRenderPassEncoder = mCommandEncoder.BeginRenderPass(&renderPassDescriptor);
|
||||||
mRenderPassEncoder.SetViewport(params.viewport.left, params.viewport.bottom,
|
// Ensure viewport dimensions are positive
|
||||||
params.viewport.width, params.viewport.height, params.depthRange.near, params.depthRange.far);
|
uint32_t viewportWidth = params.viewport.width > 0 ? params.viewport.width : 1;
|
||||||
|
uint32_t viewportHeight = params.viewport.height > 0 ? params.viewport.height : 1;
|
||||||
|
|
||||||
|
mRenderPassEncoder.SetViewport(
|
||||||
|
static_cast<float>(params.viewport.left),
|
||||||
|
static_cast<float>(params.viewport.bottom),
|
||||||
|
static_cast<float>(viewportWidth),
|
||||||
|
static_cast<float>(viewportHeight),
|
||||||
|
params.depthRange.near,
|
||||||
|
params.depthRange.far);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::endRenderPass(int /* dummy */) {
|
void WebGPUDriver::endRenderPass(int /* dummy */) {
|
||||||
|
|||||||
@@ -923,58 +923,147 @@ wgpu::TextureView WGPUTexture::makeTextureView(const uint8_t& baseLevel, const u
|
|||||||
return textureView;
|
return textureView;
|
||||||
}
|
}
|
||||||
|
|
||||||
WGPURenderTarget::Attachment WGPURenderTarget::getDrawColorAttachment(size_t index) {
|
WGPURenderTarget::WGPURenderTarget(uint32_t width, uint32_t height, uint8_t samples,
|
||||||
assert_invariant( index < MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT);
|
const MRT& colorAttachmentsMRT,
|
||||||
auto result = color[index];
|
const Attachment& depthAttachmentInfo,
|
||||||
if (index == 0 && defaultRenderTarget) {
|
const Attachment& stencilAttachmentInfo)
|
||||||
|
: HwRenderTarget(width, height),
|
||||||
}
|
defaultRenderTarget(false),
|
||||||
|
samples(samples),
|
||||||
return result;
|
mColorAttachments(colorAttachmentsMRT),
|
||||||
|
mDepthAttachment(depthAttachmentInfo),
|
||||||
|
mStencilAttachment(stencilAttachmentInfo) {
|
||||||
|
mColorAttachmentDescriptors.reserve(MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Static helper to map MRT index to TargetBufferFlags
|
||||||
|
TargetBufferFlags WGPURenderTarget::getTargetBufferFlagsAt(int mrtIndex) {
|
||||||
|
if (mrtIndex < 0 || mrtIndex >= MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT) {
|
||||||
|
return TargetBufferFlags::NONE;
|
||||||
|
}
|
||||||
|
// This mapping assumes TargetBufferFlags::COLOR_0, COLOR_1 etc. are contiguous
|
||||||
|
return static_cast<TargetBufferFlags>(
|
||||||
|
static_cast<uint32_t>(TargetBufferFlags::COLOR0) << mrtIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Corrected getLoadOperation
|
||||||
wgpu::LoadOp WGPURenderTarget::getLoadOperation(RenderPassParams const& params,
|
wgpu::LoadOp WGPURenderTarget::getLoadOperation(RenderPassParams const& params,
|
||||||
TargetBufferFlags buffer) {
|
TargetBufferFlags bufferToOperateOn) {
|
||||||
auto clearFlags = params.flags.clear;
|
if (any(params.flags.clear & bufferToOperateOn)) {
|
||||||
auto discardStartFlags = params.flags.discardStart;
|
|
||||||
if (any(clearFlags & buffer)) {
|
|
||||||
return wgpu::LoadOp::Clear;
|
|
||||||
} else if (any(discardStartFlags & buffer)) {
|
|
||||||
return wgpu::LoadOp::Clear;
|
return wgpu::LoadOp::Clear;
|
||||||
}
|
}
|
||||||
|
if (any(params.flags.discardStart & bufferToOperateOn)) {
|
||||||
|
return wgpu::LoadOp::Clear; // Or wgpu::LoadOp::Undefined if clear is not desired on discard
|
||||||
|
}
|
||||||
return wgpu::LoadOp::Load;
|
return wgpu::LoadOp::Load;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Corrected getStoreOperation
|
||||||
wgpu::StoreOp WGPURenderTarget::getStoreOperation(RenderPassParams const& params,
|
wgpu::StoreOp WGPURenderTarget::getStoreOperation(RenderPassParams const& params,
|
||||||
TargetBufferFlags buffer) {
|
TargetBufferFlags bufferToOperateOn) {
|
||||||
const auto discardEndFlags = params.flags.discardEnd;
|
if (any(params.flags.discardEnd & bufferToOperateOn)) {
|
||||||
if (any(discardEndFlags & buffer)) {
|
|
||||||
return wgpu::StoreOp::Discard;
|
return wgpu::StoreOp::Discard;
|
||||||
}
|
}
|
||||||
return wgpu::StoreOp::Store;
|
return wgpu::StoreOp::Store;
|
||||||
}
|
}
|
||||||
void WGPURenderTarget::setUpRenderPassAttachments(wgpu::RenderPassDescriptor& descriptor,
|
|
||||||
wgpu::TextureView const& textureView, RenderPassParams const& params) {
|
void WGPURenderTarget::setUpRenderPassAttachments(
|
||||||
// auto discardFlags = params.flags.discardEnd;
|
wgpu::RenderPassDescriptor& descriptor,
|
||||||
// (void) discardFlags;
|
RenderPassParams const& params,
|
||||||
// std::vector<wgpu::RenderPassColorAttachment> colorAttachments;
|
wgpu::TextureView const& defaultColorTextureView,
|
||||||
colorAttachments.clear();
|
wgpu::TextureView const& defaultDepthStencilTextureView,
|
||||||
for (size_t i = 0; i < 1/*MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT*/; i++) {
|
wgpu::TextureView const* customColorTextureViews,
|
||||||
// auto attachment = getDrawColorAttachment(i);
|
uint32_t customColorTextureViewCount,
|
||||||
// if (attachment) {
|
wgpu::TextureView const& customDepthTextureView,
|
||||||
wgpu::RenderPassColorAttachment colorAttachment;
|
wgpu::TextureView const& customStencilTextureView) {
|
||||||
colorAttachment.view = textureView;
|
mColorAttachmentDescriptors.clear();
|
||||||
colorAttachment.loadOp = getLoadOperation(params, getTargetBufferFlagsAt(i));
|
mHasDepthStencilAttachment = false;
|
||||||
colorAttachment.storeOp = getStoreOperation(params, getTargetBufferFlagsAt(i));
|
|
||||||
colorAttachment.clearValue = { params.clearColor.r, params.clearColor.g, params.clearColor.b, params.clearColor.a };
|
if (defaultRenderTarget) {
|
||||||
colorAttachments.emplace_back(colorAttachment);
|
assert_invariant(defaultColorTextureView);
|
||||||
// }
|
wgpu::RenderPassColorAttachment colorAttDesc{};
|
||||||
|
colorAttDesc.view = defaultColorTextureView;
|
||||||
|
colorAttDesc.resolveTarget = nullptr;
|
||||||
|
colorAttDesc.loadOp = WGPURenderTarget::getLoadOperation(params, TargetBufferFlags::COLOR0);
|
||||||
|
colorAttDesc.storeOp = WGPURenderTarget::getStoreOperation(params, TargetBufferFlags::COLOR0);
|
||||||
|
colorAttDesc.clearValue = {params.clearColor.r, params.clearColor.g,
|
||||||
|
params.clearColor.b, params.clearColor.a};
|
||||||
|
mColorAttachmentDescriptors.push_back(colorAttDesc);
|
||||||
|
|
||||||
|
if (defaultDepthStencilTextureView) {
|
||||||
|
mDepthStencilAttachmentDescriptor = {
|
||||||
|
.view = defaultDepthStencilTextureView,
|
||||||
|
.depthLoadOp = WGPURenderTarget::getLoadOperation(params, TargetBufferFlags::DEPTH),
|
||||||
|
.depthStoreOp = WGPURenderTarget::getStoreOperation(params, TargetBufferFlags::DEPTH),
|
||||||
|
.depthClearValue = static_cast<float>(params.clearDepth),
|
||||||
|
.depthReadOnly = (params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH) > 0,
|
||||||
|
.stencilLoadOp = WGPURenderTarget::getLoadOperation(params, TargetBufferFlags::STENCIL),
|
||||||
|
.stencilStoreOp = WGPURenderTarget::getStoreOperation(params, TargetBufferFlags::STENCIL),
|
||||||
|
.stencilClearValue = params.clearStencil,
|
||||||
|
.stencilReadOnly = (params.readOnlyDepthStencil & RenderPassParams::READONLY_STENCIL) > 0,
|
||||||
|
};
|
||||||
|
mHasDepthStencilAttachment = true;
|
||||||
|
}
|
||||||
|
} else { // Custom Render Target
|
||||||
|
for (uint32_t i = 0; i < customColorTextureViewCount; ++i) {
|
||||||
|
if (customColorTextureViews[i]) {
|
||||||
|
wgpu::RenderPassColorAttachment colorAttDesc{};
|
||||||
|
colorAttDesc.view = customColorTextureViews[i];
|
||||||
|
colorAttDesc.resolveTarget = nullptr; // TODO: MSAA resolve for custom RT
|
||||||
|
colorAttDesc.loadOp = WGPURenderTarget::getLoadOperation(params, getTargetBufferFlagsAt(i));
|
||||||
|
colorAttDesc.storeOp = WGPURenderTarget::getStoreOperation(params, getTargetBufferFlagsAt(i));
|
||||||
|
colorAttDesc.clearValue = {params.clearColor.r, params.clearColor.g,
|
||||||
|
params.clearColor.b, params.clearColor.a};
|
||||||
|
mColorAttachmentDescriptors.push_back(colorAttDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wgpu::TextureView combinedDsView = customDepthTextureView ? customDepthTextureView : customStencilTextureView;
|
||||||
|
|
||||||
|
if (combinedDsView) {
|
||||||
|
mDepthStencilAttachmentDescriptor = {};
|
||||||
|
mDepthStencilAttachmentDescriptor.view = combinedDsView;
|
||||||
|
|
||||||
|
if (customDepthTextureView) {
|
||||||
|
mDepthStencilAttachmentDescriptor.depthLoadOp = WGPURenderTarget::getLoadOperation(params, TargetBufferFlags::DEPTH);
|
||||||
|
mDepthStencilAttachmentDescriptor.depthStoreOp = WGPURenderTarget::getStoreOperation(params, TargetBufferFlags::DEPTH);
|
||||||
|
mDepthStencilAttachmentDescriptor.depthClearValue = static_cast<float>(params.clearDepth);
|
||||||
|
mDepthStencilAttachmentDescriptor.depthReadOnly = (params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH) > 0;
|
||||||
|
} else {
|
||||||
|
mDepthStencilAttachmentDescriptor.depthLoadOp = wgpu::LoadOp::Undefined;
|
||||||
|
mDepthStencilAttachmentDescriptor.depthStoreOp = wgpu::StoreOp::Undefined;
|
||||||
|
mDepthStencilAttachmentDescriptor.depthReadOnly = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customStencilTextureView) {
|
||||||
|
mDepthStencilAttachmentDescriptor.stencilLoadOp = WGPURenderTarget::getLoadOperation(params, TargetBufferFlags::STENCIL);
|
||||||
|
mDepthStencilAttachmentDescriptor.stencilStoreOp = WGPURenderTarget::getStoreOperation(params, TargetBufferFlags::STENCIL);
|
||||||
|
mDepthStencilAttachmentDescriptor.stencilClearValue = params.clearStencil;
|
||||||
|
mDepthStencilAttachmentDescriptor.stencilReadOnly = (params.readOnlyDepthStencil & RenderPassParams::READONLY_STENCIL) > 0;
|
||||||
|
} else {
|
||||||
|
mDepthStencilAttachmentDescriptor.stencilLoadOp = wgpu::LoadOp::Undefined;
|
||||||
|
mDepthStencilAttachmentDescriptor.stencilStoreOp = wgpu::StoreOp::Undefined;
|
||||||
|
mDepthStencilAttachmentDescriptor.stencilReadOnly = true;
|
||||||
|
}
|
||||||
|
mHasDepthStencilAttachment = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
descriptor.colorAttachments = colorAttachments.data();
|
|
||||||
descriptor.colorAttachmentCount = colorAttachments.size();
|
descriptor.colorAttachmentCount = mColorAttachmentDescriptors.size();
|
||||||
descriptor.depthStencilAttachment = nullptr;
|
descriptor.colorAttachments = mColorAttachmentDescriptors.data();
|
||||||
descriptor.timestampWrites = nullptr;
|
descriptor.depthStencilAttachment = mHasDepthStencilAttachment ? &mDepthStencilAttachmentDescriptor : nullptr;
|
||||||
|
// descriptor.sampleCount was removed from the core spec. If your webgpu.h still has it,
|
||||||
|
// and your Dawn version expects it, you might need to set it here based on this->samples.
|
||||||
|
// e.g., descriptor.sampleCount = this->samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
math::uint2 WGPURenderTarget::getAttachmentSize() const noexcept {
|
||||||
|
if (!defaultRenderTarget) {
|
||||||
|
return {width, height};
|
||||||
|
}
|
||||||
|
// For default RT, size is dynamic and usually obtained from the swapchain.
|
||||||
|
// The caller (WebGPUDriver::beginRenderPass) should know the current swapchain size.
|
||||||
|
return {0,0};
|
||||||
|
}
|
||||||
|
|
||||||
}// namespace filament::backend
|
}// namespace filament::backend
|
||||||
|
|||||||
@@ -197,57 +197,66 @@ struct WGPURenderPrimitive : public HwRenderPrimitive {
|
|||||||
WGPUIndexBuffer* indexBuffer = nullptr;
|
WGPUIndexBuffer* indexBuffer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WGPURenderTarget : public HwRenderTarget {
|
class WGPURenderTarget : public HwRenderTarget {
|
||||||
public:
|
public:
|
||||||
class Attachment {
|
using Attachment = TargetBufferInfo; // Using TargetBufferInfo directly for attachments
|
||||||
public:
|
|
||||||
friend class WGPURenderTarget;
|
|
||||||
|
|
||||||
Attachment() = default;
|
|
||||||
Attachment(WGPUTexture* gpuTexture, uint8_t level = 0, uint16_t layer = 0)
|
|
||||||
: level(level),
|
|
||||||
layer(layer),
|
|
||||||
texture(gpuTexture->getTexture()),
|
|
||||||
mWGPUTexture(gpuTexture) {}
|
|
||||||
operator bool() const {
|
|
||||||
return mWGPUTexture != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t level = 0;
|
|
||||||
uint16_t layer = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
wgpu::Texture texture = nullptr;
|
|
||||||
WGPUTexture* mWGPUTexture = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
WGPURenderTarget(uint32_t width, uint32_t height, uint8_t samples,
|
WGPURenderTarget(uint32_t width, uint32_t height, uint8_t samples,
|
||||||
Attachment colorAttachments[MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT]);
|
const MRT& colorAttachments,
|
||||||
|
const Attachment& depthAttachment,
|
||||||
|
const Attachment& stencilAttachment);
|
||||||
|
|
||||||
|
// Default constructor for the default render target
|
||||||
WGPURenderTarget()
|
WGPURenderTarget()
|
||||||
: HwRenderTarget(0, 0),
|
: HwRenderTarget(0, 0),
|
||||||
defaultRenderTarget(true) {}
|
defaultRenderTarget(true),
|
||||||
|
samples(1) {}
|
||||||
|
|
||||||
void setUpRenderPassAttachments(wgpu::RenderPassDescriptor& descriptor,
|
// Updated signature: takes resolved views for custom RTs, and default views for default RT
|
||||||
wgpu::TextureView const& textureView, RenderPassParams const& params);
|
void setUpRenderPassAttachments(
|
||||||
|
wgpu::RenderPassDescriptor& descriptor,
|
||||||
|
RenderPassParams const& params,
|
||||||
|
// For default render target:
|
||||||
|
wgpu::TextureView const& defaultColorTextureView,
|
||||||
|
wgpu::TextureView const& defaultDepthStencilTextureView,
|
||||||
|
// For custom render targets:
|
||||||
|
wgpu::TextureView const* customColorTextureViews, // Array of views
|
||||||
|
uint32_t customColorTextureViewCount,
|
||||||
|
wgpu::TextureView const& customDepthTextureView,
|
||||||
|
wgpu::TextureView const& customStencilTextureView);
|
||||||
|
|
||||||
math::uint2 getAttachmentSize() noexcept;
|
|
||||||
|
math::uint2 getAttachmentSize() const noexcept;
|
||||||
|
|
||||||
bool isDefaultRenderTarget() const { return defaultRenderTarget; }
|
bool isDefaultRenderTarget() const { return defaultRenderTarget; }
|
||||||
uint8_t getSamples() const { return samples; }
|
uint8_t getSamples() const { return samples; }
|
||||||
|
|
||||||
Attachment getDrawColorAttachment(size_t index);
|
// Accessors for the driver to get stored attachment info
|
||||||
Attachment getReadColorAttachment(size_t index);
|
const MRT& getColorAttachmentInfos() const { return mColorAttachments; }
|
||||||
|
const Attachment& getDepthAttachmentInfo() const { return mDepthAttachment; }
|
||||||
|
const Attachment& getStencilAttachmentInfo() const { return mStencilAttachment; }
|
||||||
|
|
||||||
|
// Static helpers for load/store operations
|
||||||
static wgpu::LoadOp getLoadOperation(const RenderPassParams& params, TargetBufferFlags buffer);
|
static wgpu::LoadOp getLoadOperation(const RenderPassParams& params, TargetBufferFlags buffer);
|
||||||
static wgpu::StoreOp getStoreOperation(const RenderPassParams& params, TargetBufferFlags buffer);
|
static wgpu::StoreOp getStoreOperation(const RenderPassParams& params, TargetBufferFlags buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Helper to map MRT index to TargetBufferFlags
|
||||||
|
static TargetBufferFlags getTargetBufferFlagsAt(int mrtIndex);
|
||||||
|
|
||||||
bool defaultRenderTarget = false;
|
bool defaultRenderTarget = false;
|
||||||
uint8_t samples = 1;
|
uint8_t samples = 1;
|
||||||
|
|
||||||
Attachment color[MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT] = {};
|
MRT mColorAttachments{};
|
||||||
math::uint2 attachmentSize = {};
|
Attachment mDepthAttachment{};
|
||||||
std::vector<wgpu::RenderPassColorAttachment> colorAttachments{};
|
Attachment mStencilAttachment{};
|
||||||
};
|
|
||||||
|
|
||||||
|
// Cached descriptors for the render pass
|
||||||
|
std::vector<wgpu::RenderPassColorAttachment> mColorAttachmentDescriptors;
|
||||||
|
wgpu::RenderPassDepthStencilAttachment mDepthStencilAttachmentDescriptor{};
|
||||||
|
bool mHasDepthStencilAttachment = false;
|
||||||
|
};
|
||||||
}// namespace filament::backend
|
}// namespace filament::backend
|
||||||
#endif// TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H
|
#endif// TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H
|
||||||
|
|||||||
Reference in New Issue
Block a user