Compare commits
8 Commits
v1.62.1
...
pf/add-dox
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edb77fe6a9 | ||
|
|
954d1021c7 | ||
|
|
bf598071a3 | ||
|
|
5cbc2321c7 | ||
|
|
6bee5fb56f | ||
|
|
eb0fcc065b | ||
|
|
117535364b | ||
|
|
b15ae15f39 |
@@ -273,6 +273,8 @@ if (FILAMENT_SUPPORTS_WEBGPU)
|
||||
src/webgpu/WebGPUFence.h
|
||||
src/webgpu/WebGPUIndexBuffer.cpp
|
||||
src/webgpu/WebGPUIndexBuffer.h
|
||||
src/webgpu/WebGPUMsaaTextureResolver.cpp
|
||||
src/webgpu/WebGPUMsaaTextureResolver.h
|
||||
src/webgpu/WebGPUPipelineCreation.cpp
|
||||
src/webgpu/WebGPUPipelineCreation.h
|
||||
src/webgpu/WebGPUProgram.cpp
|
||||
|
||||
764
filament/backend/include/private/backend/DriverAPI.dox
Normal file
764
filament/backend/include/private/backend/DriverAPI.dox
Normal file
@@ -0,0 +1,764 @@
|
||||
/** @file DriverAPI.dox
|
||||
* @brief External documentation for the backend::Driver API.
|
||||
*
|
||||
* This file contains Doxygen documentation for the functions declared in DriverAPI.inc.
|
||||
* This is used to keep the documentation separate from the macro-heavy header file.
|
||||
*/
|
||||
|
||||
// General lifecycle and frame management
|
||||
|
||||
/** @fn Driver::tick()
|
||||
* @brief Called periodically by the system to perform maintenance tasks.
|
||||
*/
|
||||
|
||||
/** @fn Driver::beginFrame(int64_t monotonic_clock_ns, int64_t refreshIntervalNs, uint32_t frameId)
|
||||
* @brief Signals the beginning of a new frame to the driver.
|
||||
* @param monotonic_clock_ns The current monotonic clock time in nanoseconds.
|
||||
* @param refreshIntervalNs The display's refresh interval in nanoseconds.
|
||||
* @param frameId A unique identifier for the new frame.
|
||||
*/
|
||||
|
||||
/** @fn Driver::setFrameScheduledCallback(backend::SwapChainHandle sch, backend::CallbackHandler* handler, backend::FrameScheduledCallback&& callback, uint64_t flags)
|
||||
* @brief Schedules a callback to be executed when the frame associated with the given swap chain has been scheduled for presentation.
|
||||
* @param sch The handle of the swap chain.
|
||||
* @param handler The callback handler that will execute the callback.
|
||||
* @param callback The function to be called.
|
||||
* @param flags Flags to control the callback behavior.
|
||||
*/
|
||||
|
||||
/** @fn Driver::setFrameCompletedCallback(backend::SwapChainHandle sch, backend::CallbackHandler* handler, utils::Invocable<void(void)>&& callback)
|
||||
* @brief Sets a callback to be executed when rendering to the given swap chain is complete for the current frame.
|
||||
* @param sch The handle of the swap chain.
|
||||
* @param handler The callback handler that will execute the callback.
|
||||
* @param callback The function to be called upon frame completion.
|
||||
*/
|
||||
|
||||
/** @fn Driver::setPresentationTime(int64_t monotonic_clock_ns)
|
||||
* @brief Informs the driver of the intended presentation time for the current frame.
|
||||
* @param monotonic_clock_ns The desired presentation time in nanoseconds, based on the monotonic clock.
|
||||
*/
|
||||
|
||||
/** @fn Driver::endFrame(uint32_t frameId)
|
||||
* @brief Signals the end of a frame to the driver.
|
||||
* @param frameId The unique identifier of the frame that is ending.
|
||||
*/
|
||||
|
||||
/** @fn Driver::flush()
|
||||
* @brief Submits all pending commands to the GPU for execution, without waiting for them to complete.
|
||||
*/
|
||||
|
||||
/** @fn Driver::finish()
|
||||
* @brief Submits all pending commands and waits for the GPU to finish executing them.
|
||||
*/
|
||||
|
||||
/** @fn Driver::resetState()
|
||||
* @brief Resets any cached or tracked driver state, forcing the driver to re-evaluate and set all states.
|
||||
*/
|
||||
|
||||
/** @fn Driver::setDebugTag(backend::HandleBase::HandleId handleId, utils::CString tag)
|
||||
* @brief Associates a user-provided string tag with a driver handle for debugging purposes.
|
||||
* @param handleId The ID of the handle to tag.
|
||||
* @param tag The debug string to associate with the handle.
|
||||
*/
|
||||
|
||||
// Resource creation
|
||||
|
||||
/** @fn backend::VertexBufferInfoHandle Driver::createVertexBufferInfo(uint8_t bufferCount, uint8_t attributeCount, backend::AttributeArray attributes)
|
||||
* @brief Creates a VertexBufferInfo object which describes the layout of a vertex buffer.
|
||||
* @param bufferCount The number of buffer objects in the vertex buffer.
|
||||
* @param attributeCount The number of attributes in the vertex buffer.
|
||||
* @param attributes An array describing each vertex attribute.
|
||||
* @return A handle to the new VertexBufferInfo object.
|
||||
*/
|
||||
|
||||
/** @fn backend::VertexBufferHandle Driver::createVertexBuffer(uint32_t vertexCount, backend::VertexBufferInfoHandle vbih)
|
||||
* @brief Creates a vertex buffer with a specified vertex count and layout.
|
||||
* @param vertexCount The number of vertices in the buffer.
|
||||
* @param vbih A handle to a VertexBufferInfo object describing the vertex layout.
|
||||
* @return A handle to the new vertex buffer.
|
||||
*/
|
||||
|
||||
/** @fn backend::IndexBufferHandle Driver::createIndexBuffer(backend::ElementType elementType, uint32_t indexCount, backend::BufferUsage usage)
|
||||
* @brief Creates an index buffer for indexed drawing.
|
||||
* @param elementType The data type of an index (e.g., USHORT, UINT).
|
||||
* @param indexCount The number of indices in the buffer.
|
||||
* @param usage The expected usage pattern of the buffer (e.g., STATIC, DYNAMIC).
|
||||
* @return A handle to the new index buffer.
|
||||
*/
|
||||
|
||||
/** @fn backend::BufferObjectHandle Driver::createBufferObject(uint32_t byteCount, backend::BufferObjectBinding bindingType, backend::BufferUsage usage)
|
||||
* @brief Creates a generic buffer object for storing arbitrary data on the GPU.
|
||||
* @param byteCount The size of the buffer in bytes.
|
||||
* @param bindingType The purpose of the buffer object (e.g., VERTEX, UNIFORM).
|
||||
* @param usage The expected usage pattern of the buffer.
|
||||
* @return A handle to the new buffer object.
|
||||
*/
|
||||
|
||||
/** @fn backend::TextureHandle Driver::createTexture(backend::SamplerType target, uint8_t levels, backend::TextureFormat format, uint8_t samples, uint32_t width, uint32_t height, uint32_t depth, backend::TextureUsage usage)
|
||||
* @brief Creates a new texture object.
|
||||
* @param target The type of the texture (e.g. 2D, 3D, CUBEMAP).
|
||||
* @param levels The number of mipmap levels.
|
||||
* @param format The internal format of the texture's pixels.
|
||||
* @param samples The number of samples for multisampling (1 for non-MSAA).
|
||||
* @param width The width of the texture in texels.
|
||||
* @param height The height of the texture in texels.
|
||||
* @param depth The depth of the texture in texels (for 3D or array textures).
|
||||
* @param usage A bitmask specifying the intended usage of the texture.
|
||||
* @return A handle to the new texture.
|
||||
*/
|
||||
|
||||
/** @fn backend::TextureHandle Driver::createTextureView(backend::TextureHandle texture, uint8_t baseLevel, uint8_t levelCount)
|
||||
* @brief Creates a new texture view from an existing texture, allowing access to a subset of its mipmap levels.
|
||||
* @param texture The handle of the original texture.
|
||||
* @param baseLevel The first mipmap level to include in the view.
|
||||
* @param levelCount The number of mipmap levels to include in the view.
|
||||
* @return A handle to the new texture view.
|
||||
*/
|
||||
|
||||
/** @fn backend::TextureHandle Driver::createTextureViewSwizzle(backend::TextureHandle texture, backend::TextureSwizzle r, backend::TextureSwizzle g, backend::TextureSwizzle b, backend::TextureSwizzle a)
|
||||
* @brief Creates a new texture view with remapped color channels (swizzling).
|
||||
* @param texture The handle of the original texture.
|
||||
* @param r The swizzle operation for the red channel.
|
||||
* @param g The swizzle operation for the green channel.
|
||||
* @param b The swizzle operation for the blue channel.
|
||||
* @param a The swizzle operation for the alpha channel.
|
||||
* @return A handle to the new texture view.
|
||||
*/
|
||||
|
||||
/** @fn backend::TextureHandle Driver::createTextureExternalImage2(backend::SamplerType target, backend::TextureFormat format, uint32_t width, uint32_t height, backend::TextureUsage usage, backend::Platform::ExternalImageHandleRef image)
|
||||
* @brief Creates a texture from a platform-specific external image handle.
|
||||
* @param target The type of the texture.
|
||||
* @param format The format of the texture's pixels.
|
||||
* @param width The width of the texture.
|
||||
* @param height The height of the texture.
|
||||
* @param usage The expected usage of the texture.
|
||||
* @param image A reference to the platform-specific external image.
|
||||
* @return A handle to the new texture.
|
||||
*/
|
||||
|
||||
/** @fn backend::TextureHandle Driver::createTextureExternalImage(backend::SamplerType target, backend::TextureFormat format, uint32_t width, uint32_t height, backend::TextureUsage usage, void* image)
|
||||
* @brief Creates a texture from a platform-specific external image pointer.
|
||||
* @param target The type of the texture.
|
||||
* @param format The format of the texture's pixels.
|
||||
* @param width The width of the texture.
|
||||
* @param height The height of the texture.
|
||||
* @param usage The expected usage of the texture.
|
||||
* @param image A pointer to the external image data.
|
||||
* @return A handle to the new texture.
|
||||
*/
|
||||
|
||||
/** @fn backend::TextureHandle Driver::createTextureExternalImagePlane(backend::TextureFormat format, uint32_t width, uint32_t height, backend::TextureUsage usage, void* image, uint32_t plane)
|
||||
* @brief Creates a texture from a single plane of a multi-planar external image.
|
||||
* @param format The format of the texture's pixels.
|
||||
* @param width The width of the texture.
|
||||
* @param height The height of the texture.
|
||||
* @param usage The expected usage of the texture.
|
||||
* @param image A pointer to the external image data.
|
||||
* @param plane The index of the plane to create the texture from.
|
||||
* @return A handle to the new texture.
|
||||
*/
|
||||
|
||||
/** @fn backend::TextureHandle Driver::importTexture(intptr_t id, backend::SamplerType target, uint8_t levels, backend::TextureFormat format, uint8_t samples, uint32_t width, uint32_t height, uint32_t depth, backend::TextureUsage usage)
|
||||
* @brief Imports an existing backend-native texture into Filament.
|
||||
* @param id The backend-specific texture ID or handle.
|
||||
* @param target The type of the texture.
|
||||
* @param levels The number of mipmap levels.
|
||||
* @param format The format of the texture's pixels.
|
||||
* @param samples The number of samples for multisampling.
|
||||
* @param width The width of the texture.
|
||||
* @param height The height of the texture.
|
||||
* @param depth The depth of the texture.
|
||||
* @param usage The expected usage of the texture.
|
||||
* @return A handle to the imported texture.
|
||||
*/
|
||||
|
||||
/** @fn backend::RenderPrimitiveHandle Driver::createRenderPrimitive(backend::VertexBufferHandle vbh, backend::IndexBufferHandle ibh, backend::PrimitiveType pt)
|
||||
* @brief Creates a render primitive, which represents a piece of geometry to be rendered.
|
||||
* @param vbh A handle to a vertex buffer.
|
||||
* @param ibh A handle to an index buffer.
|
||||
* @param pt The type of primitive to render (e.g., TRIANGLES, LINES).
|
||||
* @return A handle to the new render primitive.
|
||||
*/
|
||||
|
||||
/** @fn backend::ProgramHandle Driver::createProgram(backend::Program&& program)
|
||||
* @brief Creates a shader program from a backend-specific program object.
|
||||
* @param program A Program object containing the shader code and metadata.
|
||||
* @return A handle to the new program.
|
||||
*/
|
||||
|
||||
/** @fn backend::RenderTargetHandle Driver::createDefaultRenderTarget()
|
||||
* @brief Creates a render target that represents the default framebuffer (e.g., the screen).
|
||||
* @return A handle to the default render target.
|
||||
*/
|
||||
|
||||
/** @fn backend::RenderTargetHandle Driver::createRenderTarget(backend::TargetBufferFlags targetBufferFlags, uint32_t width, uint32_t height, uint8_t samples, uint8_t layerCount, backend::MRT color, backend::TargetBufferInfo depth, backend::TargetBufferInfo stencil)
|
||||
* @brief Creates an offscreen render target.
|
||||
* @param targetBufferFlags A bitmask specifying which buffers (color, depth, stencil) are included.
|
||||
* @param width The width of the render target in pixels.
|
||||
* @param height The height of the render target in pixels.
|
||||
* @param samples The number of samples for multisampling.
|
||||
* @param layerCount The number of layers for layered rendering.
|
||||
* @param color An array of color attachments.
|
||||
* @param depth The depth attachment.
|
||||
* @param stencil The stencil attachment.
|
||||
* @return A handle to the new render target.
|
||||
*/
|
||||
|
||||
/** @fn backend::FenceHandle Driver::createFence()
|
||||
* @brief Creates a fence for synchronization between the CPU and GPU.
|
||||
* @return A handle to the new fence.
|
||||
*/
|
||||
|
||||
/** @fn backend::SwapChainHandle Driver::createSwapChain(void* nativeWindow, uint64_t flags)
|
||||
* @brief Creates a swap chain for a native window, used for presenting rendered frames.
|
||||
* @param nativeWindow A platform-specific pointer to the native window.
|
||||
* @param flags Configuration flags for the swap chain.
|
||||
* @return A handle to the new swap chain.
|
||||
*/
|
||||
|
||||
/** @fn backend::SwapChainHandle Driver::createSwapChainHeadless(uint32_t width, uint32_t height, uint64_t flags)
|
||||
* @brief Creates a headless swap chain for offscreen rendering without a native window.
|
||||
* @param width The width of the swap chain.
|
||||
* @param height The height of the swap chain.
|
||||
* @param flags Configuration flags for the swap chain.
|
||||
* @return A handle to the new swap chain.
|
||||
*/
|
||||
|
||||
/** @fn backend::TimerQueryHandle Driver::createTimerQuery()
|
||||
* @brief Creates a timer query object for measuring GPU execution time.
|
||||
* @return A handle to the new timer query.
|
||||
*/
|
||||
|
||||
/** @fn backend::DescriptorSetLayoutHandle Driver::createDescriptorSetLayout(backend::DescriptorSetLayout&& info)
|
||||
* @brief Creates a descriptor set layout, which defines the layout of bindings in a descriptor set.
|
||||
* @param info The layout information for the descriptor set.
|
||||
* @return A handle to the new descriptor set layout.
|
||||
*/
|
||||
|
||||
/** @fn backend::DescriptorSetHandle Driver::createDescriptorSet(backend::DescriptorSetLayoutHandle dslh)
|
||||
* @brief Creates a descriptor set based on a given layout.
|
||||
* @param dslh A handle to the descriptor set layout.
|
||||
* @return A handle to the new descriptor set.
|
||||
*/
|
||||
|
||||
/** @fn Driver::updateDescriptorSetBuffer(backend::DescriptorSetHandle dsh, backend::descriptor_binding_t binding, backend::BufferObjectHandle boh, uint32_t offset, uint32_t size)
|
||||
* @brief Updates a buffer descriptor within a descriptor set.
|
||||
* @param dsh The descriptor set to update.
|
||||
* @param binding The binding point of the descriptor.
|
||||
* @param boh The handle of the buffer object to bind.
|
||||
* @param offset The offset into the buffer.
|
||||
* @param size The size of the buffer region to bind.
|
||||
*/
|
||||
|
||||
/** @fn Driver::updateDescriptorSetTexture(backend::DescriptorSetHandle dsh, backend::descriptor_binding_t binding, backend::TextureHandle th, SamplerParams params)
|
||||
* @brief Updates a texture descriptor within a descriptor set.
|
||||
* @param dsh The descriptor set to update.
|
||||
* @param binding The binding point of the descriptor.
|
||||
* @param th The handle of the texture to bind.
|
||||
* @param params The sampler parameters for the texture.
|
||||
*/
|
||||
|
||||
/** @fn Driver::bindDescriptorSet(backend::DescriptorSetHandle dsh, backend::descriptor_set_t set, backend::DescriptorSetOffsetArray&& offsets)
|
||||
* @brief Binds a descriptor set to the current pipeline.
|
||||
* @param dsh The descriptor set to bind.
|
||||
* @param set The index of the descriptor set to bind.
|
||||
* @param offsets An array of dynamic offsets for the descriptor set.
|
||||
*/
|
||||
|
||||
// Resource destruction
|
||||
|
||||
/** @fn Driver::destroyVertexBuffer(backend::VertexBufferHandle vbh)
|
||||
* @brief Destroys a vertex buffer and releases its resources.
|
||||
* @param vbh The handle of the vertex buffer to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyVertexBufferInfo(backend::VertexBufferInfoHandle vbih)
|
||||
* @brief Destroys a VertexBufferInfo object.
|
||||
* @param vbih The handle of the VertexBufferInfo object to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyIndexBuffer(backend::IndexBufferHandle ibh)
|
||||
* @brief Destroys an index buffer and releases its resources.
|
||||
* @param ibh The handle of the index buffer to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyBufferObject(backend::BufferObjectHandle boh)
|
||||
* @brief Destroys a buffer object and releases its resources.
|
||||
* @param boh The handle of the buffer object to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyRenderPrimitive(backend::RenderPrimitiveHandle rph)
|
||||
* @brief Destroys a render primitive.
|
||||
* @param rph The handle of the render primitive to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyProgram(backend::ProgramHandle ph)
|
||||
* @brief Destroys a shader program.
|
||||
* @param ph The handle of the program to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyTexture(backend::TextureHandle th)
|
||||
* @brief Destroys a texture and releases its resources.
|
||||
* @param th The handle of the texture to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyRenderTarget(backend::RenderTargetHandle rth)
|
||||
* @brief Destroys a render target.
|
||||
* @param rth The handle of the render target to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroySwapChain(backend::SwapChainHandle sch)
|
||||
* @brief Destroys a swap chain.
|
||||
* @param sch The handle of the swap chain to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyStream(backend::StreamHandle sh)
|
||||
* @brief Destroys a stream.
|
||||
* @param sh The handle of the stream to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyTimerQuery(backend::TimerQueryHandle tqh)
|
||||
* @brief Destroys a timer query object.
|
||||
* @param tqh The handle of the timer query to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyFence(backend::FenceHandle fh)
|
||||
* @brief Destroys a fence.
|
||||
* @param fh The handle of the fence to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyDescriptorSetLayout(backend::DescriptorSetLayoutHandle dslh)
|
||||
* @brief Destroys a descriptor set layout.
|
||||
* @param dslh The handle of the descriptor set layout to destroy.
|
||||
*/
|
||||
|
||||
/** @fn Driver::destroyDescriptorSet(backend::DescriptorSetHandle dsh)
|
||||
* @brief Destroys a descriptor set.
|
||||
* @param dsh The handle of the descriptor set to destroy.
|
||||
*/
|
||||
|
||||
// Synchronous APIs
|
||||
|
||||
/** @fn void Driver::terminate()
|
||||
* @brief Terminates the driver and releases all associated resources. This is a synchronous operation.
|
||||
*/
|
||||
|
||||
/** @fn backend::StreamHandle Driver::createStreamNative(void* stream)
|
||||
* @brief Creates a stream from a native stream object (e.g., a SurfaceTexture on Android).
|
||||
* @param stream A pointer to the native stream object.
|
||||
* @return A handle to the new stream.
|
||||
*/
|
||||
|
||||
/** @fn backend::StreamHandle Driver::createStreamAcquired()
|
||||
* @brief Creates a stream that will be populated with images acquired via `setAcquiredImage`.
|
||||
* @return A handle to the new stream.
|
||||
*/
|
||||
|
||||
/** @fn void Driver::setAcquiredImage(backend::StreamHandle stream, void* image, const math::mat3f& transform, backend::CallbackHandler* handler, backend::StreamCallback cb, void* userData)
|
||||
* @brief Provides an image to an acquired stream, with a callback for when the image is no longer in use.
|
||||
* @param stream The handle of the stream.
|
||||
* @param image A pointer to the image data.
|
||||
* @param transform The transformation matrix for the image.
|
||||
* @param handler The callback handler.
|
||||
* @param cb The callback function to be invoked when the image is released.
|
||||
* @param userData User data for the callback.
|
||||
*/
|
||||
|
||||
/** @fn void Driver::setStreamDimensions(backend::StreamHandle stream, uint32_t width, uint32_t height)
|
||||
* @brief Sets the dimensions of a stream, which may be necessary for certain stream types.
|
||||
* @param stream The handle of the stream.
|
||||
* @param width The new width of the stream.
|
||||
* @param height The new height of the stream.
|
||||
*/
|
||||
|
||||
/** @fn int64_t Driver::getStreamTimestamp(backend::StreamHandle stream)
|
||||
* @brief Gets the timestamp of the last frame from a stream, if available.
|
||||
* @param stream The handle of the stream.
|
||||
* @return The timestamp in nanoseconds, or 0 if not available.
|
||||
*/
|
||||
|
||||
/** @fn void Driver::updateStreams(backend::DriverApi* driver)
|
||||
* @brief Updates all active streams, typically called once per frame.
|
||||
* @param driver The driver API pointer.
|
||||
*/
|
||||
|
||||
/** @fn backend::FenceStatus Driver::getFenceStatus(backend::FenceHandle fh)
|
||||
* @brief Gets the current status of a fence.
|
||||
* @param fh The handle of the fence.
|
||||
* @return The status of the fence (e.g., SIGNALED, TIMEOUT_EXPIRED).
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isTextureFormatSupported(backend::TextureFormat format)
|
||||
* @brief Checks if a specific texture format is supported by the driver.
|
||||
* @param format The texture format to check.
|
||||
* @return True if the format is supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isTextureSwizzleSupported()
|
||||
* @brief Checks if texture channel swizzling is supported by the driver.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isTextureFormatMipmappable(backend::TextureFormat format)
|
||||
* @brief Checks if a texture format can have mipmaps automatically generated.
|
||||
* @param format The texture format to check.
|
||||
* @return True if the format is mipmappable, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isRenderTargetFormatSupported(backend::TextureFormat format)
|
||||
* @brief Checks if a texture format is supported for use as a render target attachment.
|
||||
* @param format The texture format to check.
|
||||
* @return True if the format is supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isFrameBufferFetchSupported()
|
||||
* @brief Checks if framebuffer fetch (reading from the framebuffer in a shader) is supported.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isFrameBufferFetchMultiSampleSupported()
|
||||
* @brief Checks if multisampled framebuffer fetch is supported.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isFrameTimeSupported()
|
||||
* @brief Checks if frame time queries are supported for performance measurement.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isAutoDepthResolveSupported()
|
||||
* @brief Checks if automatic resolution of multisampled depth buffers is supported.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isSRGBSwapChainSupported()
|
||||
* @brief Checks if sRGB swap chains are supported for correct color space handling.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isProtectedContentSupported()
|
||||
* @brief Checks if rendering protected content (e.g., for DRM) is supported.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isStereoSupported()
|
||||
* @brief Checks if stereoscopic rendering is supported.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isParallelShaderCompileSupported()
|
||||
* @brief Checks if the driver can compile shaders in parallel for improved performance.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isDepthStencilResolveSupported()
|
||||
* @brief Checks if resolving multisampled depth/stencil buffers is supported.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isDepthStencilBlitSupported(backend::TextureFormat format)
|
||||
* @brief Checks if blitting (copying) depth/stencil data is supported for a given format.
|
||||
* @param format The texture format.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isProtectedTexturesSupported()
|
||||
* @brief Checks if creating protected textures is supported.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isDepthClampSupported()
|
||||
* @brief Checks if depth clamping is supported by the hardware.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn uint8_t Driver::getMaxDrawBuffers()
|
||||
* @brief Gets the maximum number of simultaneous draw buffers (Multiple Render Targets).
|
||||
* @return The maximum number of draw buffers.
|
||||
*/
|
||||
|
||||
/** @fn size_t Driver::getMaxUniformBufferSize()
|
||||
* @brief Gets the maximum size of a uniform buffer in bytes.
|
||||
* @return The maximum size in bytes.
|
||||
*/
|
||||
|
||||
/** @fn size_t Driver::getMaxTextureSize(backend::SamplerType target)
|
||||
* @brief Gets the maximum texture dimension (width, height, or depth) for a given target type.
|
||||
* @param target The texture target type.
|
||||
* @return The maximum size in texels.
|
||||
*/
|
||||
|
||||
/** @fn size_t Driver::getMaxArrayTextureLayers()
|
||||
* @brief Gets the maximum number of layers in an array texture.
|
||||
* @return The maximum number of layers.
|
||||
*/
|
||||
|
||||
/** @fn math::float2 Driver::getClipSpaceParams()
|
||||
* @brief Gets the clip space parameters for the current backend.
|
||||
* @return A float2 containing clip space parameters.
|
||||
*/
|
||||
|
||||
/** @fn void Driver::setupExternalImage2(backend::Platform::ExternalImageHandleRef image)
|
||||
* @brief Performs any necessary setup for an external image before it can be used.
|
||||
* @param image A reference to the external image.
|
||||
*/
|
||||
|
||||
/** @fn void Driver::setupExternalImage(void* image)
|
||||
* @brief Performs any necessary setup for an external image before it can be used.
|
||||
* @param image A pointer to the external image.
|
||||
*/
|
||||
|
||||
/** @fn backend::TimerQueryResult Driver::getTimerQueryValue(backend::TimerQueryHandle query, uint64_t* elapsedTime)
|
||||
* @brief Gets the result of a timer query, providing the elapsed GPU time.
|
||||
* @param query The timer query handle.
|
||||
* @param elapsedTime A pointer to store the elapsed time in nanoseconds.
|
||||
* @return The result of the query (e.g., AVAILABLE, NOT_READY).
|
||||
*/
|
||||
|
||||
/** @fn bool Driver::isWorkaroundNeeded(backend::Workaround workaround)
|
||||
* @brief Checks if a specific driver or hardware workaround is needed.
|
||||
* @param workaround The workaround to check.
|
||||
* @return True if the workaround is needed, false otherwise.
|
||||
*/
|
||||
|
||||
/** @fn backend::FeatureLevel Driver::getFeatureLevel()
|
||||
* @brief Gets the feature level supported by the driver.
|
||||
* @return The driver's feature level.
|
||||
*/
|
||||
|
||||
// Resource updates
|
||||
|
||||
/** @fn Driver::setVertexBufferObject(backend::VertexBufferHandle vbh, uint32_t index, backend::BufferObjectHandle bufferObject)
|
||||
* @brief Associates a buffer object with a specific buffer slot in a vertex buffer.
|
||||
* @param vbh The handle of the vertex buffer.
|
||||
* @param index The index of the buffer slot to set.
|
||||
* @param bufferObject The handle of the buffer object to associate.
|
||||
*/
|
||||
|
||||
/** @fn Driver::updateIndexBuffer(backend::IndexBufferHandle ibh, backend::BufferDescriptor&& data, uint32_t byteOffset)
|
||||
* @brief Updates the data of an index buffer.
|
||||
* @param ibh The handle of the index buffer.
|
||||
* @param data The new data to upload.
|
||||
* @param byteOffset The offset in bytes into the buffer to start writing to.
|
||||
*/
|
||||
|
||||
/** @fn Driver::updateBufferObject(backend::BufferObjectHandle boh, backend::BufferDescriptor&& data, uint32_t byteOffset)
|
||||
* @brief Updates the data of a buffer object.
|
||||
* @param boh The handle of the buffer object.
|
||||
* @param data The new data to upload.
|
||||
* @param byteOffset The offset in bytes into the buffer to start writing to.
|
||||
*/
|
||||
|
||||
/** @fn Driver::registerBufferObjectStreams(backend::BufferObjectHandle boh, backend::BufferObjectStreamDescriptor&& streams)
|
||||
* @brief Registers external streams with a buffer object for efficient data transfer.
|
||||
* @param boh The handle of the buffer object.
|
||||
* @param streams The stream descriptors.
|
||||
*/
|
||||
|
||||
/** @fn Driver::updateBufferObjectUnsynchronized(backend::BufferObjectHandle boh, backend::BufferDescriptor&& data, uint32_t byteOffset)
|
||||
* @brief Updates a buffer object without synchronization, for use when manual synchronization is handled.
|
||||
* @param boh The handle of the buffer object.
|
||||
* @param data The new data to upload.
|
||||
* @param byteOffset The offset in bytes into the buffer to start writing to.
|
||||
*/
|
||||
|
||||
/** @fn Driver::resetBufferObject(backend::BufferObjectHandle boh)
|
||||
* @brief Resets a buffer object, potentially discarding its contents.
|
||||
* @param boh The handle of the buffer object.
|
||||
*/
|
||||
|
||||
/** @fn Driver::update3DImage(backend::TextureHandle th, uint32_t level, uint32_t xoffset, uint32_t yoffset, uint32_t zoffset, uint32_t width, uint32_t height, uint32_t depth, backend::PixelBufferDescriptor&& data)
|
||||
* @brief Updates a sub-region of a 3D texture.
|
||||
* @param th The handle of the texture.
|
||||
* @param level The mipmap level to update.
|
||||
* @param xoffset The x offset of the sub-region.
|
||||
* @param yoffset The y offset of the sub-region.
|
||||
* @param zoffset The z offset of the sub-region.
|
||||
* @param width The width of the sub-region.
|
||||
* @param height The height of the sub-region.
|
||||
* @param depth The depth of the sub-region.
|
||||
* @param data The pixel data to upload.
|
||||
*/
|
||||
|
||||
/** @fn Driver::generateMipmaps(backend::TextureHandle th)
|
||||
* @brief Generates mipmaps for a texture automatically.
|
||||
* @param th The handle of the texture.
|
||||
*/
|
||||
|
||||
/** @fn Driver::setExternalStream(backend::TextureHandle th, backend::StreamHandle sh)
|
||||
* @brief Associates an external stream with a texture for video or camera input.
|
||||
* @param th The handle of the texture.
|
||||
* @param sh The handle of the stream.
|
||||
*/
|
||||
|
||||
// Render passes
|
||||
|
||||
/** @fn Driver::beginRenderPass(backend::RenderTargetHandle rth, const backend::RenderPassParams& params)
|
||||
* @brief Begins a new render pass, targeting a specific render target.
|
||||
* @param rth The handle of the render target.
|
||||
* @param params The parameters for the render pass (e.g., clear values, load/store actions).
|
||||
*/
|
||||
|
||||
/** @fn Driver::endRenderPass()
|
||||
* @brief Ends the current render pass.
|
||||
*/
|
||||
|
||||
/** @fn Driver::nextSubpass()
|
||||
* @brief Moves to the next subpass within the current render pass.
|
||||
*/
|
||||
|
||||
// Timer queries
|
||||
|
||||
/** @fn Driver::beginTimerQuery(backend::TimerQueryHandle query)
|
||||
* @brief Begins a timer query to measure GPU time.
|
||||
* @param query The handle of the timer query.
|
||||
*/
|
||||
|
||||
/** @fn Driver::endTimerQuery(backend::TimerQueryHandle query)
|
||||
* @brief Ends a timer query.
|
||||
* @param query The handle of the timer query.
|
||||
*/
|
||||
|
||||
/** @fn Driver::compilePrograms(backend::CompilerPriorityQueue priority, backend::CallbackHandler* handler, backend::CallbackHandler::Callback callback, void* user)
|
||||
* @brief Compiles a queue of pending shader programs.
|
||||
* @param priority The priority queue to use for compilation.
|
||||
* @param handler The callback handler.
|
||||
* @param callback The callback function to be invoked upon completion.
|
||||
* @param user User data for the callback.
|
||||
*/
|
||||
|
||||
// Swap chain
|
||||
|
||||
/** @fn Driver::makeCurrent(backend::SwapChainHandle schDraw, backend::SwapChainHandle schRead)
|
||||
* @brief Makes a swap chain current for drawing and reading.
|
||||
* @param schDraw The draw swap chain.
|
||||
* @param schRead The read swap chain.
|
||||
*/
|
||||
|
||||
/** @fn Driver::commit(backend::SwapChainHandle sch)
|
||||
* @brief Commits the back buffer of a swap chain, making it visible.
|
||||
* @param sch The handle of the swap chain.
|
||||
*/
|
||||
|
||||
// Rendering state
|
||||
|
||||
/** @fn Driver::setPushConstant(backend::ShaderStage stage, uint8_t index, backend::PushConstantVariant value)
|
||||
* @brief Sets a push constant value for a specific shader stage.
|
||||
* @param stage The shader stage to set the constant for.
|
||||
* @param index The index of the push constant.
|
||||
* @param value The value to set.
|
||||
*/
|
||||
|
||||
/** @fn Driver::insertEventMarker(const char* string)
|
||||
* @brief Inserts a debug event marker into the command stream.
|
||||
* @param string The marker string.
|
||||
*/
|
||||
|
||||
/** @fn Driver::pushGroupMarker(const char* string)
|
||||
* @brief Pushes a debug group marker onto the command stream stack.
|
||||
* @param string The marker string.
|
||||
*/
|
||||
|
||||
/** @fn Driver::popGroupMarker()
|
||||
* @brief Pops a debug group marker from the command stream stack.
|
||||
*/
|
||||
|
||||
/** @fn Driver::startCapture()
|
||||
* @brief Starts a graphics capture session.
|
||||
*/
|
||||
|
||||
/** @fn Driver::stopCapture()
|
||||
* @brief Stops a graphics capture session.
|
||||
*/
|
||||
|
||||
// Read-back
|
||||
|
||||
/** @fn Driver::readPixels(backend::RenderTargetHandle src, uint32_t x, uint32_t y, uint32_t width, uint32_t height, backend::PixelBufferDescriptor&& data)
|
||||
* @brief Reads a block of pixels from a render target into a client-side buffer.
|
||||
* @param src The source render target.
|
||||
* @param x The x coordinate of the region to read.
|
||||
* @param y The y coordinate of the region to read.
|
||||
* @param width The width of the region to read.
|
||||
* @param height The height of the region to read.
|
||||
* @param data The buffer to store the pixel data.
|
||||
*/
|
||||
|
||||
/** @fn Driver::readBufferSubData(backend::BufferObjectHandle src, uint32_t offset, uint32_t size, backend::BufferDescriptor&& data)
|
||||
* @brief Reads a sub-region of a buffer object into a client-side buffer.
|
||||
* @param src The source buffer object.
|
||||
* @param offset The offset to start reading from.
|
||||
* @param size The number of bytes to read.
|
||||
* @param data The buffer to store the data.
|
||||
*/
|
||||
|
||||
// Rendering
|
||||
|
||||
/** @fn Driver::blitDEPRECATED(backend::TargetBufferFlags buffers, backend::RenderTargetHandle dst, backend::Viewport dstRect, backend::RenderTargetHandle src, backend::Viewport srcRect, backend::SamplerMagFilter filter)
|
||||
* @brief Blits (copies) a region from one render target to another (deprecated).
|
||||
* @param buffers The buffers to blit (e.g., color, depth).
|
||||
* @param dst The destination render target.
|
||||
* @param dstRect The destination rectangle.
|
||||
* @param src The source render target.
|
||||
* @param srcRect The source rectangle.
|
||||
* @param filter The filter to use for scaling.
|
||||
*/
|
||||
|
||||
/** @fn Driver::resolve(backend::TextureHandle dst, uint8_t dstLevel, uint8_t dstLayer, backend::TextureHandle src, uint8_t srcLevel, uint8_t srcLayer)
|
||||
* @brief Resolves a multisampled texture into a non-multisampled texture.
|
||||
* @param dst The destination texture.
|
||||
* @param dstLevel The destination mipmap level.
|
||||
* @param dstLayer The destination layer.
|
||||
* @param src The source multisampled texture.
|
||||
* @param srcLevel The source mipmap level.
|
||||
* @param srcLayer The source layer.
|
||||
*/
|
||||
|
||||
/** @fn Driver::blit(backend::TextureHandle dst, uint8_t dstLevel, uint8_t dstLayer, math::uint2 dstOrigin, backend::TextureHandle src, uint8_t srcLevel, uint8_t srcLayer, math::uint2 srcOrigin, math::uint2 size)
|
||||
* @brief Blits (copies) a region from one texture to another.
|
||||
* @param dst The destination texture.
|
||||
* @param dstLevel The destination mipmap level.
|
||||
* @param dstLayer The destination layer.
|
||||
* @param dstOrigin The origin of the destination region.
|
||||
* @param src The source texture.
|
||||
* @param srcLevel The source mipmap level.
|
||||
* @param srcLayer The source layer.
|
||||
* @param srcOrigin The origin of the source region.
|
||||
* @param size The size of the region to blit.
|
||||
*/
|
||||
|
||||
/** @fn Driver::bindPipeline(const backend::PipelineState& state)
|
||||
* @brief Binds a pipeline state object, including shaders and render states.
|
||||
* @param state The pipeline state to bind.
|
||||
*/
|
||||
|
||||
/** @fn Driver::bindRenderPrimitive(backend::RenderPrimitiveHandle rph)
|
||||
* @brief Binds a render primitive for subsequent draw calls.
|
||||
* @param rph The handle of the render primitive.
|
||||
*/
|
||||
|
||||
/** @fn Driver::draw2(uint32_t indexOffset, uint32_t indexCount, uint32_t instanceCount)
|
||||
* @brief Draws a render primitive using the currently bound pipeline and primitive.
|
||||
* @param indexOffset The offset into the index buffer.
|
||||
* @param indexCount The number of indices to draw.
|
||||
* @param instanceCount The number of instances to draw.
|
||||
*/
|
||||
|
||||
/** @fn Driver::draw(backend::PipelineState state, backend::RenderPrimitiveHandle rph, uint32_t indexOffset, uint32_t indexCount, uint32_t instanceCount)
|
||||
* @brief A combined call to bind a pipeline, bind a primitive, and draw.
|
||||
* @param state The pipeline state to bind.
|
||||
* @param rph The render primitive to bind.
|
||||
* @param indexOffset The offset into the index buffer.
|
||||
* @param indexCount The number of indices to draw.
|
||||
* @param instanceCount The number of instances to draw.
|
||||
*/
|
||||
|
||||
/** @fn Driver::dispatchCompute(backend::ProgramHandle program, math::uint3 workGroupCount)
|
||||
* @brief Dispatches a compute shader.
|
||||
* @param program The handle of the compute program.
|
||||
* @param workGroupCount The number of work groups to dispatch in each dimension.
|
||||
*/
|
||||
|
||||
/** @fn Driver::scissor(Viewport scissor)
|
||||
* @brief Sets the scissor rectangle for clipping.
|
||||
* @param scissor The scissor rectangle.
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ static std::string to_string(int const i) { return std::to_string(i); }
|
||||
static std::string to_string(float const f) { return "float(" + std::to_string(f) + ")"; }
|
||||
|
||||
static void logCompilationError(ShaderStage shaderType, const char* name, GLuint shaderId,
|
||||
CString const& sourceCode) noexcept;
|
||||
Program::ShaderBlob const& sourceCode) noexcept;
|
||||
static void logProgramLinkError(char const* name, GLuint program) noexcept;
|
||||
|
||||
static void process_GOOGLE_cpp_style_line_directive(OpenGLContext const& context, char* source,
|
||||
@@ -88,7 +88,7 @@ struct ShaderCompilerService::OpenGLProgramToken : ProgramToken {
|
||||
ShaderCompilerService& compiler;
|
||||
CString const& name;
|
||||
FixedCapacityVector<std::pair<CString, uint8_t>> attributes;
|
||||
shaders_source_t shaderSourceCode;
|
||||
Program::ShaderSource shaderSourceCode;
|
||||
void* user = nullptr;
|
||||
struct {
|
||||
shaders_t shaders{};
|
||||
@@ -612,7 +612,7 @@ void ShaderCompilerService::executeTickOps() noexcept {
|
||||
#ifndef NDEBUG
|
||||
// for debugging we return the original shader source (without the modifications we
|
||||
// made here), otherwise the line numbers wouldn't match.
|
||||
token->shaderSourceCode[i] = { shader_src, shader_len };
|
||||
token->shaderSourceCode[i] = std::move(shader);
|
||||
#endif
|
||||
token->gl.shaders[i] = shaderId;
|
||||
}
|
||||
@@ -758,7 +758,8 @@ void ShaderCompilerService::executeTickOps() noexcept {
|
||||
|
||||
UTILS_NOINLINE
|
||||
/* static */ void logCompilationError(ShaderStage shaderType, const char* name,
|
||||
GLuint const shaderId, UTILS_UNUSED_IN_RELEASE CString const& sourceCode) noexcept {
|
||||
GLuint const shaderId,
|
||||
UTILS_UNUSED_IN_RELEASE Program::ShaderBlob const& sourceCode) noexcept {
|
||||
|
||||
{ // scope for the temporary string storage
|
||||
auto to_string = [](ShaderStage type) -> const char* {
|
||||
@@ -785,7 +786,8 @@ UTILS_NOINLINE
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
std::string_view const shader{ sourceCode.data(), sourceCode.size() };
|
||||
std::string_view const shader{ reinterpret_cast<const char*>(sourceCode.data()),
|
||||
sourceCode.size() };
|
||||
size_t lc = 1;
|
||||
size_t start = 0;
|
||||
std::string line;
|
||||
|
||||
@@ -58,7 +58,6 @@ class ShaderCompilerService {
|
||||
public:
|
||||
using program_token_t = std::shared_ptr<OpenGLProgramToken>;
|
||||
using shaders_t = std::array<GLuint, Program::SHADER_TYPE_COUNT>;
|
||||
using shaders_source_t = std::array<utils::CString, Program::SHADER_TYPE_COUNT>;
|
||||
|
||||
explicit ShaderCompilerService(OpenGLDriver& driver);
|
||||
|
||||
|
||||
@@ -457,8 +457,13 @@ void WebGPUDriver::createRenderTargetR(Handle<HwRenderTarget> renderTargetHandle
|
||||
const TargetBufferFlags targetFlags, const uint32_t width, const uint32_t height,
|
||||
const uint8_t samples, const uint8_t layerCount, const MRT color,
|
||||
const TargetBufferInfo depth, const TargetBufferInfo stencil) {
|
||||
constructHandle<WebGPURenderTarget>(renderTargetHandle, width, height, samples, layerCount,
|
||||
color, depth, stencil, targetFlags);
|
||||
constructHandle<WebGPURenderTarget>(
|
||||
renderTargetHandle, width, height, samples, layerCount, color, depth, stencil,
|
||||
targetFlags,
|
||||
[&](const Handle<HwTexture> textureHandle) {
|
||||
return handleCast<WebGPUTexture>(textureHandle);
|
||||
},
|
||||
mDevice);
|
||||
}
|
||||
|
||||
void WebGPUDriver::createFenceR(Handle<HwFence> fenceHandle, const int /* dummy */) {
|
||||
@@ -819,10 +824,15 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> renderTargetHandle,
|
||||
wgpu::TextureView defaultDepthStencilView = nullptr;
|
||||
wgpu::TextureFormat defaultDepthStencilFormat = wgpu::TextureFormat::Undefined;
|
||||
|
||||
const bool msaaSidecarsRequired{ renderTarget->getSamples() > 1 &&
|
||||
renderTarget->getSampleCountPerAttachment() <= 1 };
|
||||
|
||||
std::array<wgpu::TextureView, MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT> customColorViews{};
|
||||
std::array<wgpu::TextureView, customColorViews.size()> customColorMsaaSidecarViews{};
|
||||
uint32_t customColorViewCount = 0;
|
||||
|
||||
wgpu::TextureView customDepthStencilView = nullptr;
|
||||
wgpu::TextureView customDepthStencilMsaaSidecarTextureView = nullptr;
|
||||
wgpu::TextureFormat customDepthStencilFormat = wgpu::TextureFormat::Undefined;
|
||||
|
||||
mCurrentRenderTarget = renderTarget;
|
||||
@@ -833,21 +843,17 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> renderTargetHandle,
|
||||
defaultDepthStencilFormat = mSwapChain->getDepthFormat();
|
||||
|
||||
if (any(renderTarget->getTargetFlags() & TargetBufferFlags::STENCIL) &&
|
||||
!(defaultDepthStencilFormat == wgpu::TextureFormat::Depth24PlusStencil8 ||
|
||||
defaultDepthStencilFormat == wgpu::TextureFormat::Depth32FloatStencil8 ||
|
||||
defaultDepthStencilFormat == wgpu::TextureFormat::Stencil8)) {
|
||||
FILAMENT_CHECK_POSTCONDITION(false) << "Default render target requested stencil, but swap chain's depth format "
|
||||
<< (uint32_t)defaultDepthStencilFormat << " does not have a stencil aspect.";
|
||||
!(hasStencil(defaultDepthStencilFormat))) {
|
||||
FILAMENT_CHECK_POSTCONDITION(false)
|
||||
<< "Default render target requested stencil, but swap chain's depth format "
|
||||
<< (uint32_t) defaultDepthStencilFormat << " does not have a stencil aspect.";
|
||||
}
|
||||
|
||||
if (any(renderTarget->getTargetFlags() & TargetBufferFlags::DEPTH) &&
|
||||
!(defaultDepthStencilFormat == wgpu::TextureFormat::Depth16Unorm ||
|
||||
defaultDepthStencilFormat == wgpu::TextureFormat::Depth32Float ||
|
||||
defaultDepthStencilFormat == wgpu::TextureFormat::Depth24Plus ||
|
||||
defaultDepthStencilFormat == wgpu::TextureFormat::Depth24PlusStencil8 ||
|
||||
defaultDepthStencilFormat == wgpu::TextureFormat::Depth32FloatStencil8)) {
|
||||
FILAMENT_CHECK_POSTCONDITION(false) << "Default render target requested depth, but swap chain's depth format "
|
||||
<< (uint32_t)defaultDepthStencilFormat << " does not have a depth aspect.";
|
||||
!(hasDepth(defaultDepthStencilFormat))) {
|
||||
FILAMENT_CHECK_POSTCONDITION(false)
|
||||
<< "Default render target requested depth, but swap chain's depth format "
|
||||
<< (uint32_t) defaultDepthStencilFormat << " does not have a depth aspect.";
|
||||
}
|
||||
} else {
|
||||
// Resolve views for custom render target
|
||||
@@ -863,8 +869,19 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> renderTargetHandle,
|
||||
<< ".";
|
||||
const uint8_t mipLevel = colorInfos[i].level;
|
||||
const uint32_t arrayLayer = colorInfos[i].layer;
|
||||
customColorViews[customColorViewCount++] =
|
||||
customColorViews[customColorViewCount] =
|
||||
colorTexture->getOrMakeTextureView(mipLevel, arrayLayer);
|
||||
if (msaaSidecarsRequired) {
|
||||
const wgpu::TextureView msaaSidecarView{
|
||||
colorTexture->makeMsaaSidecarTextureViewIfTextureSidecarExists(
|
||||
renderTarget->getSamples(), mipLevel, arrayLayer)
|
||||
};
|
||||
FILAMENT_CHECK_POSTCONDITION(msaaSidecarView)
|
||||
<< "Could not get a required MSAA sidecar texture view for color "
|
||||
<< customColorViewCount << "?";
|
||||
customColorMsaaSidecarViews[customColorViewCount] = msaaSidecarView;
|
||||
}
|
||||
customColorViewCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -896,15 +913,21 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> renderTargetHandle,
|
||||
if (depthStencilSourceHandle) {
|
||||
auto dsTexture = handleCast<WebGPUTexture>(depthStencilSourceHandle);
|
||||
if (dsTexture) {
|
||||
customDepthStencilView = dsTexture->getOrMakeTextureView(depthStencilMipLevel, depthStencilArrayLayer);
|
||||
customDepthStencilView = dsTexture->getOrMakeTextureView(depthStencilMipLevel,
|
||||
depthStencilArrayLayer);
|
||||
if (msaaSidecarsRequired) {
|
||||
customDepthStencilMsaaSidecarTextureView =
|
||||
dsTexture->makeMsaaSidecarTextureViewIfTextureSidecarExists(
|
||||
renderTarget->getSamples(), depthStencilMipLevel,
|
||||
depthStencilArrayLayer);
|
||||
FILAMENT_CHECK_POSTCONDITION(customDepthStencilMsaaSidecarTextureView)
|
||||
<< "Could not get a required MSAA sidecar texture view for "
|
||||
"depth/stencil?";
|
||||
}
|
||||
customDepthStencilFormat = dsTexture->getViewFormat();
|
||||
|
||||
if (any(renderTarget->getTargetFlags() & TargetBufferFlags::STENCIL) &&
|
||||
!(customDepthStencilFormat == wgpu::TextureFormat::Depth24PlusStencil8 ||
|
||||
customDepthStencilFormat ==
|
||||
wgpu::TextureFormat::Depth32FloatStencil8 ||
|
||||
customDepthStencilFormat ==
|
||||
wgpu::TextureFormat::Stencil8)) {
|
||||
!(hasStencil(customDepthStencilFormat))) {
|
||||
FILAMENT_CHECK_POSTCONDITION(false)
|
||||
<< "Custom render target requested stencil, but the provided texture"
|
||||
"format number"
|
||||
@@ -912,14 +935,7 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> renderTargetHandle,
|
||||
<< " does not have a stencil aspect.";
|
||||
}
|
||||
if (any(renderTarget->getTargetFlags() & TargetBufferFlags::DEPTH) &&
|
||||
!(customDepthStencilFormat == wgpu::TextureFormat::Depth16Unorm ||
|
||||
customDepthStencilFormat == wgpu::TextureFormat::Depth32Float ||
|
||||
customDepthStencilFormat ==
|
||||
wgpu::TextureFormat::Depth24Plus ||
|
||||
customDepthStencilFormat ==
|
||||
wgpu::TextureFormat::Depth24PlusStencil8 ||
|
||||
customDepthStencilFormat ==
|
||||
wgpu::TextureFormat::Depth32FloatStencil8)) {
|
||||
!(hasDepth(customDepthStencilFormat))) {
|
||||
FILAMENT_CHECK_POSTCONDITION(false) << "Custom render target requested depth, "
|
||||
"but the provided texture format number"
|
||||
<< (uint32_t) customDepthStencilFormat
|
||||
@@ -934,8 +950,10 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> renderTargetHandle,
|
||||
defaultColorView,
|
||||
defaultDepthStencilView,
|
||||
customColorViews.data(),
|
||||
customColorMsaaSidecarViews.data(),
|
||||
customColorViewCount,
|
||||
customDepthStencilView);
|
||||
customDepthStencilView,
|
||||
customDepthStencilMsaaSidecarTextureView);
|
||||
|
||||
mRenderPassEncoder = mCommandEncoder.BeginRenderPass(&renderPassDescriptor);
|
||||
|
||||
@@ -976,13 +994,13 @@ void WebGPUDriver::makeCurrent(Handle<HwSwapChain> drawSch, Handle<HwSwapChain>
|
||||
wgpu::TextureFormat depthFormat = mSwapChain->getDepthFormat();
|
||||
TargetBufferFlags newTargetFlags = filament::backend::TargetBufferFlags::NONE;
|
||||
|
||||
//Assuming Color and Depth are always present.
|
||||
//Assuming Color always present in default render target.
|
||||
newTargetFlags |= filament::backend::TargetBufferFlags::COLOR;
|
||||
if (depthFormat != wgpu::TextureFormat::Undefined) {
|
||||
newTargetFlags |= filament::backend::TargetBufferFlags::DEPTH;
|
||||
|
||||
if (depthFormat == wgpu::TextureFormat::Depth24PlusStencil8 ||
|
||||
depthFormat == wgpu::TextureFormat::Depth32FloatStencil8) {
|
||||
if (hasDepth(depthFormat)) {
|
||||
newTargetFlags |= filament::backend::TargetBufferFlags::DEPTH;
|
||||
}
|
||||
if (hasStencil(depthFormat)) {
|
||||
newTargetFlags |= filament::backend::TargetBufferFlags::STENCIL;
|
||||
}
|
||||
}
|
||||
@@ -1069,102 +1087,33 @@ void WebGPUDriver::blitDEPRECATED(TargetBufferFlags buffers,
|
||||
void WebGPUDriver::resolve(Handle<HwTexture> destinationTextureHandle, const uint8_t sourceLevel,
|
||||
const uint8_t sourceLayer, Handle<HwTexture> sourceTextureHandle,
|
||||
const uint8_t destinationLevel, const uint8_t destinationLayer) {
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(mCommandEncoder)
|
||||
<< "Resolve assumes there is a valid command encoder to piggyback on.";
|
||||
FILAMENT_CHECK_PRECONDITION(mRenderPassEncoder == nullptr)
|
||||
<< "Resolve cannot be called during an existing render pass";
|
||||
|
||||
const auto sourceTexture{ handleCast<WebGPUTexture>(sourceTextureHandle) };
|
||||
const auto destinationTexture{ handleCast<WebGPUTexture>(destinationTextureHandle) };
|
||||
|
||||
assert_invariant(sourceTexture);
|
||||
assert_invariant(destinationTexture);
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(destinationTexture->width == sourceTexture->width &&
|
||||
destinationTexture->height == sourceTexture->height)
|
||||
<< "invalid resolve: source and destination sizes don't match";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(sourceTexture->samples > 1 && destinationTexture->samples == 1)
|
||||
<< "invalid resolve: source.samples=" << +sourceTexture->samples
|
||||
<< ", destination.samples=" << +destinationTexture->samples;
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(sourceTexture->format == destinationTexture->format)
|
||||
<< "source and destination texture format don't match";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(!isDepthFormat(sourceTexture->format))
|
||||
<< "can't resolve depth formats";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(!isStencilFormat(sourceTexture->format))
|
||||
<< "can't resolve stencil formats";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(any(destinationTexture->usage & TextureUsage::BLIT_DST))
|
||||
<< "destination texture doesn't have BLIT_DST";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(any(sourceTexture->usage & TextureUsage::BLIT_SRC))
|
||||
<< "source texture doesn't have BLIT_SRC";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(sourceTexture->getTexture().GetUsage() & wgpu::TextureUsage::RenderAttachment)
|
||||
<< "source texture usage doesn't have wgpu::TextureUsage::RenderAttachment";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(destinationTexture->getTexture().GetUsage() & wgpu::TextureUsage::RenderAttachment)
|
||||
<< "destination texture usage doesn't have wgpu::TextureUsage::RenderAttachment";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(destinationTexture->getTexture().GetUsage() & wgpu::TextureUsage::TextureBinding)
|
||||
<< "destination texture usage doesn't have wgpu::TextureUsage::TextureBinding";
|
||||
|
||||
const wgpu::TextureFormat format{ sourceTexture->getViewFormat() };
|
||||
const wgpu::TextureViewDescriptor sourceTextureViewDescriptor{
|
||||
.label = "resolve_source_texture_view",
|
||||
.format = format,
|
||||
.dimension = sourceTexture->getViewDimension(),
|
||||
.baseMipLevel = sourceLevel,
|
||||
.mipLevelCount = 1,
|
||||
.baseArrayLayer = sourceLayer,
|
||||
.arrayLayerCount = 1,
|
||||
.aspect = sourceTexture->getAspect(),
|
||||
.usage = sourceTexture->getTexture().GetUsage(),
|
||||
const WebGPUMsaaTextureResolver::ResolveRequest request{
|
||||
.commandEncoder = mCommandEncoder,
|
||||
.viewFormat = sourceTexture->getViewFormat(),
|
||||
.source = {
|
||||
.texture = sourceTexture->getTexture(),
|
||||
.viewDimension = sourceTexture->getViewDimension(),
|
||||
.mipLevel = sourceLevel,
|
||||
.layer = sourceLayer,
|
||||
.aspect = sourceTexture->getAspect(),
|
||||
},
|
||||
.destination = {
|
||||
.texture = destinationTexture->getTexture(),
|
||||
.viewDimension = destinationTexture->getViewDimension(),
|
||||
.mipLevel = destinationLevel,
|
||||
.layer = destinationLayer,
|
||||
.aspect = destinationTexture->getAspect(),
|
||||
},
|
||||
};
|
||||
const wgpu::TextureView sourceTextureView{ sourceTexture->getTexture().CreateView(
|
||||
&sourceTextureViewDescriptor) };
|
||||
FILAMENT_CHECK_POSTCONDITION(sourceTextureView) << "Failed to create wgpu::TextureView sourceTextureView";
|
||||
const wgpu::TextureViewDescriptor destinationTextureViewDescriptor{
|
||||
.label = "resolve_destination_texture_view",
|
||||
.format = format,
|
||||
.dimension = destinationTexture->getViewDimension(),
|
||||
.baseMipLevel = destinationLevel,
|
||||
.mipLevelCount = 1,
|
||||
.baseArrayLayer = destinationLayer,
|
||||
.arrayLayerCount = 1,
|
||||
.aspect = destinationTexture->getAspect(),
|
||||
.usage = destinationTexture->getTexture().GetUsage(),
|
||||
};
|
||||
|
||||
const wgpu::TextureView destinationTextureView{ destinationTexture->getTexture().CreateView(
|
||||
&destinationTextureViewDescriptor) };
|
||||
FILAMENT_CHECK_POSTCONDITION(destinationTextureView) << "Failed to create wgpu::TextureView destinationTextureView.";
|
||||
const wgpu::RenderPassColorAttachment colorAttachment{
|
||||
.view = sourceTextureView,
|
||||
.depthSlice = wgpu::kDepthSliceUndefined, // being explicit for consistent behavior
|
||||
.resolveTarget = destinationTextureView,
|
||||
.loadOp = wgpu::LoadOp::Load,
|
||||
.storeOp = wgpu::StoreOp::Store,
|
||||
.clearValue = {}, // being explicit for consistent behavior
|
||||
};
|
||||
const wgpu::RenderPassDescriptor renderPassDescriptor{
|
||||
.label = "resolve_render_pass",
|
||||
.colorAttachmentCount = 1,
|
||||
.colorAttachments = &colorAttachment,
|
||||
.depthStencilAttachment = nullptr, // being explicit for consistent behavior
|
||||
.occlusionQuerySet = nullptr, // being explicit for consistent behavior
|
||||
.timestampWrites = nullptr, // being explicit for consistent behavior
|
||||
};
|
||||
|
||||
const wgpu::RenderPassEncoder renderPassEncoder{ mCommandEncoder.BeginRenderPass(
|
||||
&renderPassDescriptor) };
|
||||
FILAMENT_CHECK_POSTCONDITION(renderPassEncoder)
|
||||
<< "Failed to create wgpu::RenderPassEncoder for WebGPUDriver::resolve";
|
||||
renderPassEncoder.End(); // only the implicit resolve is happening in the pass
|
||||
mMsaaTextureResolver.resolve(request);
|
||||
}
|
||||
|
||||
void WebGPUDriver::blit(Handle<HwTexture> destinationTextureHandle, const uint8_t sourceLevel,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "WebGPURenderTarget.h"
|
||||
#include "webgpu/WebGPUConstants.h"
|
||||
#include "webgpu/WebGPUMsaaTextureResolver.h"
|
||||
#include "webgpu/WebGPURenderPassMipmapGenerator.h"
|
||||
#include <backend/platforms/WebGPUPlatform.h>
|
||||
|
||||
@@ -56,7 +57,7 @@ public:
|
||||
[[nodiscard]] static Driver* create(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
|
||||
|
||||
private:
|
||||
explicit WebGPUDriver(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
|
||||
WebGPUDriver(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
|
||||
[[nodiscard]] ShaderModel getShaderModel() const noexcept final;
|
||||
[[nodiscard]] ShaderLanguage getShaderLanguage() const noexcept final;
|
||||
[[nodiscard]] wgpu::Sampler makeSampler(SamplerParams const& params);
|
||||
@@ -80,6 +81,7 @@ private:
|
||||
WebGPURenderTarget* mCurrentRenderTarget = nullptr;
|
||||
WebGPURenderPassMipmapGenerator mRenderPassMipmapGenerator;
|
||||
spd::MipmapGenerator mSpdComputePassMipmapGenerator;
|
||||
WebGPUMsaaTextureResolver mMsaaTextureResolver{};
|
||||
|
||||
tsl::robin_map<size_t, wgpu::RenderPipeline> mPipelineMap;
|
||||
|
||||
|
||||
125
filament/backend/src/webgpu/WebGPUMsaaTextureResolver.cpp
Normal file
125
filament/backend/src/webgpu/WebGPUMsaaTextureResolver.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2025 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "WebGPUMsaaTextureResolver.h"
|
||||
|
||||
#include "WebGPUTexture.h"
|
||||
|
||||
#include <utils/Panic.h>
|
||||
|
||||
#include <webgpu/webgpu_cpp.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
namespace {
|
||||
|
||||
void resolveColorTextures(wgpu::CommandEncoder const& commandEncoder,
|
||||
wgpu::TextureView const& sourceTextureView,
|
||||
wgpu::TextureView const& destinationTextureView) {
|
||||
const wgpu::RenderPassColorAttachment colorAttachment{
|
||||
.view = sourceTextureView,
|
||||
.depthSlice = wgpu::kDepthSliceUndefined, // being explicit for consistent behavior
|
||||
.resolveTarget = destinationTextureView,
|
||||
.loadOp = wgpu::LoadOp::Load,
|
||||
.storeOp = wgpu::StoreOp::Store,
|
||||
.clearValue = {}, // being explicit for consistent behavior
|
||||
};
|
||||
const wgpu::RenderPassDescriptor renderPassDescriptor{
|
||||
.label = "resolve_render_pass",
|
||||
.colorAttachmentCount = 1,
|
||||
.colorAttachments = &colorAttachment,
|
||||
.depthStencilAttachment = nullptr, // being explicit for consistent behavior
|
||||
.occlusionQuerySet = nullptr, // being explicit for consistent behavior
|
||||
.timestampWrites = nullptr, // being explicit for consistent behavior
|
||||
};
|
||||
const wgpu::RenderPassEncoder renderPassEncoder{ commandEncoder.BeginRenderPass(
|
||||
&renderPassDescriptor) };
|
||||
FILAMENT_CHECK_POSTCONDITION(renderPassEncoder)
|
||||
<< "Failed to create wgpu::RenderPassEncoder for WebGPUDriver::resolve";
|
||||
renderPassEncoder.End(); // only the implicit resolve is happening in the pass
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void WebGPUMsaaTextureResolver::resolve(ResolveRequest const& request) {
|
||||
ResolveRequest::TextureInfo const& source{ request.source };
|
||||
ResolveRequest::TextureInfo const& destination{ request.destination };
|
||||
FILAMENT_CHECK_PRECONDITION(destination.texture.GetWidth() == source.texture.GetWidth() &&
|
||||
destination.texture.GetHeight() == source.texture.GetHeight())
|
||||
<< "invalid resolve: source and destination sizes don't match";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(
|
||||
source.texture.GetSampleCount() > 1 && destination.texture.GetSampleCount() == 1)
|
||||
<< "invalid resolve: source.samples=" << source.texture.GetSampleCount()
|
||||
<< ", destination.samples=" << destination.texture.GetSampleCount();
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(source.texture.GetFormat() == destination.texture.GetFormat())
|
||||
<< "source and destination texture format don't match";
|
||||
const wgpu::TextureFormat format{ source.texture.GetFormat() };
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(!hasDepth(format)) << "can't resolve depth formats";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(!hasStencil(format)) << "can't resolve stencil formats";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(source.texture.GetUsage() & wgpu::TextureUsage::RenderAttachment)
|
||||
<< "source texture usage doesn't have wgpu::TextureUsage::RenderAttachment";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(
|
||||
destination.texture.GetUsage() & wgpu::TextureUsage::RenderAttachment)
|
||||
<< "destination texture usage doesn't have wgpu::TextureUsage::RenderAttachment";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(destination.texture.GetUsage() & wgpu::TextureUsage::TextureBinding)
|
||||
<< "destination texture usage doesn't have wgpu::TextureUsage::TextureBinding";
|
||||
|
||||
const wgpu::TextureViewDescriptor sourceTextureViewDescriptor{
|
||||
.label = "resolve_source_texture_view",
|
||||
.format = request.viewFormat,
|
||||
.dimension = source.viewDimension,
|
||||
.baseMipLevel = source.mipLevel,
|
||||
.mipLevelCount = 1,
|
||||
.baseArrayLayer = source.layer,
|
||||
.arrayLayerCount = 1,
|
||||
.aspect = source.aspect,
|
||||
.usage = source.texture.GetUsage(),
|
||||
};
|
||||
const wgpu::TextureView sourceTextureView{ source.texture.CreateView(
|
||||
&sourceTextureViewDescriptor) };
|
||||
FILAMENT_CHECK_POSTCONDITION(sourceTextureView)
|
||||
<< "Failed to create wgpu::TextureView sourceTextureView";
|
||||
const wgpu::TextureViewDescriptor destinationTextureViewDescriptor{
|
||||
.label = "resolve_destination_texture_view",
|
||||
.format = request.viewFormat,
|
||||
.dimension = destination.viewDimension,
|
||||
.baseMipLevel = destination.mipLevel,
|
||||
.mipLevelCount = 1,
|
||||
.baseArrayLayer = destination.layer,
|
||||
.arrayLayerCount = 1,
|
||||
.aspect = destination.aspect,
|
||||
.usage = destination.texture.GetUsage(),
|
||||
};
|
||||
const wgpu::TextureView destinationTextureView{ destination.texture.CreateView(
|
||||
&destinationTextureViewDescriptor) };
|
||||
FILAMENT_CHECK_POSTCONDITION(destinationTextureView)
|
||||
<< "Failed to create wgpu::TextureView destinationTextureView.";
|
||||
|
||||
if (hasDepth(format)) {
|
||||
PANIC_PRECONDITION("DEPTH RESOLVE NOT IMPLEMENTED YET");
|
||||
} else {
|
||||
resolveColorTextures(request.commandEncoder, sourceTextureView, destinationTextureView);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace filament::backend
|
||||
55
filament/backend/src/webgpu/WebGPUMsaaTextureResolver.h
Normal file
55
filament/backend/src/webgpu/WebGPUMsaaTextureResolver.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2025 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_WEBGPUMSAATEXTURERESOLVER_H
|
||||
#define TNT_FILAMENT_BACKEND_WEBGPUMSAATEXTURERESOLVER_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace wgpu {
|
||||
class CommandEncoder;
|
||||
class Texture;
|
||||
enum class TextureAspect : uint32_t;
|
||||
enum class TextureFormat : uint32_t;
|
||||
enum class TextureViewDimension : uint32_t;
|
||||
} // namespace wgpu
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class WebGPUTexture;
|
||||
|
||||
class WebGPUMsaaTextureResolver final {
|
||||
public:
|
||||
struct ResolveRequest final {
|
||||
struct TextureInfo final {
|
||||
wgpu::Texture const& texture;
|
||||
wgpu::TextureViewDimension viewDimension;
|
||||
uint8_t mipLevel;
|
||||
uint8_t layer;
|
||||
wgpu::TextureAspect aspect;
|
||||
};
|
||||
wgpu::CommandEncoder const& commandEncoder;
|
||||
wgpu::TextureFormat viewFormat;
|
||||
TextureInfo source;
|
||||
TextureInfo destination;
|
||||
};
|
||||
|
||||
void resolve(ResolveRequest const&);
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_WEBGPUMSAATEXTURERESOLVER_H
|
||||
@@ -16,7 +16,11 @@
|
||||
|
||||
#include "WebGPURenderTarget.h"
|
||||
|
||||
#include "WebGPUTexture.h"
|
||||
|
||||
#include "DriverBase.h"
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Handle.h>
|
||||
#include <backend/TargetBufferInfo.h>
|
||||
|
||||
#include <private/backend/BackendUtils.h>
|
||||
@@ -26,14 +30,97 @@
|
||||
|
||||
#include <webgpu/webgpu_cpp.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* Panics if the number of samples in the original attachment textures do not match.
|
||||
* @return The number of samples in the original attachment textures (the number/count in each one).
|
||||
* Returns 0 if there are no attachments.
|
||||
*/
|
||||
[[nodiscard]] uint8_t createMsaaSidecarTextures(const uint8_t renderTargetSampleCount,
|
||||
const TargetBufferFlags targetFlags, MRT const& colorAttachments,
|
||||
TargetBufferInfo const& depthAttachment, TargetBufferInfo const& stencilAttachment,
|
||||
std::function<WebGPUTexture*(const Handle<HwTexture>)> const& getWebGPUTexture,
|
||||
wgpu::Device const& device) {
|
||||
struct Target final {
|
||||
std::string_view name;
|
||||
TargetBufferFlags flag{ TargetBufferFlags::NONE };
|
||||
size_t colorIndex{ 0 };
|
||||
};
|
||||
// assuming 8 colors. hopefully the following static_assert will get tripped if another
|
||||
// color ever gets added
|
||||
static_assert(
|
||||
(TargetBufferFlags::COLOR0 | TargetBufferFlags::COLOR1 | TargetBufferFlags::COLOR2 |
|
||||
TargetBufferFlags::COLOR3 | TargetBufferFlags::COLOR4 |
|
||||
TargetBufferFlags::COLOR5 | TargetBufferFlags::COLOR6 |
|
||||
TargetBufferFlags::COLOR7) == TargetBufferFlags::COLOR_ALL);
|
||||
const static std::array TARGETS{
|
||||
Target{ .name = "COLOR0", .flag = TargetBufferFlags::COLOR0, .colorIndex = 0 },
|
||||
Target{ .name = "COLOR1", .flag = TargetBufferFlags::COLOR1, .colorIndex = 1 },
|
||||
Target{ .name = "COLOR2", .flag = TargetBufferFlags::COLOR2, .colorIndex = 2 },
|
||||
Target{ .name = "COLOR3", .flag = TargetBufferFlags::COLOR3, .colorIndex = 3 },
|
||||
Target{ .name = "COLOR4", .flag = TargetBufferFlags::COLOR4, .colorIndex = 4 },
|
||||
Target{ .name = "COLOR5", .flag = TargetBufferFlags::COLOR5, .colorIndex = 5 },
|
||||
Target{ .name = "COLOR6", .flag = TargetBufferFlags::COLOR6, .colorIndex = 6 },
|
||||
Target{ .name = "COLOR7", .flag = TargetBufferFlags::COLOR7, .colorIndex = 7 },
|
||||
Target{ .name = "DEPTH", .flag = TargetBufferFlags::DEPTH },
|
||||
Target{ .name = "STENCIL", .flag = TargetBufferFlags::STENCIL },
|
||||
};
|
||||
#ifndef NDEBUG
|
||||
for (auto const& target: TARGETS) {
|
||||
assert_invariant(target.colorIndex <= MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT &&
|
||||
"color index is >= MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT, which should "
|
||||
"not be possible and could lead to us indexing into the colorAttachments "
|
||||
"array beyond its bounds.");
|
||||
}
|
||||
#endif
|
||||
bool firstAttachment{ true };
|
||||
uint8_t sampleCountPerAttachment{ 0 };
|
||||
for (auto const& target: TARGETS) {
|
||||
if (any(targetFlags & target.flag)) {
|
||||
const Handle<HwTexture> textureHandle{
|
||||
target.flag == TargetBufferFlags::DEPTH
|
||||
? depthAttachment.handle
|
||||
: (target.flag == TargetBufferFlags::STENCIL
|
||||
? stencilAttachment.handle
|
||||
: colorAttachments[target.colorIndex].handle)
|
||||
};
|
||||
WebGPUTexture* const texture{ getWebGPUTexture(textureHandle) };
|
||||
assert_invariant(texture != nullptr && "target flag indicate the use of an attachment "
|
||||
"for which we do not have a texture?");
|
||||
if (firstAttachment) {
|
||||
sampleCountPerAttachment = texture->samples;
|
||||
firstAttachment = false;
|
||||
}
|
||||
FILAMENT_CHECK_PRECONDITION(texture->samples == sampleCountPerAttachment)
|
||||
<< target.name << " attachment texture has " << +texture->samples
|
||||
<< " but the other attachment(s) have " << +sampleCountPerAttachment;
|
||||
if (renderTargetSampleCount > 1 && sampleCountPerAttachment == 1) {
|
||||
texture->createMsaaSidecarTextureIfNotAlreadyCreated(renderTargetSampleCount,
|
||||
device);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_invariant(sampleCountPerAttachment);
|
||||
return sampleCountPerAttachment;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
WebGPURenderTarget::WebGPURenderTarget(const uint32_t width, const uint32_t height,
|
||||
const uint8_t samples, const uint8_t layerCount, MRT const& colorAttachmentsMRT,
|
||||
Attachment const& depthAttachmentInfo, Attachment const& stencilAttachmentInfo,
|
||||
TargetBufferFlags const& targetFlags)
|
||||
TargetBufferFlags const& targetFlags,
|
||||
std::function<WebGPUTexture*(const Handle<HwTexture>)> const& getWebGPUTexture,
|
||||
wgpu::Device const& device)
|
||||
: HwRenderTarget{ width, height },
|
||||
mDefaultRenderTarget{ false },
|
||||
mTargetFlags{ targetFlags },
|
||||
@@ -41,8 +128,11 @@ WebGPURenderTarget::WebGPURenderTarget(const uint32_t width, const uint32_t heig
|
||||
mLayerCount{ layerCount },
|
||||
mColorAttachments{ colorAttachmentsMRT },
|
||||
mDepthAttachment{ depthAttachmentInfo },
|
||||
mStencilAttachment{ stencilAttachmentInfo } {
|
||||
// TODO consider making this an array
|
||||
mStencilAttachment{ stencilAttachmentInfo },
|
||||
mSampleCountPerAttachment{ createMsaaSidecarTextures(mSamples, mTargetFlags,
|
||||
mColorAttachments, mDepthAttachment, mStencilAttachment, getWebGPUTexture, device) } {
|
||||
// TODO consider possibly making this an array (that would avoid a heap allocation, but the
|
||||
// concern is the size limitation on the handle itself)
|
||||
mColorAttachmentDesc.reserve(MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT);
|
||||
}
|
||||
|
||||
@@ -52,8 +142,8 @@ WebGPURenderTarget::WebGPURenderTarget()
|
||||
mDefaultRenderTarget{ true },
|
||||
mTargetFlags{ TargetBufferFlags::NONE },
|
||||
mSamples{ 1 },
|
||||
mLayerCount{ 1 }
|
||||
{}
|
||||
mLayerCount{ 1 },
|
||||
mSampleCountPerAttachment{ 1 } {}
|
||||
|
||||
wgpu::LoadOp WebGPURenderTarget::getLoadOperation(RenderPassParams const& params,
|
||||
const TargetBufferFlags bufferToOperateOn) {
|
||||
@@ -77,8 +167,35 @@ wgpu::StoreOp WebGPURenderTarget::getStoreOperation(RenderPassParams const& para
|
||||
void WebGPURenderTarget::setUpRenderPassAttachments(wgpu::RenderPassDescriptor& outDescriptor,
|
||||
RenderPassParams const& params, wgpu::TextureView const& defaultColorTextureView,
|
||||
wgpu::TextureView const& defaultDepthStencilTextureView,
|
||||
wgpu::TextureView const* customColorTextureViews, uint32_t customColorTextureViewCount,
|
||||
wgpu::TextureView const& customDepthStencilTextureView) {
|
||||
wgpu::TextureView const* customColorTextureViews,
|
||||
wgpu::TextureView const* customColorMsaaSidecarTextureViews,
|
||||
uint32_t customColorTextureViewCount,
|
||||
wgpu::TextureView const& customDepthStencilTextureView,
|
||||
wgpu::TextureView const& customDepthStencilMsaaSidecarTextureView) {
|
||||
const bool hasMsaaSidecars{ (customColorTextureViewCount > 0 &&
|
||||
customColorMsaaSidecarTextureViews[0]) ||
|
||||
customDepthStencilMsaaSidecarTextureView };
|
||||
// either all the textures have MSAA sidecars or none of them do
|
||||
if (hasMsaaSidecars) {
|
||||
FILAMENT_CHECK_PRECONDITION(std::all_of(customColorMsaaSidecarTextureViews,
|
||||
customColorMsaaSidecarTextureViews + customColorTextureViewCount,
|
||||
[](wgpu::TextureView const& msaaView) { return msaaView != nullptr; }))
|
||||
<< "A color or depth/stencil attachment texture has a MSAA sidecar but at least "
|
||||
"one other color attachment texture does not.";
|
||||
FILAMENT_CHECK_PRECONDITION(customDepthStencilMsaaSidecarTextureView != nullptr)
|
||||
<< "The color attachment texture(s) have MSAA sidecar(s) but the depth/stencil "
|
||||
"texture does not.";
|
||||
} else {
|
||||
FILAMENT_CHECK_PRECONDITION(std::all_of(customColorMsaaSidecarTextureViews,
|
||||
customColorMsaaSidecarTextureViews + customColorTextureViewCount,
|
||||
[](wgpu::TextureView const& msaaView) { return msaaView == nullptr; }))
|
||||
<< "A color or depth/stencil attachment texture does not have a MSAA sidecar but "
|
||||
"at least one color attachment texture does.";
|
||||
FILAMENT_CHECK_PRECONDITION(customDepthStencilMsaaSidecarTextureView == nullptr)
|
||||
<< "Custom color textures for the render target do not have MSAA sidecar(s) but "
|
||||
"the depth/stencil texture does.";
|
||||
}
|
||||
|
||||
mColorAttachmentDesc.clear();
|
||||
|
||||
const bool hasDepth = any(mTargetFlags & TargetBufferFlags::DEPTH);
|
||||
@@ -104,9 +221,10 @@ void WebGPURenderTarget::setUpRenderPassAttachments(wgpu::RenderPassDescriptor&
|
||||
} else {
|
||||
for (uint32_t i = 0; i < customColorTextureViewCount; ++i) {
|
||||
if (customColorTextureViews[i]) {
|
||||
mColorAttachmentDesc.push_back({ .view = customColorTextureViews[i],
|
||||
.resolveTarget =
|
||||
nullptr, // We handle MSAA on the WebGPU driver's resolve function
|
||||
const wgpu::TextureView msaaSidecar{ customColorMsaaSidecarTextureViews[i] };
|
||||
mColorAttachmentDesc.push_back({
|
||||
.view = hasMsaaSidecars ? msaaSidecar : customColorTextureViews[i],
|
||||
.resolveTarget = hasMsaaSidecars ? customColorTextureViews[i] : nullptr,
|
||||
.loadOp =
|
||||
WebGPURenderTarget::getLoadOperation(params, getTargetBufferFlagsAt(i)),
|
||||
.storeOp = WebGPURenderTarget::getStoreOperation(params,
|
||||
@@ -132,7 +250,8 @@ void WebGPURenderTarget::setUpRenderPassAttachments(wgpu::RenderPassDescriptor&
|
||||
assert_invariant(depthStencilViewToUse);
|
||||
} else {
|
||||
if (customDepthStencilTextureView) {
|
||||
depthStencilViewToUse = customDepthStencilTextureView;
|
||||
depthStencilViewToUse = hasMsaaSidecars ? customDepthStencilMsaaSidecarTextureView
|
||||
: customDepthStencilTextureView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H
|
||||
#define TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H
|
||||
|
||||
#include "WebGPUTexture.h"
|
||||
|
||||
#include "DriverBase.h"
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/TargetBufferInfo.h>
|
||||
@@ -24,6 +26,7 @@
|
||||
#include <webgpu/webgpu_cpp.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace filament::backend {
|
||||
@@ -34,24 +37,27 @@ public:
|
||||
|
||||
WebGPURenderTarget(uint32_t width, uint32_t height, uint8_t samples, uint8_t layerCount,
|
||||
MRT const& colorAttachments, Attachment const& depthAttachment,
|
||||
Attachment const& stencilAttachment, TargetBufferFlags const& targetFlags);
|
||||
Attachment const& stencilAttachment, TargetBufferFlags const& targetFlags,
|
||||
std::function<WebGPUTexture*(const Handle<HwTexture>)> const&, wgpu::Device const&);
|
||||
|
||||
// Default constructor for the default render target
|
||||
WebGPURenderTarget();
|
||||
|
||||
void setUpRenderPassAttachments(
|
||||
wgpu::RenderPassDescriptor& outDescriptor,
|
||||
void setUpRenderPassAttachments(wgpu::RenderPassDescriptor& outDescriptor,
|
||||
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
|
||||
wgpu::TextureView const* customColorTextureViews, // Array of views
|
||||
wgpu::TextureView const* customColorMsaaSidecarTextureViews, // nullptrs if N/A
|
||||
uint32_t customColorTextureViewCount,
|
||||
wgpu::TextureView const& customDepthStencilTextureView);
|
||||
wgpu::TextureView const& customDepthStencilTextureView,
|
||||
wgpu::TextureView const& customDepthStencilMsaaSidecarTextureView /* nullptr if N/A */);
|
||||
|
||||
[[nodiscard]] bool isDefaultRenderTarget() const { return mDefaultRenderTarget; }
|
||||
[[nodiscard]] uint8_t getSamples() const { return mSamples; }
|
||||
[[nodiscard]] uint8_t getSampleCountPerAttachment() const { return mSampleCountPerAttachment; }
|
||||
[[nodiscard]] uint8_t getLayerCount() const { return mLayerCount; }
|
||||
|
||||
[[nodiscard]] MRT const& getColorAttachmentInfos() const { return mColorAttachments; }
|
||||
@@ -78,6 +84,8 @@ private:
|
||||
Attachment mDepthAttachment{};
|
||||
Attachment mStencilAttachment{};
|
||||
|
||||
uint8_t mSampleCountPerAttachment = 0;
|
||||
|
||||
// Cached descriptors for the render pass
|
||||
std::vector<wgpu::RenderPassColorAttachment> mColorAttachmentDesc;
|
||||
wgpu::RenderPassDepthStencilAttachment mDepthStencilAttachmentDesc{};
|
||||
|
||||
@@ -402,7 +402,21 @@ WebGPUTexture::WebGPUTexture(WebGPUTexture const* src, const uint8_t baseLevel,
|
||||
mDefaultMipLevel{ baseLevel },
|
||||
mDefaultBaseArrayLayer{ src->mArrayLayerCount },
|
||||
mDefaultTextureView{ makeTextureView(mDefaultMipLevel, levelCount, 0, mDefaultBaseArrayLayer,
|
||||
src->target) } {}
|
||||
src->target) },
|
||||
mMsaaSidecarTexture{ src->mMsaaSidecarTexture } {}
|
||||
|
||||
wgpu::Texture const& WebGPUTexture::getMsaaSidecarTexture(const uint8_t sampleCount) const {
|
||||
if (mMsaaSidecarTexture == nullptr) {
|
||||
return mMsaaSidecarTexture; // nullptr (no such sidecar)
|
||||
}
|
||||
FILAMENT_CHECK_PRECONDITION(sampleCount == mMsaaSidecarTexture.GetSampleCount())
|
||||
<< "The MSAA sidecar texture has a different sample count ("
|
||||
<< mMsaaSidecarTexture.GetSampleCount() << ") than requested (" << +sampleCount
|
||||
<< "). Note that this restriction was written when WebGPU only supported msaa "
|
||||
"textures with 4 samples. If that has changed, this implementation should be "
|
||||
"updated (e.g. map of sidecar textures by sampleCount or something).";
|
||||
return mMsaaSidecarTexture;
|
||||
}
|
||||
|
||||
bool WebGPUTexture::supportsMultipleMipLevelsViaStorageBinding(const wgpu::TextureFormat format) {
|
||||
return storageBindingCompatibleFormatForViewFormat(format) != wgpu::TextureFormat::Undefined;
|
||||
@@ -417,6 +431,68 @@ wgpu::TextureView WebGPUTexture::getOrMakeTextureView(const uint8_t mipLevel,
|
||||
return makeTextureView(mipLevel, 1, arrayLayer, 1, target);
|
||||
}
|
||||
|
||||
void WebGPUTexture::createMsaaSidecarTextureIfNotAlreadyCreated(const uint8_t samples,
|
||||
wgpu::Device const& device) {
|
||||
FILAMENT_CHECK_PRECONDITION(samples > 1) << "Requesting to create a MSAA sidecar texture for "
|
||||
<< +samples << " samples? Invalid request.";
|
||||
if (mMsaaSidecarTexture) {
|
||||
FILAMENT_CHECK_PRECONDITION(mMsaaSidecarTexture.GetSampleCount() == samples)
|
||||
<< "An MSAA sidecar texture has already been created for this texture, but with a "
|
||||
"different sample count ("
|
||||
<< mMsaaSidecarTexture.GetSampleCount() << ") than requested (" << +samples
|
||||
<< "). Note that this restriction was written when WebGPU only supported msaa "
|
||||
"textures with 4 samples. If that has changed, this implementation should be "
|
||||
"updated (e.g. map of sidecar textures by sampleCount or something).";
|
||||
return; // we already have the sidecar created
|
||||
}
|
||||
const wgpu::TextureDescriptor descriptor{
|
||||
.label = "msaa_sidecar_texture",
|
||||
.usage = mTexture.GetUsage(),
|
||||
.dimension = mTexture.GetDimension(),
|
||||
.size = {
|
||||
.width = mTexture.GetWidth(),
|
||||
.height = mTexture.GetHeight(),
|
||||
.depthOrArrayLayers = mTexture.GetDepthOrArrayLayers(),
|
||||
},
|
||||
.format = mTexture.GetFormat(),
|
||||
.mipLevelCount = mTexture.GetMipLevelCount(),
|
||||
.sampleCount = samples,
|
||||
.viewFormatCount = 1,
|
||||
.viewFormats = &mViewFormat,
|
||||
};
|
||||
mMsaaSidecarTexture = device.CreateTexture(&descriptor);
|
||||
FILAMENT_CHECK_POSTCONDITION(mMsaaSidecarTexture) << "Failed to create MSAA sidecar texture";
|
||||
}
|
||||
|
||||
wgpu::TextureView WebGPUTexture::makeMsaaSidecarTextureViewIfTextureSidecarExists(
|
||||
const uint8_t samples, const uint8_t mipLevel, const uint32_t arrayLayer) const {
|
||||
if (mMsaaSidecarTexture == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
FILAMENT_CHECK_PRECONDITION(mMsaaSidecarTexture.GetSampleCount() == samples)
|
||||
<< "An MSAA sidecar texture has already been created for this texture, but with a "
|
||||
"different sample count ("
|
||||
<< mMsaaSidecarTexture.GetSampleCount() << ") than requested for view (" << +samples
|
||||
<< "). Note that this restriction was written when WebGPU only supported msaa "
|
||||
"textures with 4 samples. If that has changed, this implementation should be "
|
||||
"updated (e.g. map of sidecar textures by sampleCount or something).";
|
||||
const wgpu::TextureViewDescriptor descriptor{
|
||||
.label = "msaa_sidecar_texture_view",
|
||||
.format = mViewFormat,
|
||||
.dimension = mDimension,
|
||||
.baseMipLevel = mipLevel,
|
||||
.mipLevelCount = 1,
|
||||
.baseArrayLayer = arrayLayer,
|
||||
.arrayLayerCount = 1,
|
||||
.aspect = mAspect,
|
||||
.usage = mViewUsage,
|
||||
};
|
||||
const wgpu::TextureView textureView{ mMsaaSidecarTexture.CreateView(&descriptor) };
|
||||
FILAMENT_CHECK_POSTCONDITION(mMsaaSidecarTexture)
|
||||
<< "Failed to create MSAA sidecar texture view (" << +samples << " samples)";
|
||||
return textureView;
|
||||
}
|
||||
|
||||
wgpu::TextureFormat WebGPUTexture::fToWGPUTextureFormat(TextureFormat const& fFormat) {
|
||||
switch (fFormat) {
|
||||
case TextureFormat::R8: return wgpu::TextureFormat::R8Unorm;
|
||||
@@ -591,16 +667,6 @@ wgpu::TextureFormat WebGPUTexture::fToWGPUTextureFormat(TextureFormat const& fFo
|
||||
wgpu::TextureView WebGPUTexture::makeTextureView(const uint8_t& baseLevel,
|
||||
const uint8_t& levelCount, const uint32_t& baseArrayLayer, const uint32_t& arrayLayerCount,
|
||||
const SamplerType samplerType) const noexcept {
|
||||
#if FWGPU_ENABLED(FWGPU_DEBUG_VALIDATION)
|
||||
if (baseLevel > 0 && mMipmapGenerationStrategy == MipmapGenerationStrategy::NONE) {
|
||||
FWGPU_LOGW << "Trying to make a texture view into a level ("
|
||||
<< static_cast<uint32_t>(baseLevel)
|
||||
<< ") for which we cannot generate mip levels. SamplerType "
|
||||
<< to_string(samplerType) << " WebGPU view format "
|
||||
<< webGPUTextureFormatToString(mViewFormat) << " samples "
|
||||
<< static_cast<uint32_t>(samples);
|
||||
}
|
||||
#endif
|
||||
const wgpu::TextureViewDescriptor textureViewDescriptor{
|
||||
.label = getUserTextureViewLabel(target),
|
||||
.format = mViewFormat,
|
||||
|
||||
@@ -26,6 +26,20 @@
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
[[nodiscard]] constexpr bool hasStencil(const wgpu::TextureFormat textureFormat) {
|
||||
return textureFormat == wgpu::TextureFormat::Depth24PlusStencil8 ||
|
||||
textureFormat == wgpu::TextureFormat::Depth32FloatStencil8 ||
|
||||
textureFormat == wgpu::TextureFormat::Stencil8;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool hasDepth(const wgpu::TextureFormat textureFormat) {
|
||||
return textureFormat == wgpu::TextureFormat::Depth16Unorm ||
|
||||
textureFormat == wgpu::TextureFormat::Depth32Float ||
|
||||
textureFormat == wgpu::TextureFormat::Depth24Plus ||
|
||||
textureFormat == wgpu::TextureFormat::Depth24PlusStencil8 ||
|
||||
textureFormat == wgpu::TextureFormat::Depth32FloatStencil8;
|
||||
}
|
||||
|
||||
class WebGPUTexture : public HwTexture {
|
||||
public:
|
||||
enum class MipmapGenerationStrategy : uint8_t {
|
||||
@@ -47,6 +61,8 @@ public:
|
||||
|
||||
[[nodiscard]] wgpu::Texture const& getTexture() const { return mTexture; }
|
||||
|
||||
[[nodiscard]] wgpu::Texture const& getMsaaSidecarTexture(uint8_t sampleCount) const;
|
||||
|
||||
[[nodiscard]] wgpu::TextureView const& getDefaultTextureView() const {
|
||||
return mDefaultTextureView;
|
||||
}
|
||||
@@ -62,6 +78,33 @@ public:
|
||||
return mMipmapGenerationStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the MSAA sidecar texture if it has not already been created.
|
||||
* If the sidecar already exists with a different number of samples this will panic
|
||||
* (at the time of writing this WebGPU only supports MSAA with 4 samples. If this changes, then
|
||||
* multiple sidecars with different number of samples could be supported if needed, but that
|
||||
* level of complexity is not warranted at this time).
|
||||
* Additionally, if samples is <= 1 this will panic as well, as that is not an MSAA texture.
|
||||
* @param samples The number of samples the texture will have
|
||||
*/
|
||||
void createMsaaSidecarTextureIfNotAlreadyCreated(uint8_t samples, wgpu::Device const&);
|
||||
|
||||
/**
|
||||
* @param samples The number of samples the underlying texture supports
|
||||
* @param mipLevel The mip level into the underyling texture for which this view will reference
|
||||
* (this view will only have one mip level)
|
||||
* @param arrayLayer The layer into the underyling texture for which this view will reference
|
||||
* (this view will only have one layer)
|
||||
* @return A texture view for the MSAA sidecar texture
|
||||
*/
|
||||
wgpu::TextureView makeMsaaSidecarTextureViewIfTextureSidecarExists(uint8_t samples,
|
||||
uint8_t mipLevel, uint32_t arrayLayer) const;
|
||||
|
||||
/**
|
||||
* @return nullptr if a MSAA sidecar texture is not appliable, otherwise a view to one
|
||||
*/
|
||||
[[nodiscard]] wgpu::TextureView makeMsaaSidecarTextureView(wgpu::Texture const&, uint8_t mipLevel, uint32_t arrayLayer) const;
|
||||
|
||||
[[nodiscard]] static wgpu::TextureFormat fToWGPUTextureFormat(
|
||||
filament::backend::TextureFormat const& fFormat);
|
||||
|
||||
@@ -96,6 +139,11 @@ private:
|
||||
uint32_t mDefaultMipLevel = 0;
|
||||
uint32_t mDefaultBaseArrayLayer = 0;
|
||||
wgpu::TextureView mDefaultTextureView = nullptr;
|
||||
// At the time of writing this, WebGPU only supported 4 samples in a multi-sampled texture.
|
||||
// If that has changed, then consider updating the implementation to have a map of msaa textures
|
||||
// by sampleCount or something like that.
|
||||
// For now that complexity and cost is not warranted due to WebGPU's restrictions.
|
||||
wgpu::Texture mMsaaSidecarTexture = nullptr;
|
||||
|
||||
[[nodiscard]] wgpu::TextureView makeTextureView(const uint8_t& baseLevel,
|
||||
const uint8_t& levelCount, const uint32_t& baseArrayLayer,
|
||||
|
||||
@@ -118,6 +118,7 @@ INPUT = ../libs/filabridge/include \
|
||||
../libs/gltfio/include \
|
||||
../libs/utils/include \
|
||||
backend/include \
|
||||
backend/include/private/backend/DriverAPI.dox \
|
||||
include
|
||||
|
||||
INPUT_ENCODING = UTF-8
|
||||
|
||||
@@ -57,7 +57,8 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
|
||||
|
||||
public:
|
||||
using CullingMode = backend::CullingMode;
|
||||
using TransparencyMode = TransparencyMode;
|
||||
// ReSharper disable once CppRedundantQualifier
|
||||
using TransparencyMode = filament::TransparencyMode;
|
||||
using DepthFunc = backend::SamplerCompareFunc;
|
||||
using StencilCompareFunc = backend::SamplerCompareFunc;
|
||||
using StencilOperation = backend::StencilOperation;
|
||||
|
||||
@@ -2989,7 +2989,7 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::upscale(FrameGraph& fg, bool
|
||||
}
|
||||
|
||||
if (dsrOptions.quality == QualityLevel::LOW) {
|
||||
return upscaleBilinear(fg, translucent, dsrOptions, input, vp, outDesc, filter);
|
||||
return upscaleBilinear(fg, dsrOptions, input, vp, outDesc, filter);
|
||||
}
|
||||
if (dsrOptions.quality == QualityLevel::MEDIUM) {
|
||||
return upscaleSGSR1(fg, sourceHasLuminance, dsrOptions, input, vp, outDesc);
|
||||
@@ -2997,7 +2997,7 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::upscale(FrameGraph& fg, bool
|
||||
return upscaleFSR1(fg, dsrOptions, input, vp, outDesc);
|
||||
}
|
||||
|
||||
FrameGraphId<FrameGraphTexture> PostProcessManager::upscaleBilinear(FrameGraph& fg, bool translucent,
|
||||
FrameGraphId<FrameGraphTexture> PostProcessManager::upscaleBilinear(FrameGraph& fg,
|
||||
DynamicResolutionOptions dsrOptions, FrameGraphId<FrameGraphTexture> const input,
|
||||
filament::Viewport const& vp, FrameGraphTexture::Descriptor const& outDesc,
|
||||
SamplerMagFilter filter) noexcept {
|
||||
@@ -3016,18 +3016,10 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::upscaleBilinear(FrameGraph&
|
||||
.attachments = { .color = { data.output } },
|
||||
.clearFlags = TargetBufferFlags::DEPTH });
|
||||
},
|
||||
[this, vp, translucent, filter](FrameGraphResources const& resources,
|
||||
[this, vp, filter](FrameGraphResources const& resources,
|
||||
auto const& data, DriverApi& driver) {
|
||||
bindPostProcessDescriptorSet(driver);
|
||||
|
||||
// helper to enable blending
|
||||
auto enableTranslucentBlending = [](PipelineState& pipeline) {
|
||||
pipeline.rasterState.blendFunctionSrcRGB = BlendFunction::ONE;
|
||||
pipeline.rasterState.blendFunctionSrcAlpha = BlendFunction::ONE;
|
||||
pipeline.rasterState.blendFunctionDstRGB = BlendFunction::ONE_MINUS_SRC_ALPHA;
|
||||
pipeline.rasterState.blendFunctionDstAlpha = BlendFunction::ONE_MINUS_SRC_ALPHA;
|
||||
};
|
||||
|
||||
auto color = resources.getTexture(data.input);
|
||||
auto const& inputDesc = resources.getDescriptor(data.input);
|
||||
|
||||
@@ -3055,9 +3047,6 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::upscaleBilinear(FrameGraph&
|
||||
auto out = resources.getRenderPassInfo();
|
||||
|
||||
auto pipeline = getPipelineState(material.getMaterial(mEngine));
|
||||
if (translucent) {
|
||||
enableTranslucentBlending(pipeline);
|
||||
}
|
||||
renderFullScreenQuad(out, pipeline, driver);
|
||||
});
|
||||
|
||||
@@ -3065,7 +3054,8 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::upscaleBilinear(FrameGraph&
|
||||
|
||||
// if we had to take the low quality fallback, we still do the "sharpen pass"
|
||||
if (dsrOptions.sharpness > 0.0f) {
|
||||
output = rcas(fg, dsrOptions.sharpness, output, outDesc, translucent);
|
||||
output = rcas(fg, dsrOptions.sharpness, output, outDesc,
|
||||
false /* translucent=false, because dst buffer is allocated */);
|
||||
}
|
||||
|
||||
// we rely on automatic culling of unused render passes
|
||||
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
FrameGraphId<FrameGraphTexture> input, Viewport const& vp,
|
||||
FrameGraphTexture::Descriptor const& outDesc, backend::SamplerMagFilter filter) noexcept;
|
||||
|
||||
FrameGraphId<FrameGraphTexture> upscaleBilinear(FrameGraph& fg, bool translucent,
|
||||
FrameGraphId<FrameGraphTexture> upscaleBilinear(FrameGraph& fg,
|
||||
DynamicResolutionOptions dsrOptions, FrameGraphId<FrameGraphTexture> input,
|
||||
Viewport const& vp, FrameGraphTexture::Descriptor const& outDesc,
|
||||
backend::SamplerMagFilter filter) noexcept;
|
||||
|
||||
@@ -98,6 +98,14 @@ namespace filament::fgviewer {
|
||||
} // namespace filament::fgviewer
|
||||
#endif
|
||||
|
||||
// We have added correctness assertions that breaks clients' projects. We add this define to allow
|
||||
// for the client's to address these assertions at a more gradual pace.
|
||||
#if defined(FILAMENT_RELAXED_CORRECTNESS_ASSERTIONS)
|
||||
#define CORRECTNESS_ASSERTION_DEFAULT false
|
||||
#else
|
||||
#define CORRECTNESS_ASSERTION_DEFAULT true
|
||||
#endif
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Renderer;
|
||||
@@ -715,10 +723,14 @@ public:
|
||||
bool use_shadow_atlas = false;
|
||||
} shadows;
|
||||
struct {
|
||||
// TODO: default the following two flags to true.
|
||||
bool assert_material_instance_in_use = false;
|
||||
bool assert_destroy_material_before_material_instance = false;
|
||||
bool assert_vertex_buffer_count_exceeds_8 = false;
|
||||
// TODO: clean-up the following flags (equivalent to setting them to true) when
|
||||
// clients have addressed their usages.
|
||||
bool assert_material_instance_in_use = CORRECTNESS_ASSERTION_DEFAULT;
|
||||
bool assert_destroy_material_before_material_instance =
|
||||
CORRECTNESS_ASSERTION_DEFAULT;
|
||||
bool assert_vertex_buffer_count_exceeds_8 = CORRECTNESS_ASSERTION_DEFAULT;
|
||||
bool assert_vertex_buffer_attribute_stride_mult_of_4 =
|
||||
CORRECTNESS_ASSERTION_DEFAULT;
|
||||
} debug;
|
||||
} engine;
|
||||
struct {
|
||||
@@ -759,6 +771,9 @@ public:
|
||||
{ "features.engine.debug.assert_vertex_buffer_count_exceeds_8",
|
||||
"Assert when a client's number of buffers for a VertexBuffer exceeds 8.",
|
||||
&features.engine.debug.assert_vertex_buffer_count_exceeds_8, false },
|
||||
{ "features.engine.debug.assert_vertex_buffer_attribute_stride_mult_of_4",
|
||||
"Assert that the attribute stride of a vertex buffer is a multiple of 4.",
|
||||
&features.engine.debug.assert_vertex_buffer_attribute_stride_mult_of_4, false },
|
||||
}};
|
||||
|
||||
utils::Slice<const FeatureFlag> getFeatureFlags() const noexcept {
|
||||
|
||||
@@ -386,8 +386,9 @@ void FTexture::setImage(FEngine& engine, size_t const level,
|
||||
FILAMENT_CHECK_PRECONDITION(any(mUsage & Texture::Usage::UPLOADABLE))
|
||||
<< "Texture is not uploadable.";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(mSampleCount <= 1) << "Operation not supported with multisample ("
|
||||
<< unsigned(mSampleCount) << ") texture.";
|
||||
FILAMENT_CHECK_PRECONDITION(mSampleCount <= 1)
|
||||
<< "Operation not supported with multisample ("
|
||||
<< unsigned(mSampleCount) << ") texture.";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION(xoffset + width <= valueForLevel(level, mWidth))
|
||||
<< "xoffset (" << unsigned(xoffset) << ") + width (" << unsigned(width)
|
||||
@@ -428,28 +429,46 @@ void FTexture::setImage(FEngine& engine, size_t const level,
|
||||
<< ") > texture depth (" << effectiveTextureDepthOrLayers << ") at level ("
|
||||
<< unsigned(level) << ")";
|
||||
|
||||
if (UTILS_UNLIKELY(!width || !height || !depth)) {
|
||||
// The operation is a no-op, return immediately. The PixelBufferDescriptor callback
|
||||
// should be called automatically when the object is destroyed.
|
||||
// The precondition check below assumes width, height, depth non null.
|
||||
return;
|
||||
}
|
||||
|
||||
if (p.type != PixelDataType::COMPRESSED) {
|
||||
using PBD = PixelBufferDescriptor;
|
||||
size_t const stride = p.stride ? p.stride : width;
|
||||
size_t const bpp = PBD::computePixelSize(p.format, p.type);
|
||||
size_t const bpp = PBD::computeDataSize(p.format, p.type, 1, 1, 1);
|
||||
size_t const bpr = PBD::computeDataSize(p.format, p.type, stride, 1, p.alignment);
|
||||
size_t const pbdWidth = stride;
|
||||
// TODO: PBD should have a "layer stride" (using "depth" as a substitute).
|
||||
size_t const pbdDepth = depth;
|
||||
size_t const pbdHeight = p.size / bpr / pbdDepth;
|
||||
assert_invariant(p.size % bpr == 0 && (p.size / bpr) % pbdDepth == 0);
|
||||
|
||||
size_t const bpl = bpr * height; // TODO: PBD should have a "layer stride"
|
||||
// TODO: PBD should have a p.depth (# layers to skip)
|
||||
FILAMENT_CHECK_PRECONDITION(
|
||||
bpp * (pbdWidth - p.left) * (pbdHeight - p.top) * (pbdDepth - 0) >=
|
||||
bpp * width * height * depth)
|
||||
|
||||
/* Calculates the byte offset of the last pixel in a 3D sub-region. */
|
||||
auto const calculateLastPixelOffset = [bpp, bpr, bpl](
|
||||
size_t xoff, size_t yoff, size_t zoff,
|
||||
size_t width, size_t height, size_t depth) {
|
||||
// The 0-indexed coordinates of the last pixel are:
|
||||
// x = xoff + width - 1
|
||||
// y = yoff + height - 1
|
||||
// z = zoff + depth - 1
|
||||
// The offset is calculated as: (z * bpl) + (y * bpr) + (x * bpp)
|
||||
return ((zoff + depth - 1) * bpl) +
|
||||
((yoff + height - 1) * bpr) +
|
||||
((xoff + width - 1) * bpp);
|
||||
};
|
||||
|
||||
size_t const lastPixelOffset = calculateLastPixelOffset(
|
||||
p.left, p.top, 0, width, height, depth);
|
||||
|
||||
// make sure the whole last pixel is in the buffer
|
||||
FILAMENT_CHECK_PRECONDITION(lastPixelOffset + bpp <= p.size)
|
||||
<< "buffer overflow: (size=" << size_t(p.size) << ", stride=" << size_t(p.stride)
|
||||
<< ", left=" << unsigned(p.left) << ", top=" << unsigned(p.top)
|
||||
<< ") smaller than specified region "
|
||||
"{{"
|
||||
<< unsigned(xoffset) << "," << unsigned(yoffset) << "," << unsigned(zoffset)
|
||||
<< "},{" << unsigned(width) << "," << unsigned(height) << "," << unsigned(depth)
|
||||
<< ")}}";
|
||||
<< unsigned(xoffset) << "," << unsigned(yoffset) << "," << unsigned(zoffset) << "},{"
|
||||
<< unsigned(width) << "," << unsigned(height) << "," << unsigned(depth) << ")}}";
|
||||
}
|
||||
|
||||
engine.getDriverApi().update3DImage(mHandle, uint8_t(level), xoffset, yoffset, zoffset, width,
|
||||
|
||||
@@ -177,9 +177,15 @@ VertexBuffer* VertexBuffer::Builder::build(Engine& engine) {
|
||||
<< "attribute " << j << " offset=" << attributes[j].offset
|
||||
<< " is not multiple of 4";
|
||||
|
||||
FILAMENT_CHECK_PRECONDITION((attributes[j].stride & 0x3u) == 0)
|
||||
<< "attribute " << j << " stride=" << attributes[j].stride
|
||||
<< " is not multiple of 4";
|
||||
FEngine* fengine = static_cast<FEngine*>(&engine);
|
||||
if (fengine->features.engine.debug.assert_vertex_buffer_attribute_stride_mult_of_4) {
|
||||
FILAMENT_CHECK_PRECONDITION((attributes[j].stride & 0x3u) == 0)
|
||||
<< "attribute " << j << " stride=" << attributes[j].stride
|
||||
<< " is not multiple of 4";
|
||||
} else if ((attributes[j].stride & 0x3u) != 0) {
|
||||
LOG(WARNING) << "attribute " << j << " stride=" << attributes[j].stride
|
||||
<< " is not multiple of 4";
|
||||
}
|
||||
|
||||
if (engine.getActiveFeatureLevel() == FeatureLevel::FEATURE_LEVEL_0) {
|
||||
FILAMENT_CHECK_PRECONDITION(!(attributes[j].flags & Attribute::FLAG_INTEGER_TARGET))
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "TangentsJob.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
||||
#include <geometry/SurfaceOrientation.h>
|
||||
|
||||
Reference in New Issue
Block a user