Compare commits
8 Commits
ebridgewat
...
pf/test-ex
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8f088140c | ||
|
|
1c72d108fb | ||
|
|
9d18cc35e0 | ||
|
|
2e37ebe70c | ||
|
|
63ef412be1 | ||
|
|
f0996296c1 | ||
|
|
a60d570b3b | ||
|
|
3fdb9f311a |
34
.github/workflows/presubmit.yml
vendored
34
.github/workflows/presubmit.yml
vendored
@@ -19,6 +19,8 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
|
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
|
||||||
@@ -44,6 +46,8 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- uses: actions/setup-java@v3
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
@@ -60,6 +64,8 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4.1.6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Run build script
|
- name: Run build script
|
||||||
run: |
|
run: |
|
||||||
cd build/ios && printf "y" | ./build.sh presubmit
|
cd build/ios && printf "y" | ./build.sh presubmit
|
||||||
@@ -122,3 +128,31 @@ jobs:
|
|||||||
run: source ./build/linux/ci-common.sh && ./build.sh -W debug test_filamat filament
|
run: source ./build/linux/ci-common.sh && ./build.sh -W debug test_filamat filament
|
||||||
- name: Run test
|
- name: Run test
|
||||||
run: ./out/cmake-debug/libs/filamat/test_filamat --gtest_filter=MaterialCompiler.Wgsl*
|
run: ./out/cmake-debug/libs/filamat/test_filamat --gtest_filter=MaterialCompiler.Wgsl*
|
||||||
|
|
||||||
|
code-correcteness:
|
||||||
|
name: code-correctness
|
||||||
|
runs-on: 'macos-14-xlarge'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4.1.6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Set up Homebrew
|
||||||
|
id: set-up-homebrew
|
||||||
|
uses: Homebrew/actions/setup-homebrew@master
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- name: Install prerequisites
|
||||||
|
run: |
|
||||||
|
pip install pyyaml
|
||||||
|
brew install llvm
|
||||||
|
sudo ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
|
||||||
|
- name: Run build script
|
||||||
|
# We need to build before clang-tidy can run analysis
|
||||||
|
run: |
|
||||||
|
# This will build for all three desktop backends on mac
|
||||||
|
./build.sh -p desktop debug gltf_viewer
|
||||||
|
- name: Run test
|
||||||
|
run: |
|
||||||
|
bash test/code-correctness/test.sh
|
||||||
|
|||||||
@@ -142,6 +142,12 @@ abstract class MaterialCompiler extends TaskWithBinary {
|
|||||||
if (!exclude_vulkan) {
|
if (!exclude_vulkan) {
|
||||||
matcArgs += ['-a', 'vulkan']
|
matcArgs += ['-a', 'vulkan']
|
||||||
}
|
}
|
||||||
|
def include_webgpu = providers
|
||||||
|
.gradleProperty("com.google.android.filament.include-webgpu")
|
||||||
|
.forUseAtConfigurationTime().present
|
||||||
|
if (include_webgpu) {
|
||||||
|
matcArgs += ['-a', 'webgpu', '--variant-filter=skinning,stereo']
|
||||||
|
}
|
||||||
|
|
||||||
def mat_no_opt = providers
|
def mat_no_opt = providers
|
||||||
.gradleProperty("com.google.android.filament.matnopt")
|
.gradleProperty("com.google.android.filament.matnopt")
|
||||||
|
|||||||
@@ -177,29 +177,6 @@ endif()
|
|||||||
if (FILAMENT_SUPPORTS_VULKAN)
|
if (FILAMENT_SUPPORTS_VULKAN)
|
||||||
list(APPEND SRCS
|
list(APPEND SRCS
|
||||||
include/backend/platforms/VulkanPlatform.h
|
include/backend/platforms/VulkanPlatform.h
|
||||||
src/vulkan/VulkanDescriptorSetCache.cpp
|
|
||||||
src/vulkan/VulkanDescriptorSetCache.h
|
|
||||||
src/vulkan/VulkanDescriptorSetLayoutCache.cpp
|
|
||||||
src/vulkan/VulkanDescriptorSetLayoutCache.h
|
|
||||||
src/vulkan/VulkanPipelineLayoutCache.cpp
|
|
||||||
src/vulkan/VulkanPipelineLayoutCache.h
|
|
||||||
src/vulkan/memory/ResourceManager.cpp
|
|
||||||
src/vulkan/memory/ResourceManager.h
|
|
||||||
src/vulkan/memory/ResourcePointer.h
|
|
||||||
src/vulkan/memory/Resource.cpp
|
|
||||||
src/vulkan/memory/Resource.h
|
|
||||||
src/vulkan/platform/VulkanPlatform.cpp
|
|
||||||
src/vulkan/platform/VulkanPlatformSwapChainImpl.cpp
|
|
||||||
src/vulkan/platform/VulkanPlatformSwapChainImpl.h
|
|
||||||
src/vulkan/utils/Conversion.cpp
|
|
||||||
src/vulkan/utils/Conversion.h
|
|
||||||
src/vulkan/utils/Definitions.h
|
|
||||||
src/vulkan/utils/Helper.h
|
|
||||||
src/vulkan/utils/Image.h
|
|
||||||
src/vulkan/utils/Image.cpp
|
|
||||||
src/vulkan/utils/Spirv.h
|
|
||||||
src/vulkan/utils/Spirv.cpp
|
|
||||||
src/vulkan/utils/StaticVector.h
|
|
||||||
src/vulkan/VulkanAsyncHandles.h
|
src/vulkan/VulkanAsyncHandles.h
|
||||||
src/vulkan/VulkanBlitter.cpp
|
src/vulkan/VulkanBlitter.cpp
|
||||||
src/vulkan/VulkanBlitter.h
|
src/vulkan/VulkanBlitter.h
|
||||||
@@ -210,31 +187,56 @@ if (FILAMENT_SUPPORTS_VULKAN)
|
|||||||
src/vulkan/VulkanConstants.h
|
src/vulkan/VulkanConstants.h
|
||||||
src/vulkan/VulkanContext.cpp
|
src/vulkan/VulkanContext.cpp
|
||||||
src/vulkan/VulkanContext.h
|
src/vulkan/VulkanContext.h
|
||||||
|
src/vulkan/VulkanDescriptorSetCache.cpp
|
||||||
|
src/vulkan/VulkanDescriptorSetCache.h
|
||||||
|
src/vulkan/VulkanDescriptorSetLayoutCache.cpp
|
||||||
|
src/vulkan/VulkanDescriptorSetLayoutCache.h
|
||||||
src/vulkan/VulkanDriver.cpp
|
src/vulkan/VulkanDriver.cpp
|
||||||
src/vulkan/VulkanDriver.h
|
src/vulkan/VulkanDriver.h
|
||||||
src/vulkan/VulkanDriverFactory.h
|
src/vulkan/VulkanDriverFactory.h
|
||||||
|
src/vulkan/VulkanExternalImageManager.cpp
|
||||||
|
src/vulkan/VulkanExternalImageManager.h
|
||||||
src/vulkan/VulkanFboCache.cpp
|
src/vulkan/VulkanFboCache.cpp
|
||||||
src/vulkan/VulkanFboCache.h
|
src/vulkan/VulkanFboCache.h
|
||||||
src/vulkan/VulkanHandles.cpp
|
src/vulkan/VulkanHandles.cpp
|
||||||
src/vulkan/VulkanHandles.h
|
src/vulkan/VulkanHandles.h
|
||||||
src/vulkan/VulkanMemory.h
|
|
||||||
src/vulkan/VulkanMemory.cpp
|
src/vulkan/VulkanMemory.cpp
|
||||||
|
src/vulkan/VulkanMemory.h
|
||||||
src/vulkan/VulkanPipelineCache.cpp
|
src/vulkan/VulkanPipelineCache.cpp
|
||||||
src/vulkan/VulkanPipelineCache.h
|
src/vulkan/VulkanPipelineCache.h
|
||||||
|
src/vulkan/VulkanPipelineLayoutCache.cpp
|
||||||
|
src/vulkan/VulkanPipelineLayoutCache.h
|
||||||
src/vulkan/VulkanQueryManager.cpp
|
src/vulkan/VulkanQueryManager.cpp
|
||||||
src/vulkan/VulkanQueryManager.h
|
src/vulkan/VulkanQueryManager.h
|
||||||
|
src/vulkan/VulkanReadPixels.cpp
|
||||||
|
src/vulkan/VulkanReadPixels.h
|
||||||
src/vulkan/VulkanSamplerCache.cpp
|
src/vulkan/VulkanSamplerCache.cpp
|
||||||
src/vulkan/VulkanSamplerCache.h
|
src/vulkan/VulkanSamplerCache.h
|
||||||
src/vulkan/VulkanStagePool.cpp
|
src/vulkan/VulkanStagePool.cpp
|
||||||
src/vulkan/VulkanStagePool.h
|
src/vulkan/VulkanStagePool.h
|
||||||
src/vulkan/VulkanSwapChain.cpp
|
src/vulkan/VulkanSwapChain.cpp
|
||||||
src/vulkan/VulkanSwapChain.h
|
src/vulkan/VulkanSwapChain.h
|
||||||
src/vulkan/VulkanReadPixels.cpp
|
|
||||||
src/vulkan/VulkanReadPixels.h
|
|
||||||
src/vulkan/VulkanTexture.cpp
|
src/vulkan/VulkanTexture.cpp
|
||||||
src/vulkan/VulkanTexture.h
|
src/vulkan/VulkanTexture.h
|
||||||
src/vulkan/VulkanYcbcrConversionCache.cpp
|
src/vulkan/VulkanYcbcrConversionCache.cpp
|
||||||
src/vulkan/VulkanYcbcrConversionCache.h
|
src/vulkan/VulkanYcbcrConversionCache.h
|
||||||
|
src/vulkan/memory/Resource.cpp
|
||||||
|
src/vulkan/memory/Resource.h
|
||||||
|
src/vulkan/memory/ResourceManager.cpp
|
||||||
|
src/vulkan/memory/ResourceManager.h
|
||||||
|
src/vulkan/memory/ResourcePointer.h
|
||||||
|
src/vulkan/platform/VulkanPlatform.cpp
|
||||||
|
src/vulkan/platform/VulkanPlatformSwapChainImpl.cpp
|
||||||
|
src/vulkan/platform/VulkanPlatformSwapChainImpl.h
|
||||||
|
src/vulkan/utils/Conversion.cpp
|
||||||
|
src/vulkan/utils/Conversion.h
|
||||||
|
src/vulkan/utils/Definitions.h
|
||||||
|
src/vulkan/utils/Helper.h
|
||||||
|
src/vulkan/utils/Image.cpp
|
||||||
|
src/vulkan/utils/Image.h
|
||||||
|
src/vulkan/utils/Spirv.cpp
|
||||||
|
src/vulkan/utils/Spirv.h
|
||||||
|
src/vulkan/utils/StaticVector.h
|
||||||
)
|
)
|
||||||
if (LINUX OR WIN32)
|
if (LINUX OR WIN32)
|
||||||
list(APPEND SRCS src/vulkan/platform/VulkanPlatformLinuxWindows.cpp)
|
list(APPEND SRCS src/vulkan/platform/VulkanPlatformLinuxWindows.cpp)
|
||||||
@@ -506,6 +508,7 @@ if (APPLE OR LINUX)
|
|||||||
test/ImageExpectations.cpp
|
test/ImageExpectations.cpp
|
||||||
test/Lifetimes.cpp
|
test/Lifetimes.cpp
|
||||||
test/Shader.cpp
|
test/Shader.cpp
|
||||||
|
test/SharedShaders.cpp
|
||||||
test/test_FeedbackLoops.cpp
|
test/test_FeedbackLoops.cpp
|
||||||
test/test_Blit.cpp
|
test/test_Blit.cpp
|
||||||
test/test_MissingRequiredAttributes.cpp
|
test/test_MissingRequiredAttributes.cpp
|
||||||
|
|||||||
@@ -149,6 +149,13 @@ public:
|
|||||||
* - PlatformEGLAndroid
|
* - PlatformEGLAndroid
|
||||||
*/
|
*/
|
||||||
bool assertNativeWindowIsValid = false;
|
bool assertNativeWindowIsValid = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action to take if a Drawable cannot be acquired. If true, the
|
||||||
|
* frame is aborted instead of panic. This is only supported for:
|
||||||
|
* - PlatformMetal
|
||||||
|
*/
|
||||||
|
bool metalDisablePanicOnDrawableFailure = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Platform() noexcept;
|
Platform() noexcept;
|
||||||
|
|||||||
@@ -104,10 +104,6 @@ public:
|
|||||||
|
|
||||||
// Semaphore to be signaled once the image is available.
|
// Semaphore to be signaled once the image is available.
|
||||||
VkSemaphore imageReadySemaphore = VK_NULL_HANDLE;
|
VkSemaphore imageReadySemaphore = VK_NULL_HANDLE;
|
||||||
|
|
||||||
// A function called right before vkQueueSubmit. After this call, the image must be
|
|
||||||
// available. This pointer can be null if imageReadySemaphore is not VK_NULL_HANDLE.
|
|
||||||
std::function<void(SwapChainPtr handle)> explicitImageReadyWait = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VulkanPlatform();
|
VulkanPlatform();
|
||||||
@@ -298,6 +294,16 @@ public:
|
|||||||
VkQueue getProtectedGraphicsQueue() const noexcept;
|
VkQueue getProtectedGraphicsQueue() const noexcept;
|
||||||
|
|
||||||
struct ExternalImageMetadata {
|
struct ExternalImageMetadata {
|
||||||
|
/**
|
||||||
|
* The Filament texture format.
|
||||||
|
*/
|
||||||
|
TextureFormat filamentFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Filament texture usage.
|
||||||
|
*/
|
||||||
|
TextureUsage filamentUsage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the external image
|
* The width of the external image
|
||||||
*/
|
*/
|
||||||
@@ -308,11 +314,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
|
||||||
/**
|
|
||||||
* The layerCount of the external image
|
|
||||||
*/
|
|
||||||
uint32_t layerCount;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The layer count of the external image
|
* The layer count of the external image
|
||||||
*/
|
*/
|
||||||
@@ -328,11 +329,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
VkFormat format;
|
VkFormat format;
|
||||||
|
|
||||||
/**
|
|
||||||
* An external buffer can be protected. This tells you if it is.
|
|
||||||
*/
|
|
||||||
bool isProtected;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of external format (opaque int) if used.
|
* The type of external format (opaque int) if used.
|
||||||
*/
|
*/
|
||||||
@@ -352,20 +348,44 @@ public:
|
|||||||
* Heap information
|
* Heap information
|
||||||
*/
|
*/
|
||||||
uint32_t memoryTypeBits;
|
uint32_t memoryTypeBits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ycbcr conversion components
|
||||||
|
*/
|
||||||
|
VkComponentMapping ycbcrConversionComponents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ycbcr model
|
||||||
|
*/
|
||||||
|
VkSamplerYcbcrModelConversion ycbcrModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ycbcr range
|
||||||
|
*/
|
||||||
|
VkSamplerYcbcrRange ycbcrRange;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ycbcr x chroma offset
|
||||||
|
*/
|
||||||
|
VkChromaLocation xChromaOffset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ycbcr y chroma offset
|
||||||
|
*/
|
||||||
|
VkChromaLocation yChromaOffset;
|
||||||
};
|
};
|
||||||
virtual ExternalImageMetadata getExternalImageMetadata(ExternalImageHandleRef externalImage);
|
|
||||||
|
|
||||||
|
// Note that the image metadata might change per-frame, hence we need a method for extracting
|
||||||
|
// it.
|
||||||
|
virtual ExternalImageMetadata extractExternalImageMetadata(ExternalImageHandleRef image) const {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
using ImageData = std::pair<VkImage, VkDeviceMemory>;
|
using ImageData = std::pair<VkImage, VkDeviceMemory>;
|
||||||
virtual ImageData createExternalImageData(ExternalImageHandleRef externalImage,
|
virtual ImageData createVkImageFromExternal(ExternalImageHandleRef image) const {
|
||||||
const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex,
|
return { VK_NULL_HANDLE, VK_NULL_HANDLE };
|
||||||
VkImageUsageFlags usage);
|
}
|
||||||
|
|
||||||
virtual VkSampler createExternalSampler(SamplerYcbcrConversion chroma,
|
|
||||||
SamplerParams sampler, uint32_t internalFormat);
|
|
||||||
|
|
||||||
virtual VkImageView createExternalImageView(SamplerYcbcrConversion chroma,
|
|
||||||
uint32_t internalFormat, VkImage image, VkImageSubresourceRange range,
|
|
||||||
VkImageViewType viewType, VkComponentMapping swizzle);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ExtensionSet getSwapchainInstanceExtensions() const;
|
virtual ExtensionSet getSwapchainInstanceExtensions() const;
|
||||||
@@ -378,20 +398,6 @@ private:
|
|||||||
// Platform dependent helper methods
|
// Platform dependent helper methods
|
||||||
static ExtensionSet getSwapchainInstanceExtensionsImpl();
|
static ExtensionSet getSwapchainInstanceExtensionsImpl();
|
||||||
|
|
||||||
static ExternalImageMetadata getExternalImageMetadataImpl(ExternalImageHandleRef externalImage,
|
|
||||||
VkDevice device);
|
|
||||||
|
|
||||||
static ImageData createExternalImageDataImpl(ExternalImageHandleRef externalImage,
|
|
||||||
VkDevice device, const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex,
|
|
||||||
VkImageUsageFlags usage);
|
|
||||||
static VkSampler createExternalSamplerImpl(VkDevice device,
|
|
||||||
SamplerYcbcrConversion chroma, SamplerParams sampler,
|
|
||||||
uint32_t internalFormat);
|
|
||||||
static VkImageView createExternalImageViewImpl(VkDevice device,
|
|
||||||
SamplerYcbcrConversion chroma, uint32_t internalFormat, VkImage image,
|
|
||||||
VkImageSubresourceRange range, VkImageViewType viewType,
|
|
||||||
VkComponentMapping swizzle);
|
|
||||||
|
|
||||||
// Platform dependent helper methods
|
// Platform dependent helper methods
|
||||||
static SurfaceBundle createVkSurfaceKHRImpl(void* nativeWindow, VkInstance instance,
|
static SurfaceBundle createVkSurfaceKHRImpl(void* nativeWindow, VkInstance instance,
|
||||||
uint64_t flags) noexcept;
|
uint64_t flags) noexcept;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace filament::backend {
|
|||||||
|
|
||||||
class VulkanPlatformAndroid : public VulkanPlatform {
|
class VulkanPlatformAndroid : public VulkanPlatform {
|
||||||
public:
|
public:
|
||||||
Platform::ExternalImageHandle UTILS_PUBLIC createExternalImage(AHardwareBuffer const* buffer,
|
ExternalImageHandle UTILS_PUBLIC createExternalImage(AHardwareBuffer const* buffer,
|
||||||
bool sRGB) noexcept;
|
bool sRGB) noexcept;
|
||||||
|
|
||||||
struct UTILS_PUBLIC ExternalImageDescAndroid {
|
struct UTILS_PUBLIC ExternalImageDescAndroid {
|
||||||
@@ -39,31 +39,26 @@ public:
|
|||||||
ExternalImageDescAndroid UTILS_PUBLIC getExternalImageDesc(
|
ExternalImageDescAndroid UTILS_PUBLIC getExternalImageDesc(
|
||||||
ExternalImageHandleRef externalImage) const noexcept;
|
ExternalImageHandleRef externalImage) const noexcept;
|
||||||
|
|
||||||
|
virtual ExternalImageMetadata extractExternalImageMetadata(
|
||||||
|
ExternalImageHandleRef image) const override;
|
||||||
|
|
||||||
|
virtual ImageData createVkImageFromExternal(ExternalImageHandleRef image) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual ExtensionSet getSwapchainInstanceExtensions() const override;
|
||||||
|
|
||||||
|
using SurfaceBundle = VulkanPlatform::SurfaceBundle;
|
||||||
|
virtual SurfaceBundle createVkSurfaceKHR(void* nativeWindow, VkInstance instance,
|
||||||
|
uint64_t flags) const noexcept override;
|
||||||
|
|
||||||
|
private:
|
||||||
struct ExternalImageVulkanAndroid : public Platform::ExternalImage {
|
struct ExternalImageVulkanAndroid : public Platform::ExternalImage {
|
||||||
AHardwareBuffer* aHardwareBuffer = nullptr;
|
AHardwareBuffer* aHardwareBuffer = nullptr;
|
||||||
bool sRGB = false;
|
bool sRGB = false;
|
||||||
unsigned int width; // Texture width
|
|
||||||
unsigned int height; // Texture height
|
|
||||||
TextureFormat format;// Texture format
|
|
||||||
TextureUsage usage; // Texture usage flags
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~ExternalImageVulkanAndroid() override;
|
~ExternalImageVulkanAndroid() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ExternalImageMetadata getExternalImageMetadata(ExternalImageHandleRef externalImage);
|
|
||||||
|
|
||||||
using ImageData = VulkanPlatform::ImageData;
|
|
||||||
virtual ImageData createExternalImageData(ExternalImageHandleRef externalImage,
|
|
||||||
const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex,
|
|
||||||
VkImageUsageFlags usage);
|
|
||||||
|
|
||||||
virtual ExtensionSet getSwapchainInstanceExtensions() const;
|
|
||||||
|
|
||||||
using SurfaceBundle = VulkanPlatform::SurfaceBundle;
|
|
||||||
virtual SurfaceBundle createVkSurfaceKHR(void* nativeWindow, VkInstance instance,
|
|
||||||
uint64_t flags) const noexcept;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace filament::backend
|
}// namespace filament::backend
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ PlatformMetal::~PlatformMetal() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Driver* PlatformMetal::createDriver(void* /*sharedContext*/, const Platform::DriverConfig& driverConfig) noexcept {
|
Driver* PlatformMetal::createDriver(void* /*sharedContext*/, const Platform::DriverConfig& driverConfig) noexcept {
|
||||||
|
pImpl->mDrawableFailureBehavior = driverConfig.metalDisablePanicOnDrawableFailure
|
||||||
|
? DrawableFailureBehavior::ABORT_FRAME
|
||||||
|
: DrawableFailureBehavior::PANIC;
|
||||||
return MetalDriverFactory::create(this, driverConfig);
|
return MetalDriverFactory::create(this, driverConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#define FVK_DEBUG_FLAGS (FVK_DEBUG_PERFORMANCE | FVK_DEBUG_FORWARDED_FLAG)
|
#define FVK_DEBUG_FLAGS (FVK_DEBUG_PERFORMANCE | FVK_DEBUG_FORWARDED_FLAG | FVK_DEBUG_VALIDATION)
|
||||||
#else
|
#else
|
||||||
#define FVK_DEBUG_FLAGS 0
|
#define FVK_DEBUG_FLAGS 0
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -70,13 +70,11 @@ struct VulkanRenderPass {
|
|||||||
// context are stored in VulkanPlatform.
|
// context are stored in VulkanPlatform.
|
||||||
struct VulkanContext {
|
struct VulkanContext {
|
||||||
public:
|
public:
|
||||||
inline uint32_t selectMemoryType(uint32_t flags, VkFlags reqs) const {
|
static uint32_t selectMemoryType(VkPhysicalDeviceMemoryProperties const& memoryProperties,
|
||||||
if ((reqs & VK_MEMORY_PROPERTY_PROTECTED_BIT) != 0) {
|
uint32_t flags, VkFlags reqs) {
|
||||||
assert_invariant(isProtectedMemorySupported() == true);
|
|
||||||
}
|
|
||||||
for (uint32_t i = 0; i < VK_MAX_MEMORY_TYPES; i++) {
|
for (uint32_t i = 0; i < VK_MAX_MEMORY_TYPES; i++) {
|
||||||
if (flags & 1) {
|
if (flags & 1) {
|
||||||
if ((mMemoryProperties.memoryTypes[i].propertyFlags & reqs) == reqs) {
|
if ((memoryProperties.memoryTypes[i].propertyFlags & reqs) == reqs) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +83,13 @@ public:
|
|||||||
return (uint32_t) VK_MAX_MEMORY_TYPES;
|
return (uint32_t) VK_MAX_MEMORY_TYPES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint32_t selectMemoryType(uint32_t flags, VkFlags reqs) const {
|
||||||
|
if ((reqs & VK_MEMORY_PROPERTY_PROTECTED_BIT) != 0) {
|
||||||
|
assert_invariant(isProtectedMemorySupported());
|
||||||
|
}
|
||||||
|
return selectMemoryType(mMemoryProperties, flags, reqs);
|
||||||
|
}
|
||||||
|
|
||||||
inline fvkutils::VkFormatList const& getAttachmentDepthStencilFormats() const {
|
inline fvkutils::VkFormatList const& getAttachmentDepthStencilFormats() const {
|
||||||
return mDepthStencilFormats;
|
return mDepthStencilFormats;
|
||||||
}
|
}
|
||||||
@@ -118,7 +123,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool isMultiviewEnabled() const noexcept {
|
inline bool isMultiviewEnabled() const noexcept {
|
||||||
return mMultiviewEnabled;
|
return mPhysicalDeviceVk11Features.multiview == VK_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool isClipDistanceSupported() const noexcept {
|
inline bool isClipDistanceSupported() const noexcept {
|
||||||
@@ -142,6 +147,9 @@ private:
|
|||||||
VkPhysicalDeviceProperties2 mPhysicalDeviceProperties = {
|
VkPhysicalDeviceProperties2 mPhysicalDeviceProperties = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
|
||||||
};
|
};
|
||||||
|
VkPhysicalDeviceVulkan11Features mPhysicalDeviceVk11Features = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES,
|
||||||
|
};
|
||||||
VkPhysicalDeviceFeatures2 mPhysicalDeviceFeatures = {
|
VkPhysicalDeviceFeatures2 mPhysicalDeviceFeatures = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
||||||
};
|
};
|
||||||
@@ -154,7 +162,6 @@ private:
|
|||||||
};
|
};
|
||||||
bool mDebugMarkersSupported = false;
|
bool mDebugMarkersSupported = false;
|
||||||
bool mDebugUtilsSupported = false;
|
bool mDebugUtilsSupported = false;
|
||||||
bool mMultiviewEnabled = false;
|
|
||||||
bool mLazilyAllocatedMemorySupported = false;
|
bool mLazilyAllocatedMemorySupported = false;
|
||||||
bool mProtectedMemorySupported = false;
|
bool mProtectedMemorySupported = false;
|
||||||
|
|
||||||
|
|||||||
@@ -282,18 +282,25 @@ void VulkanDescriptorSetCache::commit(VulkanCommandBuffer* commands,
|
|||||||
fvkutils::DescriptorSetMask curMask = setMask;
|
fvkutils::DescriptorSetMask curMask = setMask;
|
||||||
|
|
||||||
auto& updateSets = mStashedSets;
|
auto& updateSets = mStashedSets;
|
||||||
auto& lastBoundSets = mLastBoundInfo.boundSets;
|
bool const pipelineLayoutIsSame = mLastBoundInfo.pipelineLayout == pipelineLayout;
|
||||||
|
|
||||||
setMask.forEachSetBit([&](size_t index) {
|
if (pipelineLayoutIsSame) {
|
||||||
if (!updateSets[index] || updateSets[index] == lastBoundSets[index]) {
|
auto& lastBoundSets = mLastBoundInfo.boundSets;
|
||||||
curMask.unset(index);
|
setMask.forEachSetBit([&](size_t index) {
|
||||||
|
if (!updateSets[index] || updateSets[index] == lastBoundSets[index]) {
|
||||||
|
curMask.unset(index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (curMask.none() &&
|
||||||
|
mLastBoundInfo.setMask == setMask && mLastBoundInfo.boundSets == updateSets) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
setMask.forEachSetBit([&](size_t index) {
|
||||||
if (curMask.none() &&
|
if (!updateSets[index]) {
|
||||||
(mLastBoundInfo.pipelineLayout == pipelineLayout && mLastBoundInfo.setMask == setMask &&
|
curMask.unset(index);
|
||||||
mLastBoundInfo.boundSets == updateSets)) {
|
}
|
||||||
return;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
curMask.forEachSetBit([&updateSets, commands, pipelineLayout](size_t index) {
|
curMask.forEachSetBit([&updateSets, commands, pipelineLayout](size_t index) {
|
||||||
@@ -301,7 +308,7 @@ void VulkanDescriptorSetCache::commit(VulkanCommandBuffer* commands,
|
|||||||
auto set = updateSets[index];
|
auto set = updateSets[index];
|
||||||
VkCommandBuffer const cmdbuffer = commands->buffer();
|
VkCommandBuffer const cmdbuffer = commands->buffer();
|
||||||
vkCmdBindDescriptorSets(cmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, index,
|
vkCmdBindDescriptorSets(cmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, index,
|
||||||
1, &set->vkSet, set->uniqueDynamicUboCount, set->getOffsets()->data());
|
1, &set->getVkSet(), set->uniqueDynamicUboCount, set->getOffsets()->data());
|
||||||
commands->acquire(set);
|
commands->acquire(set);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -329,7 +336,7 @@ void VulkanDescriptorSetCache::updateBuffer(fvkmemory::resource_ptr<VulkanDescri
|
|||||||
}
|
}
|
||||||
VkWriteDescriptorSet const descriptorWrite = {
|
VkWriteDescriptorSet const descriptorWrite = {
|
||||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||||
.dstSet = set->vkSet,
|
.dstSet = set->getVkSet(),
|
||||||
.dstBinding = binding,
|
.dstBinding = binding,
|
||||||
.descriptorCount = 1,
|
.descriptorCount = 1,
|
||||||
.descriptorType = type,
|
.descriptorType = type,
|
||||||
@@ -342,10 +349,6 @@ void VulkanDescriptorSetCache::updateBuffer(fvkmemory::resource_ptr<VulkanDescri
|
|||||||
void VulkanDescriptorSetCache::updateSampler(fvkmemory::resource_ptr<VulkanDescriptorSet> set,
|
void VulkanDescriptorSetCache::updateSampler(fvkmemory::resource_ptr<VulkanDescriptorSet> set,
|
||||||
uint8_t binding, fvkmemory::resource_ptr<VulkanTexture> texture,
|
uint8_t binding, fvkmemory::resource_ptr<VulkanTexture> texture,
|
||||||
VkSampler sampler) noexcept {
|
VkSampler sampler) noexcept {
|
||||||
VkDescriptorImageInfo info{
|
|
||||||
.sampler = sampler,
|
|
||||||
.imageLayout = fvkutils::getVkLayout(texture->getDefaultLayout()),
|
|
||||||
};
|
|
||||||
VkImageSubresourceRange range = texture->getPrimaryViewRange();
|
VkImageSubresourceRange range = texture->getPrimaryViewRange();
|
||||||
VkImageViewType const expectedType = texture->getViewType();
|
VkImageViewType const expectedType = texture->getViewType();
|
||||||
if (any(texture->usage & TextureUsage::DEPTH_ATTACHMENT) &&
|
if (any(texture->usage & TextureUsage::DEPTH_ATTACHMENT) &&
|
||||||
@@ -355,12 +358,16 @@ void VulkanDescriptorSetCache::updateSampler(fvkmemory::resource_ptr<VulkanDescr
|
|||||||
range.levelCount = 1;
|
range.levelCount = 1;
|
||||||
range.layerCount = 1;
|
range.layerCount = 1;
|
||||||
}
|
}
|
||||||
info.imageView = texture->getView(range);
|
VkDescriptorImageInfo info{
|
||||||
|
.sampler = sampler,
|
||||||
|
.imageView = texture->getView(range),
|
||||||
|
.imageLayout = fvkutils::getVkLayout(texture->getDefaultLayout()),
|
||||||
|
};
|
||||||
|
|
||||||
VkWriteDescriptorSet const descriptorWrite = {
|
VkWriteDescriptorSet const descriptorWrite = {
|
||||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.dstSet = set->vkSet,
|
.dstSet = set->getVkSet(),
|
||||||
.dstBinding = binding,
|
.dstBinding = binding,
|
||||||
.descriptorCount = 1,
|
.descriptorCount = 1,
|
||||||
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
@@ -378,10 +385,10 @@ void VulkanDescriptorSetCache::updateInputAttachment(
|
|||||||
|
|
||||||
fvkmemory::resource_ptr<VulkanDescriptorSet> VulkanDescriptorSetCache::createSet(
|
fvkmemory::resource_ptr<VulkanDescriptorSet> VulkanDescriptorSetCache::createSet(
|
||||||
Handle<HwDescriptorSet> handle, fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout) {
|
Handle<HwDescriptorSet> handle, fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout) {
|
||||||
auto const vkSet = mDescriptorPool->obtainSet(layout);
|
auto const vkSet = getVkSet(layout);
|
||||||
auto const& count = layout->count;
|
auto const& count = layout->count;
|
||||||
auto const vklayout = layout->getVkLayout();
|
auto const vklayout = layout->getVkLayout();
|
||||||
return fvkmemory::resource_ptr<VulkanDescriptorSet>::make(mResourceManager, handle, vkSet,
|
auto set = fvkmemory::resource_ptr<VulkanDescriptorSet>::make(mResourceManager, handle,
|
||||||
layout->bitmask.dynamicUbo, layout->count.dynamicUbo,
|
layout->bitmask.dynamicUbo, layout->count.dynamicUbo,
|
||||||
[vkSet, count, vklayout, this](VulkanDescriptorSet*) {
|
[vkSet, count, vklayout, this](VulkanDescriptorSet*) {
|
||||||
// Note that mDescriptorPool could be gone due to terminate (when the backend shuts
|
// Note that mDescriptorPool could be gone due to terminate (when the backend shuts
|
||||||
@@ -390,10 +397,20 @@ fvkmemory::resource_ptr<VulkanDescriptorSet> VulkanDescriptorSetCache::createSet
|
|||||||
mDescriptorPool->recycle(count, vklayout, vkSet);
|
mDescriptorPool->recycle(count, vklayout, vkSet);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
set->setVkSet(vkSet);
|
||||||
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanDescriptorSetCache::gc() {
|
VkDescriptorSet VulkanDescriptorSetCache::getVkSet(
|
||||||
mStashedSets = {};
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout) {
|
||||||
|
return mDescriptorPool->obtainSet(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanDescriptorSetCache::manualRecyle(VulkanDescriptorSetLayout::Count const& count,
|
||||||
|
VkDescriptorSetLayout vklayout, VkDescriptorSet vkSet) {
|
||||||
|
mDescriptorPool->recycle(count, vklayout, vkSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanDescriptorSetCache::gc() { mStashedSets = {}; }
|
||||||
|
|
||||||
} // namespace filament::backend
|
} // namespace filament::backend
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ public:
|
|||||||
VulkanDescriptorSetLayout::UNIQUE_DESCRIPTOR_SET_COUNT;
|
VulkanDescriptorSetLayout::UNIQUE_DESCRIPTOR_SET_COUNT;
|
||||||
|
|
||||||
using DescriptorSetLayoutArray = VulkanDescriptorSetLayout::DescriptorSetLayoutArray;
|
using DescriptorSetLayoutArray = VulkanDescriptorSetLayout::DescriptorSetLayoutArray;
|
||||||
|
using DescriptorSetArray =
|
||||||
|
std::array<fvkmemory::resource_ptr<VulkanDescriptorSet>, UNIQUE_DESCRIPTOR_SET_COUNT>;
|
||||||
|
|
||||||
VulkanDescriptorSetCache(VkDevice device, fvkmemory::ResourceManager* resourceManager);
|
VulkanDescriptorSetCache(VkDevice device, fvkmemory::ResourceManager* resourceManager);
|
||||||
~VulkanDescriptorSetCache();
|
~VulkanDescriptorSetCache();
|
||||||
@@ -68,14 +70,21 @@ public:
|
|||||||
fvkmemory::resource_ptr<VulkanDescriptorSet> createSet(Handle<HwDescriptorSet> handle,
|
fvkmemory::resource_ptr<VulkanDescriptorSet> createSet(Handle<HwDescriptorSet> handle,
|
||||||
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout);
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout);
|
||||||
|
|
||||||
|
// This method is only meant to be used with external samplers (or internally within this
|
||||||
|
// class).
|
||||||
|
VkDescriptorSet getVkSet(fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout);
|
||||||
|
|
||||||
|
// This method is only meant to be used with external samplers.
|
||||||
|
void manualRecyle(VulkanDescriptorSetLayout::Count const& count, VkDescriptorSetLayout vklayout,
|
||||||
|
VkDescriptorSet vkSet);
|
||||||
|
|
||||||
|
DescriptorSetArray const& getBoundSets() const { return mStashedSets; }
|
||||||
|
|
||||||
void gc();
|
void gc();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class DescriptorInfinitePool;
|
class DescriptorInfinitePool;
|
||||||
|
|
||||||
using DescriptorSetArray =
|
|
||||||
std::array<fvkmemory::resource_ptr<VulkanDescriptorSet>, UNIQUE_DESCRIPTOR_SET_COUNT>;
|
|
||||||
|
|
||||||
VkDevice mDevice;
|
VkDevice mDevice;
|
||||||
fvkmemory::ResourceManager* mResourceManager;
|
fvkmemory::ResourceManager* mResourceManager;
|
||||||
std::unique_ptr<DescriptorInfinitePool> mDescriptorPool;
|
std::unique_ptr<DescriptorInfinitePool> mDescriptorPool;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include "VulkanHandles.h"
|
#include "VulkanHandles.h"
|
||||||
|
|
||||||
|
#include <utils/Hash.h>
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -58,6 +60,56 @@ uint32_t appendBindings(VkDescriptorSetLayoutBinding* toBind, VkDescriptorType t
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t appendSamplerBindings(VkDescriptorSetLayoutBinding* toBind,
|
||||||
|
fvkutils::SamplerBitmask const& mask, fvkutils::SamplerBitmask const& external,
|
||||||
|
utils::FixedCapacityVector<VkSampler> const& immutableSamplers) {
|
||||||
|
using Bitmask = fvkutils::SamplerBitmask;
|
||||||
|
uint32_t count = 0;
|
||||||
|
Bitmask alreadySeen;
|
||||||
|
uint8_t immutableIndex = 0;
|
||||||
|
size_t const immutableSamplerCount = immutableSamplers.size();
|
||||||
|
mask.forEachSetBit([&](size_t index) {
|
||||||
|
VkShaderStageFlags stages = 0;
|
||||||
|
uint32_t binding = 0;
|
||||||
|
if (index < fvkutils::getFragmentStageShift<Bitmask>()) {
|
||||||
|
binding = (uint32_t) index;
|
||||||
|
stages |= VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
|
auto fragIndex = index + fvkutils::getFragmentStageShift<Bitmask>();
|
||||||
|
if (mask.test(fragIndex)) {
|
||||||
|
stages |= VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
alreadySeen.set(fragIndex);
|
||||||
|
}
|
||||||
|
} else if (!alreadySeen.test(index)) {
|
||||||
|
// We are in fragment stage bits
|
||||||
|
binding = (uint32_t) (index - fvkutils::getFragmentStageShift<Bitmask>());
|
||||||
|
stages |= VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stages) {
|
||||||
|
toBind[count++] = {
|
||||||
|
.binding = binding,
|
||||||
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.stageFlags = stages,
|
||||||
|
.pImmutableSamplers = external[index] && immutableSamplerCount > immutableIndex
|
||||||
|
? &immutableSamplers[immutableIndex++]
|
||||||
|
: nullptr,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t computeImmutableSamplerHash(utils::FixedCapacityVector<VkSampler> const& samplers) {
|
||||||
|
size_t const size = samplers.size();
|
||||||
|
if (size == 0) {
|
||||||
|
return 0;
|
||||||
|
} else if (size == 1) {
|
||||||
|
return (uint64_t) samplers[0];
|
||||||
|
}
|
||||||
|
return utils::hash::murmur3((uint32_t*) samplers.data(), samplers.size() * 2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
VulkanDescriptorSetLayoutCache::VulkanDescriptorSetLayoutCache(VkDevice device,
|
VulkanDescriptorSetLayoutCache::VulkanDescriptorSetLayoutCache(VkDevice device,
|
||||||
@@ -73,37 +125,44 @@ void VulkanDescriptorSetLayoutCache::terminate() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkDescriptorSetLayout VulkanDescriptorSetLayoutCache::getVkLayout(
|
||||||
|
VulkanDescriptorSetLayout::Bitmask const& bitmasks,
|
||||||
|
utils::FixedCapacityVector<VkSampler> immutableSamplers) {
|
||||||
|
LayoutKey key = {
|
||||||
|
.bitmask = bitmasks,
|
||||||
|
.immutableSamplerHash = computeImmutableSamplerHash(immutableSamplers),
|
||||||
|
};
|
||||||
|
if (auto itr = mVkLayouts.find(key); itr != mVkLayouts.end()) {
|
||||||
|
return itr->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkDescriptorSetLayoutBinding toBind[VulkanDescriptorSetLayout::MAX_BINDINGS];
|
||||||
|
uint32_t count = 0;
|
||||||
|
count += appendBindings(&toBind[count], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
|
||||||
|
bitmasks.dynamicUbo);
|
||||||
|
count += appendBindings(&toBind[count], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, bitmasks.ubo);
|
||||||
|
count += appendSamplerBindings(&toBind[count], bitmasks.sampler, bitmasks.externalSampler,
|
||||||
|
immutableSamplers);
|
||||||
|
count += appendBindings(&toBind[count], VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
|
||||||
|
bitmasks.inputAttachment);
|
||||||
|
|
||||||
|
assert_invariant(count != 0 && "Need at least one binding for descriptor set layout.");
|
||||||
|
VkDescriptorSetLayoutCreateInfo dlinfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||||
|
.bindingCount = count,
|
||||||
|
.pBindings = toBind,
|
||||||
|
};
|
||||||
|
VkDescriptorSetLayout vklayout;
|
||||||
|
vkCreateDescriptorSetLayout(mDevice, &dlinfo, VKALLOC, &vklayout);
|
||||||
|
mVkLayouts[key] = vklayout;
|
||||||
|
return vklayout;
|
||||||
|
}
|
||||||
|
|
||||||
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> VulkanDescriptorSetLayoutCache::createLayout(
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> VulkanDescriptorSetLayoutCache::createLayout(
|
||||||
Handle<HwDescriptorSetLayout> handle, backend::DescriptorSetLayout&& info) {
|
Handle<HwDescriptorSetLayout> handle, backend::DescriptorSetLayout&& info) {
|
||||||
auto layout = fvkmemory::resource_ptr<VulkanDescriptorSetLayout>::make(mResourceManager, handle,
|
auto layout = fvkmemory::resource_ptr<VulkanDescriptorSetLayout>::make(mResourceManager, handle,
|
||||||
info);
|
info);
|
||||||
VkDescriptorSetLayout vklayout = VK_NULL_HANDLE;
|
layout->setVkLayout(getVkLayout(layout->bitmask));
|
||||||
auto const& bitmasks = layout->bitmask;
|
|
||||||
if (auto itr = mVkLayouts.find(bitmasks); itr != mVkLayouts.end()) {
|
|
||||||
vklayout = itr->second;
|
|
||||||
} else {
|
|
||||||
VkDescriptorSetLayoutBinding toBind[VulkanDescriptorSetLayout::MAX_BINDINGS];
|
|
||||||
uint32_t count = 0;
|
|
||||||
count += appendBindings(&toBind[count], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
|
|
||||||
bitmasks.dynamicUbo);
|
|
||||||
count += appendBindings(&toBind[count], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, bitmasks.ubo);
|
|
||||||
count += appendBindings(&toBind[count], VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
||||||
bitmasks.sampler);
|
|
||||||
count += appendBindings(&toBind[count], VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
|
|
||||||
bitmasks.inputAttachment);
|
|
||||||
|
|
||||||
assert_invariant(count != 0 && "Need at least one binding for descriptor set layout.");
|
|
||||||
VkDescriptorSetLayoutCreateInfo dlinfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.bindingCount = count,
|
|
||||||
.pBindings = toBind,
|
|
||||||
};
|
|
||||||
|
|
||||||
vkCreateDescriptorSetLayout(mDevice, &dlinfo, VKALLOC, &vklayout);
|
|
||||||
mVkLayouts[bitmasks] = vklayout;
|
|
||||||
}
|
|
||||||
layout->setVkLayout(vklayout);
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,12 +26,11 @@
|
|||||||
#include <backend/TargetBufferInfo.h>
|
#include <backend/TargetBufferInfo.h>
|
||||||
|
|
||||||
#include <utils/bitset.h>
|
#include <utils/bitset.h>
|
||||||
|
#include <utils/FixedCapacityVector.h>
|
||||||
|
|
||||||
#include <bluevk/BlueVK.h>
|
#include <bluevk/BlueVK.h>
|
||||||
#include <tsl/robin_map.h>
|
#include <tsl/robin_map.h>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
class VulkanDescriptorSetLayoutCache {
|
class VulkanDescriptorSetLayoutCache {
|
||||||
@@ -41,21 +40,34 @@ public:
|
|||||||
|
|
||||||
void terminate() noexcept;
|
void terminate() noexcept;
|
||||||
|
|
||||||
|
// Just a wrapper around getVkLayout()
|
||||||
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> createLayout(
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> createLayout(
|
||||||
Handle<HwDescriptorSetLayout> handle, backend::DescriptorSetLayout&& info);
|
Handle<HwDescriptorSetLayout> handle, backend::DescriptorSetLayout&& info);
|
||||||
|
|
||||||
|
// This method is meant to be used with external samplers
|
||||||
|
VkDescriptorSetLayout getVkLayout(VulkanDescriptorSetLayout::Bitmask const& bitmasks,
|
||||||
|
utils::FixedCapacityVector<VkSampler> immutableSamplers = {});
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkDevice mDevice;
|
VkDevice mDevice;
|
||||||
fvkmemory::ResourceManager* mResourceManager;
|
fvkmemory::ResourceManager* mResourceManager;
|
||||||
|
|
||||||
using BitmaskGroup = VulkanDescriptorSetLayout::Bitmask;
|
struct LayoutKey {
|
||||||
using BitmaskGroupHashFn = utils::hash::MurmurHashFn<BitmaskGroup>;
|
// this describes the layout using bitset.
|
||||||
struct BitmaskGroupEqual {
|
VulkanDescriptorSetLayout::Bitmask bitmask = {};
|
||||||
bool operator()(BitmaskGroup const& k1, BitmaskGroup const& k2) const { return k1 == k2; }
|
// number of immutable samplers can be arbitrary; so we hash them into 64-bit.
|
||||||
|
uint64_t immutableSamplerHash = 0;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(LayoutKey) == 48);
|
||||||
|
|
||||||
|
using LayoutKeyHashFn = utils::hash::MurmurHashFn<LayoutKey>;
|
||||||
|
struct LayoutKeyEqual {
|
||||||
|
bool operator()(LayoutKey const& k1, LayoutKey const& k2) const {
|
||||||
|
return k1.bitmask == k2.bitmask && k1.immutableSamplerHash == k2.immutableSamplerHash;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tsl::robin_map<BitmaskGroup, VkDescriptorSetLayout, BitmaskGroupHashFn, BitmaskGroupEqual>
|
tsl::robin_map<LayoutKey, VkDescriptorSetLayout, LayoutKeyHashFn, LayoutKeyEqual> mVkLayouts;
|
||||||
mVkLayouts;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace filament::backend
|
} // namespace filament::backend
|
||||||
|
|||||||
@@ -200,9 +200,7 @@ Dispatcher VulkanDriver::getDispatcher() const noexcept {
|
|||||||
VulkanDriver::VulkanDriver(VulkanPlatform* platform, VulkanContext const& context,
|
VulkanDriver::VulkanDriver(VulkanPlatform* platform, VulkanContext const& context,
|
||||||
Platform::DriverConfig const& driverConfig) noexcept
|
Platform::DriverConfig const& driverConfig) noexcept
|
||||||
: mPlatform(platform),
|
: mPlatform(platform),
|
||||||
mResourceManager(
|
mResourceManager(driverConfig.handleArenaSize, driverConfig.disableHandleUseAfterFreeCheck,
|
||||||
driverConfig.handleArenaSize,
|
|
||||||
driverConfig.disableHandleUseAfterFreeCheck,
|
|
||||||
driverConfig.disableHeapHandleTags),
|
driverConfig.disableHeapHandleTags),
|
||||||
mAllocator(createAllocator(mPlatform->getInstance(), mPlatform->getPhysicalDevice(),
|
mAllocator(createAllocator(mPlatform->getInstance(), mPlatform->getPhysicalDevice(),
|
||||||
mPlatform->getDevice())),
|
mPlatform->getDevice())),
|
||||||
@@ -221,6 +219,8 @@ VulkanDriver::VulkanDriver(VulkanPlatform* platform, VulkanContext const& contex
|
|||||||
mDescriptorSetLayoutCache(mPlatform->getDevice(), &mResourceManager),
|
mDescriptorSetLayoutCache(mPlatform->getDevice(), &mResourceManager),
|
||||||
mDescriptorSetCache(mPlatform->getDevice(), &mResourceManager),
|
mDescriptorSetCache(mPlatform->getDevice(), &mResourceManager),
|
||||||
mQueryManager(mPlatform->getDevice()),
|
mQueryManager(mPlatform->getDevice()),
|
||||||
|
mExternalImageManager(platform, &mSamplerCache, &mYcbcrConversionCache, &mDescriptorSetCache,
|
||||||
|
&mDescriptorSetLayoutCache),
|
||||||
mIsSRGBSwapChainSupported(mPlatform->getCustomization().isSRGBSwapChainSupported),
|
mIsSRGBSwapChainSupported(mPlatform->getCustomization().isSRGBSwapChainSupported),
|
||||||
mStereoscopicType(driverConfig.stereoscopicType) {
|
mStereoscopicType(driverConfig.stereoscopicType) {
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ void VulkanDriver::terminate() {
|
|||||||
|
|
||||||
mCurrentSwapChain = {};
|
mCurrentSwapChain = {};
|
||||||
mDefaultRenderTarget = {};
|
mDefaultRenderTarget = {};
|
||||||
mBoundPipeline = {};
|
mPipelineState = {};
|
||||||
|
|
||||||
mQueryManager.terminate();
|
mQueryManager.terminate();
|
||||||
|
|
||||||
@@ -325,6 +325,10 @@ void VulkanDriver::terminate() {
|
|||||||
|
|
||||||
mCommands.terminate();
|
mCommands.terminate();
|
||||||
|
|
||||||
|
// Must come before samplerCache, ycbcrConversionCache, descriptorSetCache,
|
||||||
|
// descriptorSetLayoutCache
|
||||||
|
mExternalImageManager.terminate();
|
||||||
|
|
||||||
mStagePool.terminate();
|
mStagePool.terminate();
|
||||||
mPipelineCache.terminate();
|
mPipelineCache.terminate();
|
||||||
mFramebufferCache.reset();
|
mFramebufferCache.reset();
|
||||||
@@ -381,6 +385,10 @@ void VulkanDriver::beginFrame(int64_t monotonic_clock_ns,
|
|||||||
int64_t refreshIntervalNs, uint32_t frameId) {
|
int64_t refreshIntervalNs, uint32_t frameId) {
|
||||||
FVK_PROFILE_MARKER(PROFILE_NAME_BEGINFRAME);
|
FVK_PROFILE_MARKER(PROFILE_NAME_BEGINFRAME);
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
|
|
||||||
|
if (mAppState.hasExternalSamplers()) {
|
||||||
|
mExternalImageManager.onBeginFrame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanDriver::setFrameScheduledCallback(Handle<HwSwapChain> sch, CallbackHandler* handler,
|
void VulkanDriver::setFrameScheduledCallback(Handle<HwSwapChain> sch, CallbackHandler* handler,
|
||||||
@@ -421,12 +429,16 @@ void VulkanDriver::updateDescriptorSetTexture(
|
|||||||
auto set = resource_ptr<VulkanDescriptorSet>::cast(&mResourceManager, dsh);
|
auto set = resource_ptr<VulkanDescriptorSet>::cast(&mResourceManager, dsh);
|
||||||
auto texture = resource_ptr<VulkanTexture>::cast(&mResourceManager, th);
|
auto texture = resource_ptr<VulkanTexture>::cast(&mResourceManager, th);
|
||||||
|
|
||||||
// TODO: YcbcrConversion?
|
if (mExternalImageManager.isExternallySampledTexture(texture)) {
|
||||||
VulkanSamplerCache::Params cacheParams = {
|
mExternalImageManager.bindExternallySampledTexture(set, binding, texture, params);
|
||||||
.sampler = params,
|
mAppState.hasBoundExternalImages = true;
|
||||||
};
|
} else {
|
||||||
VkSampler const vksampler = mSamplerCache.getSampler(cacheParams);
|
VulkanSamplerCache::Params cacheParams = {
|
||||||
mDescriptorSetCache.updateSampler(set, binding, texture, vksampler);
|
.sampler = params,
|
||||||
|
};
|
||||||
|
VkSampler const vksampler = mSamplerCache.getSampler(cacheParams);
|
||||||
|
mDescriptorSetCache.updateSampler(set, binding, texture, vksampler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanDriver::flush(int) {
|
void VulkanDriver::flush(int) {
|
||||||
@@ -563,41 +575,35 @@ void VulkanDriver::createTextureExternalImage2R(Handle<HwTexture> th, backend::S
|
|||||||
backend::TextureFormat format, uint32_t width, uint32_t height, backend::TextureUsage usage,
|
backend::TextureFormat format, uint32_t width, uint32_t height, backend::TextureUsage usage,
|
||||||
Platform::ExternalImageHandleRef externalImage) {
|
Platform::ExternalImageHandleRef externalImage) {
|
||||||
FVK_SYSTRACE_SCOPE();
|
FVK_SYSTRACE_SCOPE();
|
||||||
auto const& metadata = mPlatform->getExternalImageMetadata(externalImage);
|
auto const& metadata = mPlatform->extractExternalImageMetadata(externalImage);
|
||||||
if (metadata.isProtected) {
|
|
||||||
usage |= backend::TextureUsage::PROTECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImageUsageFlags vkUsage = metadata.usage;
|
// In theory the following are reasonable expectations, but in practice it's hard for client's
|
||||||
if (any(usage & TextureUsage::BLIT_SRC)) {
|
// to match up the dimensions of the texture with that of the AHB.
|
||||||
vkUsage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
// assert_invariant(width == metadata.width);
|
||||||
}
|
// assert_invariant(height == metadata.height);
|
||||||
|
// assert_invariant(format == metadata.filamentFormat);
|
||||||
if (any(usage & (TextureUsage::BLIT_DST | TextureUsage::UPLOADABLE))) {
|
// assert_invariant(fvkutils::getVkFormat(format) == metadata.format);
|
||||||
vkUsage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_invariant(width == metadata.width);
|
|
||||||
assert_invariant(height == metadata.height);
|
|
||||||
assert_invariant(fvkutils::getVkFormat(format) == metadata.format);
|
|
||||||
|
|
||||||
VkMemoryPropertyFlags const requiredMemoryFlags = any(usage & TextureUsage::UPLOADABLE)
|
|
||||||
? VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
|
||||||
: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
||||||
uint32_t const memoryTypeIndex =
|
|
||||||
mContext.selectMemoryType(metadata.memoryTypeBits, requiredMemoryFlags);
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(memoryTypeIndex != VK_MAX_MEMORY_TYPES)
|
|
||||||
<< "failed to find a valid memory type for external image memory.";
|
|
||||||
|
|
||||||
VkImage vkimg;
|
VkImage vkimg;
|
||||||
VkDeviceMemory deviceMemory;
|
VkDeviceMemory deviceMemory;
|
||||||
std::tie(vkimg, deviceMemory) =
|
std::tie(vkimg, deviceMemory) = mPlatform->createVkImageFromExternal(externalImage);
|
||||||
mPlatform->createExternalImageData(externalImage, metadata, memoryTypeIndex, vkUsage);
|
|
||||||
|
VkSamplerYcbcrConversion conversion =
|
||||||
|
mExternalImageManager.getVkSamplerYcbcrConversion(metadata);
|
||||||
|
|
||||||
auto texture = resource_ptr<VulkanTexture>::make(&mResourceManager, th, mContext,
|
auto texture = resource_ptr<VulkanTexture>::make(&mResourceManager, th, mContext,
|
||||||
mPlatform->getDevice(), mAllocator, &mResourceManager, &mCommands, vkimg, deviceMemory,
|
mPlatform->getDevice(), mAllocator, &mResourceManager, &mCommands, vkimg, deviceMemory,
|
||||||
metadata.format, VK_NULL_HANDLE, metadata.samples, metadata.width, metadata.height,
|
metadata.format, conversion, metadata.samples, metadata.width, metadata.height,
|
||||||
metadata.layerCount, usage, mStagePool);
|
metadata.layers, usage, mStagePool);
|
||||||
|
|
||||||
|
if (conversion != VK_NULL_HANDLE) {
|
||||||
|
mExternalImageManager.addExternallySampledTexture(texture, externalImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlike uploaded textures or swapchains, we need to explicit transition this
|
||||||
|
// texture into the read layout.
|
||||||
|
auto& commands = mCommands.get();
|
||||||
|
texture->transitionLayout(&commands, texture->getPrimaryViewRange(), VulkanLayout::READ_ONLY);
|
||||||
|
|
||||||
texture.inc();
|
texture.inc();
|
||||||
}
|
}
|
||||||
@@ -630,6 +636,8 @@ void VulkanDriver::destroyTexture(Handle<HwTexture> th) {
|
|||||||
}
|
}
|
||||||
auto texture = resource_ptr<VulkanTexture>::cast(&mResourceManager, th);
|
auto texture = resource_ptr<VulkanTexture>::cast(&mResourceManager, th);
|
||||||
texture.dec();
|
texture.dec();
|
||||||
|
|
||||||
|
mExternalImageManager.removeExternallySampledTexture(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanDriver::createProgramR(Handle<HwProgram> ph, Program&& program) {
|
void VulkanDriver::createProgramR(Handle<HwProgram> ph, Program&& program) {
|
||||||
@@ -798,6 +806,11 @@ void VulkanDriver::createDescriptorSetR(Handle<HwDescriptorSet> dsh,
|
|||||||
fvkmemory::resource_ptr<VulkanDescriptorSetLayout>::cast(&mResourceManager, dslh);
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout>::cast(&mResourceManager, dslh);
|
||||||
auto set = mDescriptorSetCache.createSet(dsh, layout);
|
auto set = mDescriptorSetCache.createSet(dsh, layout);
|
||||||
set.inc();
|
set.inc();
|
||||||
|
|
||||||
|
if (layout->hasExternalSamplers()) {
|
||||||
|
mAppState.hasExternalSamplerLayouts = true;
|
||||||
|
mExternalImageManager.addDescriptorSet(layout, set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<HwVertexBufferInfo> VulkanDriver::createVertexBufferInfoS() noexcept {
|
Handle<HwVertexBufferInfo> VulkanDriver::createVertexBufferInfoS() noexcept {
|
||||||
@@ -917,11 +930,19 @@ void VulkanDriver::destroyTimerQuery(Handle<HwTimerQuery> tqh) {
|
|||||||
void VulkanDriver::destroyDescriptorSetLayout(Handle<HwDescriptorSetLayout> dslh) {
|
void VulkanDriver::destroyDescriptorSetLayout(Handle<HwDescriptorSetLayout> dslh) {
|
||||||
auto layout = resource_ptr<VulkanDescriptorSetLayout>::cast(&mResourceManager, dslh);
|
auto layout = resource_ptr<VulkanDescriptorSetLayout>::cast(&mResourceManager, dslh);
|
||||||
layout.dec();
|
layout.dec();
|
||||||
|
|
||||||
|
if (layout->hasExternalSamplers()) {
|
||||||
|
mExternalImageManager.removeDescriptorSetLayout(layout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanDriver::destroyDescriptorSet(Handle<HwDescriptorSet> dsh) {
|
void VulkanDriver::destroyDescriptorSet(Handle<HwDescriptorSet> dsh) {
|
||||||
auto set = resource_ptr<VulkanDescriptorSet>::cast(&mResourceManager, dsh);
|
auto set = resource_ptr<VulkanDescriptorSet>::cast(&mResourceManager, dsh);
|
||||||
set.dec();
|
set.dec();
|
||||||
|
|
||||||
|
if (mAppState.hasExternalSamplers()) {
|
||||||
|
mExternalImageManager.removeDescriptorSet(set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<HwStream> VulkanDriver::createStreamNative(void* nativeStream) {
|
Handle<HwStream> VulkanDriver::createStreamNative(void* nativeStream) {
|
||||||
@@ -1482,7 +1503,6 @@ void VulkanDriver::endRenderPass(int) {
|
|||||||
// pipeline barrier between framebuffer writes and shader reads.
|
// pipeline barrier between framebuffer writes and shader reads.
|
||||||
rt->emitBarriersEndRenderPass(*mCurrentRenderPass.commandBuffer);
|
rt->emitBarriersEndRenderPass(*mCurrentRenderPass.commandBuffer);
|
||||||
|
|
||||||
mRenderPassFboInfo = {};
|
|
||||||
mCurrentRenderPass.renderTarget = {};
|
mCurrentRenderPass.renderTarget = {};
|
||||||
mCurrentRenderPass.renderPass = VK_NULL_HANDLE;
|
mCurrentRenderPass.renderPass = VK_NULL_HANDLE;
|
||||||
|
|
||||||
@@ -1542,10 +1562,10 @@ void VulkanDriver::commit(Handle<HwSwapChain> sch) {
|
|||||||
|
|
||||||
void VulkanDriver::setPushConstant(backend::ShaderStage stage, uint8_t index,
|
void VulkanDriver::setPushConstant(backend::ShaderStage stage, uint8_t index,
|
||||||
backend::PushConstantVariant value) {
|
backend::PushConstantVariant value) {
|
||||||
assert_invariant(mBoundPipeline.program && "Expect a program when writing to push constants");
|
assert_invariant(mPipelineState.program && "Expect a program when writing to push constants");
|
||||||
assert_invariant(mCurrentRenderPass.commandBuffer && "Should be called within a renderpass");
|
assert_invariant(mCurrentRenderPass.commandBuffer && "Should be called within a renderpass");
|
||||||
mBoundPipeline.program->writePushConstant(mCurrentRenderPass.commandBuffer->buffer(),
|
mPipelineState.program->writePushConstant(mCurrentRenderPass.commandBuffer->buffer(),
|
||||||
mBoundPipeline.pipelineLayout, stage, index, value);
|
mPipelineState.pipelineLayout, stage, index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanDriver::insertEventMarker(char const* string) {
|
void VulkanDriver::insertEventMarker(char const* string) {
|
||||||
@@ -1724,6 +1744,27 @@ void VulkanDriver::blitDEPRECATED(TargetBufferFlags buffers,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VulkanDriver::bindPipeline(PipelineState const& pipelineState) {
|
void VulkanDriver::bindPipeline(PipelineState const& pipelineState) {
|
||||||
|
// We need to determine whether to delay bindning until draw().
|
||||||
|
mPipelineState.bindInDraw.first = false;
|
||||||
|
if (mAppState.hasExternalSamplers()) {
|
||||||
|
auto& layouts = pipelineState.pipelineLayout.setLayout;
|
||||||
|
auto haveExternalSamplers = [&](auto hwHandle) {
|
||||||
|
if (!hwHandle) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto layout =
|
||||||
|
resource_ptr<VulkanDescriptorSetLayout>::cast(&mResourceManager, hwHandle);
|
||||||
|
return layout->hasExternalSamplers();
|
||||||
|
};
|
||||||
|
if (std::any_of(layouts.begin(), layouts.end(), haveExternalSamplers)) {
|
||||||
|
mPipelineState.bindInDraw = { true, pipelineState };
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bindPipelineImpl(pipelineState);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanDriver::bindPipelineImpl(PipelineState const& pipelineState) {
|
||||||
FVK_SYSTRACE_SCOPE();
|
FVK_SYSTRACE_SCOPE();
|
||||||
auto commands = mCurrentRenderPass.commandBuffer;
|
auto commands = mCurrentRenderPass.commandBuffer;
|
||||||
auto vbi = resource_ptr<VulkanVertexBufferInfo>::cast(&mResourceManager,
|
auto vbi = resource_ptr<VulkanVertexBufferInfo>::cast(&mResourceManager,
|
||||||
@@ -1792,10 +1833,11 @@ void VulkanDriver::bindPipeline(PipelineState const& pipelineState) {
|
|||||||
|
|
||||||
constexpr uint8_t descriptorSetMaskTable[4] = {0x1, 0x3, 0x7, 0xF};
|
constexpr uint8_t descriptorSetMaskTable[4] = {0x1, 0x3, 0x7, 0xF};
|
||||||
|
|
||||||
mBoundPipeline = {
|
mPipelineState = {
|
||||||
.program = program,
|
.program = program,
|
||||||
.pipelineLayout = pipelineLayout,
|
.pipelineLayout = pipelineLayout,
|
||||||
.descriptorSetMask = fvkutils::DescriptorSetMask(descriptorSetMaskTable[layoutCount]),
|
.descriptorSetMask = fvkutils::DescriptorSetMask(descriptorSetMaskTable[layoutCount]),
|
||||||
|
.bindInDraw = {false, {}},
|
||||||
};
|
};
|
||||||
|
|
||||||
mPipelineCache.bindLayout(pipelineLayout);
|
mPipelineCache.bindLayout(pipelineLayout);
|
||||||
@@ -1842,14 +1884,24 @@ void VulkanDriver::draw2(uint32_t indexOffset, uint32_t indexCount, uint32_t ins
|
|||||||
FVK_SYSTRACE_SCOPE();
|
FVK_SYSTRACE_SCOPE();
|
||||||
VkCommandBuffer cmdbuffer = mCurrentRenderPass.commandBuffer->buffer();
|
VkCommandBuffer cmdbuffer = mCurrentRenderPass.commandBuffer->buffer();
|
||||||
|
|
||||||
|
if (mAppState.hasExternalSamplers()) {
|
||||||
|
auto const& [bindInDraw, pipelineSt] = mPipelineState.bindInDraw;
|
||||||
|
bool const hasUpdated =
|
||||||
|
mExternalImageManager.prepareBindSets(mDescriptorSetCache.getBoundSets());
|
||||||
|
if (bindInDraw || hasUpdated) {
|
||||||
|
bindPipelineImpl(pipelineSt);
|
||||||
|
}
|
||||||
|
mPipelineState.bindInDraw.first = false;
|
||||||
|
}
|
||||||
|
|
||||||
mDescriptorSetCache.commit(mCurrentRenderPass.commandBuffer,
|
mDescriptorSetCache.commit(mCurrentRenderPass.commandBuffer,
|
||||||
mBoundPipeline.pipelineLayout,
|
mPipelineState.pipelineLayout,
|
||||||
mBoundPipeline.descriptorSetMask);
|
mPipelineState.descriptorSetMask);
|
||||||
|
|
||||||
// Finally, make the actual draw call. TODO: support subranges
|
// Finally, make the actual draw call. TODO: support subranges
|
||||||
const uint32_t firstIndex = indexOffset;
|
uint32_t const firstIndex = indexOffset;
|
||||||
const int32_t vertexOffset = 0;
|
constexpr int32_t vertexOffset = 0;
|
||||||
const uint32_t firstInstId = 0;
|
constexpr uint32_t firstInstId = 0;
|
||||||
|
|
||||||
vkCmdDrawIndexed(cmdbuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstId);
|
vkCmdDrawIndexed(cmdbuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "VulkanYcbcrConversionCache.h"
|
#include "VulkanYcbcrConversionCache.h"
|
||||||
#include "vulkan/VulkanDescriptorSetCache.h"
|
#include "vulkan/VulkanDescriptorSetCache.h"
|
||||||
#include "vulkan/VulkanDescriptorSetLayoutCache.h"
|
#include "vulkan/VulkanDescriptorSetLayoutCache.h"
|
||||||
|
#include "vulkan/VulkanExternalImageManager.h"
|
||||||
#include "vulkan/VulkanPipelineLayoutCache.h"
|
#include "vulkan/VulkanPipelineLayoutCache.h"
|
||||||
#include "vulkan/memory/ResourceManager.h"
|
#include "vulkan/memory/ResourceManager.h"
|
||||||
#include "vulkan/memory/ResourcePointer.h"
|
#include "vulkan/memory/ResourcePointer.h"
|
||||||
@@ -119,6 +120,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void collectGarbage();
|
void collectGarbage();
|
||||||
|
void bindPipelineImpl(PipelineState const& pipelineState);
|
||||||
|
|
||||||
VulkanPlatform* mPlatform = nullptr;
|
VulkanPlatform* mPlatform = nullptr;
|
||||||
fvkmemory::ResourceManager mResourceManager;
|
fvkmemory::ResourceManager mResourceManager;
|
||||||
@@ -143,21 +145,29 @@ private:
|
|||||||
VulkanDescriptorSetLayoutCache mDescriptorSetLayoutCache;
|
VulkanDescriptorSetLayoutCache mDescriptorSetLayoutCache;
|
||||||
VulkanDescriptorSetCache mDescriptorSetCache;
|
VulkanDescriptorSetCache mDescriptorSetCache;
|
||||||
VulkanQueryManager mQueryManager;
|
VulkanQueryManager mQueryManager;
|
||||||
|
VulkanExternalImageManager mExternalImageManager;
|
||||||
|
|
||||||
// This is necessary for us to write to push constants after binding a pipeline.
|
// This is necessary for us to write to push constants after binding a pipeline.
|
||||||
struct {
|
struct {
|
||||||
|
// For push constant
|
||||||
resource_ptr<VulkanProgram> program;
|
resource_ptr<VulkanProgram> program;
|
||||||
|
// For push commiting dynamic ubos in draw()
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
fvkutils::DescriptorSetMask descriptorSetMask;
|
fvkutils::DescriptorSetMask descriptorSetMask;
|
||||||
} mBoundPipeline = {};
|
|
||||||
|
|
||||||
// We need to store information about a render pass to enable better barriers at the end of a
|
std::pair<bool, PipelineState> bindInDraw = {false, {}};
|
||||||
// renderpass.
|
} mPipelineState = {};
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
using AttachmentArray =
|
// This tracks whether the app has seen external samplers bound to a the descriptor set.
|
||||||
fvkutils::StaticVector<VulkanAttachment, MAX_RENDERTARGET_ATTACHMENT_TEXTURES>;
|
// This will force bindPipeline to take a slow path.
|
||||||
AttachmentArray attachments;
|
bool hasExternalSamplerLayouts = false;
|
||||||
} mRenderPassFboInfo = {};
|
bool hasBoundExternalImages = false;
|
||||||
|
|
||||||
|
bool hasExternalSamplers() const noexcept {
|
||||||
|
return hasExternalSamplerLayouts && hasBoundExternalImages;
|
||||||
|
}
|
||||||
|
} mAppState;
|
||||||
|
|
||||||
bool const mIsSRGBSwapChainSupported;
|
bool const mIsSRGBSwapChainSupported;
|
||||||
backend::StereoscopicType const mStereoscopicType;
|
backend::StereoscopicType const mStereoscopicType;
|
||||||
|
|||||||
280
filament/backend/src/vulkan/VulkanExternalImageManager.cpp
Normal file
280
filament/backend/src/vulkan/VulkanExternalImageManager.cpp
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
/*
|
||||||
|
* 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 "VulkanExternalImageManager.h"
|
||||||
|
|
||||||
|
#include "VulkanDescriptorSetCache.h"
|
||||||
|
#include "VulkanDescriptorSetLayoutCache.h"
|
||||||
|
#include "VulkanSamplerCache.h"
|
||||||
|
#include "VulkanYcbcrConversionCache.h"
|
||||||
|
#include "vulkan/memory/ResourcePointer.h"
|
||||||
|
#include "vulkan/utils/Conversion.h"
|
||||||
|
|
||||||
|
#include <backend/platforms/VulkanPlatform.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace filament::backend {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void erase(std::vector<T>& v, std::function<bool(T const&)> f) {
|
||||||
|
auto newEnd = std::remove_if(v.begin(), v.end(), f);
|
||||||
|
v.erase(newEnd, v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous
|
||||||
|
|
||||||
|
VulkanExternalImageManager::VulkanExternalImageManager(VulkanPlatform* platform,
|
||||||
|
VulkanSamplerCache* samplerCache, VulkanYcbcrConversionCache* ycbcrConversionCache,
|
||||||
|
VulkanDescriptorSetCache* setCache, VulkanDescriptorSetLayoutCache* layoutCache)
|
||||||
|
: mPlatform(platform),
|
||||||
|
mSamplerCache(samplerCache),
|
||||||
|
mYcbcrConversionCache(ycbcrConversionCache),
|
||||||
|
mDescriptorSetCache(setCache),
|
||||||
|
mDescriptorSetLayoutCache(layoutCache) {
|
||||||
|
}
|
||||||
|
|
||||||
|
VulkanExternalImageManager::~VulkanExternalImageManager() = default;
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::terminate() {
|
||||||
|
mSetAndLayouts.clear();
|
||||||
|
mSetBindings.clear();
|
||||||
|
mImages.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::onBeginFrame() {
|
||||||
|
std::for_each(mImages.begin(), mImages.end(), [](ImageData& image) {
|
||||||
|
image.hasBeenValidated = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VulkanExternalImageManager::prepareBindSets(SetArray const& sets) {
|
||||||
|
bool hasUpdated = false;
|
||||||
|
for (auto set: sets) {
|
||||||
|
if (!set) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (auto itr = std::find_if(mSetAndLayouts.begin(), mSetAndLayouts.end(),
|
||||||
|
[&](auto const& setAndLayout) { return setAndLayout.first == set; });
|
||||||
|
itr != mSetAndLayouts.end()) {
|
||||||
|
hasUpdated = updateSetAndLayout(itr->first, itr->second) || hasUpdated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VulkanExternalImageManager::updateSetAndLayout(
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSet> set,
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout) {
|
||||||
|
auto findImage = [&](fvkmemory::resource_ptr<VulkanTexture> texture) -> ImageData* {
|
||||||
|
auto itr = std::find_if(mImages.begin(), mImages.end(), [&](ImageData const& data) {
|
||||||
|
return data.ptr == texture;
|
||||||
|
});
|
||||||
|
assert_invariant(itr != mImages.end());
|
||||||
|
return &(*itr);
|
||||||
|
};
|
||||||
|
|
||||||
|
//std::vector<std::pair<uint8_t, ImageData*>> externalImages;
|
||||||
|
utils::FixedCapacityVector<std::pair<uint8_t, VkSampler>> samplerAndBindings;
|
||||||
|
samplerAndBindings.reserve(MAX_SAMPLER_COUNT);
|
||||||
|
|
||||||
|
bool hasImageUpdates = false;
|
||||||
|
for (auto& bindingInfo : mSetBindings) {
|
||||||
|
if (bindingInfo.set != set) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto imageData = findImage(bindingInfo.image);
|
||||||
|
hasImageUpdates = updateImage(imageData) || hasImageUpdates;
|
||||||
|
|
||||||
|
auto samplerParams = bindingInfo.samplerParams;
|
||||||
|
// according to spec, these must match chromaFilter
|
||||||
|
// https://registry.khronos.org/vulkan/specs/latest/man/html/VkSamplerCreateInfo.html#VUID-VkSamplerCreateInfo-minFilter-01645
|
||||||
|
samplerParams.filterMag = SamplerMagFilter::NEAREST;
|
||||||
|
samplerParams.filterMin = SamplerMinFilter::NEAREST;
|
||||||
|
|
||||||
|
auto sampler = mSamplerCache->getSampler({
|
||||||
|
.sampler = samplerParams,
|
||||||
|
.conversion = imageData->conversion,
|
||||||
|
});
|
||||||
|
samplerAndBindings.push_back({ bindingInfo.binding, sampler });
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to sort by binding number
|
||||||
|
std::sort(samplerAndBindings.begin(), samplerAndBindings.end());
|
||||||
|
|
||||||
|
utils::FixedCapacityVector<VkSampler> outSamplers;
|
||||||
|
outSamplers.reserve(MAX_SAMPLER_COUNT);
|
||||||
|
std::for_each(samplerAndBindings.begin(), samplerAndBindings.end(),
|
||||||
|
[&](auto const& b) { outSamplers.push_back(b.second); });
|
||||||
|
|
||||||
|
VkDescriptorSetLayout const oldLayout = layout->getVkLayout();
|
||||||
|
VkDescriptorSetLayout const newLayout =
|
||||||
|
mDescriptorSetLayoutCache->getVkLayout(layout->bitmask, outSamplers);
|
||||||
|
bool const hasLayoutUpdate = oldLayout != newLayout;
|
||||||
|
layout->setVkLayout(newLayout);
|
||||||
|
|
||||||
|
assert_invariant(
|
||||||
|
(!hasImageUpdates && !hasLayoutUpdate) ||
|
||||||
|
(hasImageUpdates && hasLayoutUpdate));
|
||||||
|
|
||||||
|
if (!hasLayoutUpdate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto foldBitsInHalf = [](auto bitset) {
|
||||||
|
constexpr size_t BITMASK_LOWER_BITS_LEN = sizeof(bitset) * 4;
|
||||||
|
decltype(bitset) outBitset;
|
||||||
|
bitset.forEachSetBit([&](size_t index) { outBitset.set(index % BITMASK_LOWER_BITS_LEN); });
|
||||||
|
return outBitset;
|
||||||
|
};
|
||||||
|
// We need to build a new descriptor set from the new layout
|
||||||
|
VkDescriptorSet oldSet = set->getVkSet();
|
||||||
|
VkDescriptorSet newSet = mDescriptorSetCache->getVkSet(layout);
|
||||||
|
|
||||||
|
using Bitmask = fvkutils::UniformBufferBitmask;
|
||||||
|
static_assert(sizeof(Bitmask) * 8 == fvkutils::MAX_DESCRIPTOR_SET_BITMASK_BITS);
|
||||||
|
|
||||||
|
auto const ubo = layout->bitmask.ubo | layout->bitmask.dynamicUbo;
|
||||||
|
auto const samplers = layout->bitmask.sampler & (~layout->bitmask.externalSampler);
|
||||||
|
|
||||||
|
// each bitmask denotes a binding index, and separated into two stages - vertex and buffer
|
||||||
|
// We fold the two stages into just the lower half of the bits to denote a combined set of
|
||||||
|
// bindings.
|
||||||
|
Bitmask const copyBindings = foldBitsInHalf(ubo | samplers);
|
||||||
|
|
||||||
|
// TODO: fix the size for better memory
|
||||||
|
std::vector<VkCopyDescriptorSet> copies;
|
||||||
|
copyBindings.forEachSetBit([&](size_t index) {
|
||||||
|
copies.push_back({
|
||||||
|
.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET,
|
||||||
|
.srcSet = oldSet,
|
||||||
|
.srcBinding = (uint32_t) index,
|
||||||
|
.dstSet = newSet,
|
||||||
|
.dstBinding = (uint32_t) index,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
vkUpdateDescriptorSets(mPlatform->getDevice(), 0, nullptr, copies.size(), copies.data());
|
||||||
|
|
||||||
|
set->setVkSet(newSet);
|
||||||
|
|
||||||
|
// We need to release the vkset, which is no longer used, back into the pool.
|
||||||
|
mDescriptorSetCache->manualRecyle(layout->count, oldLayout, oldSet);
|
||||||
|
|
||||||
|
// We need to update the external samplers in the set
|
||||||
|
for (auto& bindingInfo: mSetBindings) {
|
||||||
|
if (bindingInfo.set != set) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mDescriptorSetCache->updateSampler(set, bindingInfo.binding, bindingInfo.image,
|
||||||
|
VK_NULL_HANDLE);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkSamplerYcbcrConversion VulkanExternalImageManager::getVkSamplerYcbcrConversion(
|
||||||
|
VulkanPlatform::ExternalImageMetadata const& metadata) {
|
||||||
|
// This external image does not require external sampler (YUV conversion).
|
||||||
|
if (metadata.externalFormat == 0) {
|
||||||
|
return VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
VulkanYcbcrConversionCache::Params ycbcrParams = {
|
||||||
|
.conversion = {
|
||||||
|
.ycbcrModel = fvkutils::getYcbcrModelConversionFilament(metadata.ycbcrModel),
|
||||||
|
.r = fvkutils::getSwizzleFilament(metadata.ycbcrConversionComponents.r, 0),
|
||||||
|
.g = fvkutils::getSwizzleFilament(metadata.ycbcrConversionComponents.g, 1),
|
||||||
|
.b = fvkutils::getSwizzleFilament(metadata.ycbcrConversionComponents.b, 2),
|
||||||
|
.a = fvkutils::getSwizzleFilament(metadata.ycbcrConversionComponents.a, 3),
|
||||||
|
.ycbcrRange = fvkutils::getYcbcrRangeFilament(metadata.ycbcrRange),
|
||||||
|
.xChromaOffset = fvkutils::getChromaLocationFilament(metadata.xChromaOffset),
|
||||||
|
.yChromaOffset = fvkutils::getChromaLocationFilament(metadata.yChromaOffset),
|
||||||
|
|
||||||
|
// Unclear where to get the chromaFilter, we just assume it's nearest.
|
||||||
|
.chromaFilter = SamplerMagFilter::NEAREST,
|
||||||
|
},
|
||||||
|
.format = metadata.filamentFormat,
|
||||||
|
.externalFormat = metadata.externalFormat,
|
||||||
|
};
|
||||||
|
return mYcbcrConversionCache->getConversion(ycbcrParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VulkanExternalImageManager::updateImage(ImageData* image) {
|
||||||
|
if (image->hasBeenValidated) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
image->hasBeenValidated = true;
|
||||||
|
|
||||||
|
auto metadata = mPlatform->extractExternalImageMetadata(image->platformHandle);
|
||||||
|
auto vkYcbcr = getVkSamplerYcbcrConversion(metadata);
|
||||||
|
if (vkYcbcr == image->conversion) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
image->ptr->setYcbcrConversion(vkYcbcr, metadata.externalFormat != 0);
|
||||||
|
image->conversion = vkYcbcr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::addDescriptorSet(
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout,
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSet> set) {
|
||||||
|
mSetAndLayouts.push_back({set, layout});
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::removeDescriptorSet(
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSet> inSet) {
|
||||||
|
erase<SetAndLayout>(mSetAndLayouts,
|
||||||
|
[&](auto const& setLayout) { return (setLayout.first == inSet); });
|
||||||
|
erase<SetBindingInfo>(mSetBindings,
|
||||||
|
[&](auto const& bindingInfo) { return (bindingInfo.set == inSet); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::removeDescriptorSetLayout(
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> inLayout) {
|
||||||
|
erase<SetAndLayout>(mSetAndLayouts,
|
||||||
|
[&](auto const& setLayout) { return (setLayout.second == inLayout); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::bindExternallySampledTexture(
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSet> set, uint8_t bindingPoint,
|
||||||
|
fvkmemory::resource_ptr<VulkanTexture> image, SamplerParams samplerParams) {
|
||||||
|
// Should we do duplicate validation here?
|
||||||
|
mSetBindings.push_back({ bindingPoint, image, set, samplerParams });
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::addExternallySampledTexture(
|
||||||
|
fvkmemory::resource_ptr<VulkanTexture> image,
|
||||||
|
Platform::ExternalImageHandleRef platformHandleRef) {
|
||||||
|
mImages.push_back({ image, platformHandleRef, false });
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExternalImageManager::removeExternallySampledTexture(
|
||||||
|
fvkmemory::resource_ptr<VulkanTexture> image) {
|
||||||
|
erase<SetBindingInfo>(mSetBindings,
|
||||||
|
[&](auto const& bindingInfo) { return (bindingInfo.image == image); });
|
||||||
|
erase<ImageData>(mImages, [&](auto const& imageData) { return imageData.ptr == image; });
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VulkanExternalImageManager::isExternallySampledTexture(
|
||||||
|
fvkmemory::resource_ptr<VulkanTexture> image) const {
|
||||||
|
return std::find_if(mImages.begin(), mImages.end(),
|
||||||
|
[&](auto const& imageData) { return imageData.ptr == image; }) != mImages.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namesapce filament::backend
|
||||||
115
filament/backend/src/vulkan/VulkanExternalImageManager.h
Normal file
115
filament/backend/src/vulkan/VulkanExternalImageManager.h
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* 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_CACHING_VULKANEXTERNALIMAGEMANAGER_H
|
||||||
|
#define TNT_FILAMENT_BACKEND_CACHING_VULKANEXTERNALIMAGEMANAGER_H
|
||||||
|
|
||||||
|
#include "VulkanHandles.h"
|
||||||
|
|
||||||
|
#include <backend/DriverEnums.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace filament::backend {
|
||||||
|
|
||||||
|
class VulkanYcbcrConversionCache;
|
||||||
|
class VulkanSamplerCache;
|
||||||
|
class VulkanDescriptorSetLayoutCache;
|
||||||
|
class VulkanDescriptorSetCache;
|
||||||
|
|
||||||
|
// Manages the logic of external images and their quirks wrt Vulikan.
|
||||||
|
class VulkanExternalImageManager {
|
||||||
|
public:
|
||||||
|
|
||||||
|
VulkanExternalImageManager(
|
||||||
|
VulkanPlatform* platform,
|
||||||
|
VulkanSamplerCache* samplerCache,
|
||||||
|
VulkanYcbcrConversionCache* ycbcrConversionCache,
|
||||||
|
VulkanDescriptorSetCache* setCache,
|
||||||
|
VulkanDescriptorSetLayoutCache* layoutCache);
|
||||||
|
|
||||||
|
~VulkanExternalImageManager();
|
||||||
|
|
||||||
|
void terminate();
|
||||||
|
|
||||||
|
void onBeginFrame();
|
||||||
|
|
||||||
|
using SetArray = std::array<fvkmemory::resource_ptr<VulkanDescriptorSet>,
|
||||||
|
VulkanDescriptorSetLayout::UNIQUE_DESCRIPTOR_SET_COUNT>;
|
||||||
|
|
||||||
|
// This sets the currently bound layouts objects for the pipeline
|
||||||
|
bool prepareBindSets(SetArray const& layouts);
|
||||||
|
|
||||||
|
void addDescriptorSet(fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout,
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSet> set);
|
||||||
|
|
||||||
|
void removeDescriptorSetLayout(fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout);
|
||||||
|
|
||||||
|
void removeDescriptorSet(fvkmemory::resource_ptr<VulkanDescriptorSet> set);
|
||||||
|
|
||||||
|
void bindExternallySampledTexture(fvkmemory::resource_ptr<VulkanDescriptorSet> set,
|
||||||
|
uint8_t bindingPoint, fvkmemory::resource_ptr<VulkanTexture> image,
|
||||||
|
SamplerParams samplerParams);
|
||||||
|
|
||||||
|
void addExternallySampledTexture(fvkmemory::resource_ptr<VulkanTexture> image,
|
||||||
|
Platform::ExternalImageHandleRef platformHandleRef);
|
||||||
|
|
||||||
|
void removeExternallySampledTexture(fvkmemory::resource_ptr<VulkanTexture> image);
|
||||||
|
|
||||||
|
bool isExternallySampledTexture(fvkmemory::resource_ptr<VulkanTexture> image) const;
|
||||||
|
|
||||||
|
VkSamplerYcbcrConversion getVkSamplerYcbcrConversion(
|
||||||
|
VulkanPlatform::ExternalImageMetadata const& metadata);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct ImageData {
|
||||||
|
fvkmemory::resource_ptr<VulkanTexture> ptr;
|
||||||
|
Platform::ExternalImageHandle platformHandle;
|
||||||
|
bool hasBeenValidated = false; // indicates whether the image has been validated *this frame*
|
||||||
|
VkSamplerYcbcrConversion conversion = VK_NULL_HANDLE;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool updateSetAndLayout(fvkmemory::resource_ptr<VulkanDescriptorSet> set,
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout> layout);
|
||||||
|
bool updateImage(ImageData* imageData);
|
||||||
|
|
||||||
|
VulkanPlatform* mPlatform;
|
||||||
|
VulkanSamplerCache* mSamplerCache;
|
||||||
|
VulkanYcbcrConversionCache* mYcbcrConversionCache;
|
||||||
|
VulkanDescriptorSetCache* mDescriptorSetCache;
|
||||||
|
VulkanDescriptorSetLayoutCache* mDescriptorSetLayoutCache;
|
||||||
|
|
||||||
|
using SetAndLayout = std::pair<fvkmemory::resource_ptr<VulkanDescriptorSet>,
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSetLayout>>;
|
||||||
|
|
||||||
|
struct SetBindingInfo {
|
||||||
|
uint8_t binding = 0;
|
||||||
|
fvkmemory::resource_ptr<VulkanTexture> image;
|
||||||
|
fvkmemory::resource_ptr<VulkanDescriptorSet> set;
|
||||||
|
SamplerParams samplerParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use vectors instead of hash maps because we only expect small number of entries.
|
||||||
|
std::vector<SetAndLayout> mSetAndLayouts;
|
||||||
|
std::vector<SetBindingInfo> mSetBindings;
|
||||||
|
std::vector<ImageData> mImages;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // filament::backend
|
||||||
|
|
||||||
|
#endif // TNT_FILAMENT_BACKEND_CACHING_VULKANEXTERNALIMAGEMANAGER_H
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include <backend/platforms/VulkanPlatform.h>
|
#include <backend/platforms/VulkanPlatform.h>
|
||||||
|
|
||||||
|
#include <utils/compiler.h> // UTILS_FALLTHROUGH
|
||||||
#include <utils/Panic.h> // ASSERT_POSTCONDITION
|
#include <utils/Panic.h> // ASSERT_POSTCONDITION
|
||||||
|
|
||||||
using namespace bluevk;
|
using namespace bluevk;
|
||||||
@@ -89,8 +90,9 @@ BitmaskGroup fromBackendLayout(DescriptorSetLayout const& layout) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// TODO: properly handle external sampler
|
|
||||||
case DescriptorType::SAMPLER_EXTERNAL:
|
case DescriptorType::SAMPLER_EXTERNAL:
|
||||||
|
fromStageFlags(binding.stageFlags, binding.binding, mask.externalSampler);
|
||||||
|
UTILS_FALLTHROUGH;
|
||||||
case DescriptorType::SAMPLER: {
|
case DescriptorType::SAMPLER: {
|
||||||
fromStageFlags(binding.stageFlags, binding.binding, mask.sampler);
|
fromStageFlags(binding.stageFlags, binding.binding, mask.sampler);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -66,18 +66,21 @@ struct VulkanDescriptorSetLayout : public HwDescriptorSetLayout, fvkmemory::Reso
|
|||||||
|
|
||||||
// The bitmask representation of a set layout.
|
// The bitmask representation of a set layout.
|
||||||
struct Bitmask {
|
struct Bitmask {
|
||||||
// TODO: better utiltize the space below and use bitset instead.
|
|
||||||
fvkutils::UniformBufferBitmask ubo; // 8 bytes
|
fvkutils::UniformBufferBitmask ubo; // 8 bytes
|
||||||
fvkutils::UniformBufferBitmask dynamicUbo; // 8 bytes
|
fvkutils::UniformBufferBitmask dynamicUbo; // 8 bytes
|
||||||
fvkutils::SamplerBitmask sampler; // 8 bytes
|
fvkutils::SamplerBitmask sampler; // 8 bytes
|
||||||
fvkutils::InputAttachmentBitmask inputAttachment; // 8 bytes
|
fvkutils::InputAttachmentBitmask inputAttachment; // 8 bytes
|
||||||
|
|
||||||
|
// This is a subset of the bitmask.sampler field.
|
||||||
|
fvkutils::SamplerBitmask externalSampler; // 8 bytes
|
||||||
|
|
||||||
bool operator==(Bitmask const& right) const {
|
bool operator==(Bitmask const& right) const {
|
||||||
return ubo == right.ubo && dynamicUbo == right.dynamicUbo && sampler == right.sampler &&
|
return ubo == right.ubo && dynamicUbo == right.dynamicUbo && sampler == right.sampler &&
|
||||||
inputAttachment == right.inputAttachment;
|
inputAttachment == right.inputAttachment &&
|
||||||
|
externalSampler == right.externalSampler;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static_assert(sizeof(Bitmask) == 32);
|
static_assert(sizeof(Bitmask) == 40);
|
||||||
|
|
||||||
// This is a convenience struct to quickly check layout compatibility in terms of descriptor set
|
// This is a convenience struct to quickly check layout compatibility in terms of descriptor set
|
||||||
// pools.
|
// pools.
|
||||||
@@ -119,10 +122,16 @@ struct VulkanDescriptorSetLayout : public HwDescriptorSetLayout, fvkmemory::Reso
|
|||||||
|
|
||||||
VulkanDescriptorSetLayout(DescriptorSetLayout const& layout);
|
VulkanDescriptorSetLayout(DescriptorSetLayout const& layout);
|
||||||
|
|
||||||
|
// Note that we don't destroy the vklayout. This is done by the layout cache.
|
||||||
~VulkanDescriptorSetLayout() = default;
|
~VulkanDescriptorSetLayout() = default;
|
||||||
|
|
||||||
VkDescriptorSetLayout getVkLayout() const { return mVkLayout; }
|
VkDescriptorSetLayout const& getVkLayout() const noexcept { return mVkLayout; }
|
||||||
void setVkLayout(VkDescriptorSetLayout vklayout) { mVkLayout = vklayout; }
|
|
||||||
|
// It is possible to have the layout switch out due to AHardwarebuffer (external image) format
|
||||||
|
// changes.
|
||||||
|
void setVkLayout(VkDescriptorSetLayout vklayout) noexcept { mVkLayout = vklayout; }
|
||||||
|
|
||||||
|
bool hasExternalSamplers() const noexcept { return bitmask.externalSampler.count() > 0; }
|
||||||
|
|
||||||
Bitmask const bitmask;
|
Bitmask const bitmask;
|
||||||
Count const count;
|
Count const count;
|
||||||
@@ -137,12 +146,11 @@ public:
|
|||||||
// can use to repackage the vk handle.
|
// can use to repackage the vk handle.
|
||||||
using OnRecycle = std::function<void(VulkanDescriptorSet*)>;
|
using OnRecycle = std::function<void(VulkanDescriptorSet*)>;
|
||||||
|
|
||||||
VulkanDescriptorSet(VkDescriptorSet rawSet,
|
VulkanDescriptorSet(
|
||||||
fvkutils::UniformBufferBitmask const& dynamicUboMask,
|
fvkutils::UniformBufferBitmask const& dynamicUboMask,
|
||||||
uint8_t uniqueDynamicUboCount,
|
uint8_t uniqueDynamicUboCount,
|
||||||
OnRecycle&& onRecycleFn)
|
OnRecycle&& onRecycleFn)
|
||||||
: vkSet(rawSet),
|
: dynamicUboMask(dynamicUboMask),
|
||||||
dynamicUboMask(dynamicUboMask),
|
|
||||||
uniqueDynamicUboCount(uniqueDynamicUboCount),
|
uniqueDynamicUboCount(uniqueDynamicUboCount),
|
||||||
mOnRecycleFn(std::move(onRecycleFn)) {}
|
mOnRecycleFn(std::move(onRecycleFn)) {}
|
||||||
|
|
||||||
@@ -152,6 +160,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkDescriptorSet const& getVkSet() const noexcept {
|
||||||
|
return mVkSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that the only case where you'd set it more than once is with external images/samplers.
|
||||||
|
void setVkSet(VkDescriptorSet vkset) noexcept { mVkSet = vkset; }
|
||||||
|
|
||||||
void setOffsets(backend::DescriptorSetOffsetArray&& offsets) noexcept {
|
void setOffsets(backend::DescriptorSetOffsetArray&& offsets) noexcept {
|
||||||
mOffsets = std::move(offsets);
|
mOffsets = std::move(offsets);
|
||||||
}
|
}
|
||||||
@@ -163,11 +178,11 @@ public:
|
|||||||
void acquire(fvkmemory::resource_ptr<VulkanTexture> texture);
|
void acquire(fvkmemory::resource_ptr<VulkanTexture> texture);
|
||||||
void acquire(fvkmemory::resource_ptr<VulkanBufferObject> buffer);
|
void acquire(fvkmemory::resource_ptr<VulkanBufferObject> buffer);
|
||||||
|
|
||||||
VkDescriptorSet const vkSet;
|
|
||||||
fvkutils::UniformBufferBitmask const dynamicUboMask;
|
fvkutils::UniformBufferBitmask const dynamicUboMask;
|
||||||
uint8_t const uniqueDynamicUboCount;
|
uint8_t const uniqueDynamicUboCount;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
VkDescriptorSet mVkSet = VK_NULL_HANDLE;
|
||||||
backend::DescriptorSetOffsetArray mOffsets;
|
backend::DescriptorSetOffsetArray mOffsets;
|
||||||
std::vector<fvkmemory::resource_ptr<fvkmemory::Resource>> mResources;
|
std::vector<fvkmemory::resource_ptr<fvkmemory::Resource>> mResources;
|
||||||
OnRecycle mOnRecycleFn;
|
OnRecycle mOnRecycleFn;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "VulkanConstants.h"
|
#include "VulkanConstants.h"
|
||||||
#include "vulkan/utils/Conversion.h"
|
#include "vulkan/utils/Conversion.h"
|
||||||
|
#include "vulkan/vulkan_core.h"
|
||||||
|
|
||||||
#include <utils/Panic.h>
|
#include <utils/Panic.h>
|
||||||
|
|
||||||
@@ -33,8 +34,15 @@ VkSampler VulkanSamplerCache::getSampler(Params params) noexcept {
|
|||||||
if (UTILS_LIKELY(iter != mCache.end())) {
|
if (UTILS_LIKELY(iter != mCache.end())) {
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
VkSamplerYcbcrConversionInfo ycbcrConversion = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
||||||
|
.conversion = params.conversion,
|
||||||
|
};
|
||||||
|
|
||||||
auto const& samplerParams = params.sampler;
|
auto const& samplerParams = params.sampler;
|
||||||
VkSamplerCreateInfo samplerInfo{ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
VkSamplerCreateInfo samplerInfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
||||||
|
.pNext = params.conversion != VK_NULL_HANDLE ? &ycbcrConversion : VK_NULL_HANDLE,
|
||||||
.magFilter = fvkutils::getFilter(samplerParams.filterMag),
|
.magFilter = fvkutils::getFilter(samplerParams.filterMag),
|
||||||
.minFilter = fvkutils::getFilter(samplerParams.filterMin),
|
.minFilter = fvkutils::getFilter(samplerParams.filterMin),
|
||||||
.mipmapMode = fvkutils::getMipmapMode(samplerParams.filterMin),
|
.mipmapMode = fvkutils::getMipmapMode(samplerParams.filterMin),
|
||||||
@@ -48,7 +56,8 @@ VkSampler VulkanSamplerCache::getSampler(Params params) noexcept {
|
|||||||
.minLod = 0.0f,
|
.minLod = 0.0f,
|
||||||
.maxLod = fvkutils::getMaxLod(samplerParams.filterMin),
|
.maxLod = fvkutils::getMaxLod(samplerParams.filterMin),
|
||||||
.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
|
.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
|
||||||
.unnormalizedCoordinates = VK_FALSE };
|
.unnormalizedCoordinates = VK_FALSE,
|
||||||
|
};
|
||||||
VkSampler sampler;
|
VkSampler sampler;
|
||||||
VkResult result = vkCreateSampler(mDevice, &samplerInfo, VKALLOC, &sampler);
|
VkResult result = vkCreateSampler(mDevice, &samplerInfo, VKALLOC, &sampler);
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS) << "Unable to create sampler."
|
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS) << "Unable to create sampler."
|
||||||
|
|||||||
@@ -108,11 +108,6 @@ void VulkanSwapChain::present() {
|
|||||||
|
|
||||||
mCommands->flush();
|
mCommands->flush();
|
||||||
|
|
||||||
// call the image ready wait function
|
|
||||||
if (mExplicitImageReadyWait != nullptr) {
|
|
||||||
mExplicitImageReadyWait(swapChain);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We only present if it is not headless. No-op for headless.
|
// We only present if it is not headless. No-op for headless.
|
||||||
if (!mHeadless) {
|
if (!mHeadless) {
|
||||||
VkSemaphore const finishedDrawing = mCommands->acquireFinishedSignal();
|
VkSemaphore const finishedDrawing = mCommands->acquireFinishedSignal();
|
||||||
@@ -146,7 +141,6 @@ void VulkanSwapChain::acquire(bool& resized) {
|
|||||||
VulkanPlatform::ImageSyncData imageSyncData;
|
VulkanPlatform::ImageSyncData imageSyncData;
|
||||||
VkResult const result = mPlatform->acquire(swapChain, &imageSyncData);
|
VkResult const result = mPlatform->acquire(swapChain, &imageSyncData);
|
||||||
mCurrentSwapIndex = imageSyncData.imageIndex;
|
mCurrentSwapIndex = imageSyncData.imageIndex;
|
||||||
mExplicitImageReadyWait = imageSyncData.explicitImageReadyWait;
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)
|
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)
|
||||||
<< "Cannot acquire in swapchain. error=" << static_cast<int32_t>(result);
|
<< "Cannot acquire in swapchain. error=" << static_cast<int32_t>(result);
|
||||||
if (imageSyncData.imageReadySemaphore != VK_NULL_HANDLE) {
|
if (imageSyncData.imageReadySemaphore != VK_NULL_HANDLE) {
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ struct VulkanSwapChain : public HwSwapChain, fvkmemory::Resource {
|
|||||||
|
|
||||||
void present();
|
void present();
|
||||||
|
|
||||||
void acquire(bool& reized);
|
// Acquire a new image from the swapchain. If the image is not available it would wait until it
|
||||||
|
// is.
|
||||||
|
void acquire(bool& resized);
|
||||||
|
|
||||||
fvkmemory::resource_ptr<VulkanTexture> getCurrentColor() const noexcept {
|
fvkmemory::resource_ptr<VulkanTexture> getCurrentColor() const noexcept {
|
||||||
uint32_t const imageIndex = mCurrentSwapIndex;
|
uint32_t const imageIndex = mCurrentSwapIndex;
|
||||||
@@ -99,7 +101,6 @@ private:
|
|||||||
VkExtent2D mExtent;
|
VkExtent2D mExtent;
|
||||||
uint32_t mLayerCount;
|
uint32_t mLayerCount;
|
||||||
uint32_t mCurrentSwapIndex;
|
uint32_t mCurrentSwapIndex;
|
||||||
std::function<void(Platform::SwapChain* handle)> mExplicitImageReadyWait = nullptr;
|
|
||||||
bool mAcquired;
|
bool mAcquired;
|
||||||
bool mIsFirstRenderPass;
|
bool mIsFirstRenderPass;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ VkSamplerYcbcrConversion VulkanYcbcrConversionCache::getConversion(
|
|||||||
TextureSwizzle const swizzleArray[] = { chroma.r, chroma.g, chroma.b, chroma.a };
|
TextureSwizzle const swizzleArray[] = { chroma.r, chroma.g, chroma.b, chroma.a };
|
||||||
VkSamplerYcbcrConversionCreateInfo conversionInfo = {
|
VkSamplerYcbcrConversionCreateInfo conversionInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
|
||||||
.format = VK_FORMAT_UNDEFINED,
|
.format = fvkutils::getVkFormat(params.format),
|
||||||
.ycbcrModel = fvkutils::getYcbcrModelConversion(chroma.ycbcrModel),
|
.ycbcrModel = fvkutils::getYcbcrModelConversion(chroma.ycbcrModel),
|
||||||
.ycbcrRange = fvkutils::getYcbcrRange(chroma.ycbcrRange),
|
.ycbcrRange = fvkutils::getYcbcrRange(chroma.ycbcrRange),
|
||||||
.components = fvkutils::getSwizzleMap(swizzleArray),
|
.components = fvkutils::getSwizzleMap(swizzleArray),
|
||||||
@@ -52,6 +52,7 @@ VkSamplerYcbcrConversion VulkanYcbcrConversionCache::getConversion(
|
|||||||
.chromaFilter = fvkutils::getFilter(chroma.chromaFilter),
|
.chromaFilter = fvkutils::getFilter(chroma.chromaFilter),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// We could put this in the platform class, but that seems like a bit of an overkill
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
VkExternalFormatANDROID externalFormat = {
|
VkExternalFormatANDROID externalFormat = {
|
||||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID,
|
.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID,
|
||||||
@@ -59,6 +60,7 @@ VkSamplerYcbcrConversion VulkanYcbcrConversionCache::getConversion(
|
|||||||
};
|
};
|
||||||
if (params.externalFormat) {
|
if (params.externalFormat) {
|
||||||
conversionInfo.pNext = &externalFormat;
|
conversionInfo.pNext = &externalFormat;
|
||||||
|
conversionInfo.format = VK_FORMAT_UNDEFINED;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ class VulkanYcbcrConversionCache {
|
|||||||
public:
|
public:
|
||||||
struct Params {
|
struct Params {
|
||||||
SamplerYcbcrConversion conversion = {};
|
SamplerYcbcrConversion conversion = {};
|
||||||
uint32_t padding = 0;
|
TextureFormat format = {};
|
||||||
|
uint16_t padding = 0;
|
||||||
uint64_t externalFormat = 0;
|
uint64_t externalFormat = 0;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(Params) == 16);
|
static_assert(sizeof(Params) == 16);
|
||||||
|
|||||||
@@ -132,6 +132,10 @@ public:
|
|||||||
return id() == other.id() && type() == other.type();
|
return id() == other.id() && type() == other.type();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(resource_ptr<D> const& other) const {
|
||||||
|
return !((*this) == other);
|
||||||
|
}
|
||||||
|
|
||||||
inline explicit operator bool() const {
|
inline explicit operator bool() const {
|
||||||
return bool(mRef);
|
return bool(mRef);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ ExtensionSet getDeviceExtensions(VkPhysicalDevice device) {
|
|||||||
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
|
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
|
||||||
VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME,
|
VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME,
|
||||||
VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME,
|
VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME,
|
||||||
|
VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME,
|
||||||
#endif
|
#endif
|
||||||
// MoltenVk is the only non-conformant implementation we're interested in.
|
// MoltenVk is the only non-conformant implementation we're interested in.
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
@@ -326,7 +327,9 @@ VkInstance createInstance(ExtensionSet const& requiredExts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VkDevice createLogicalDevice(VkPhysicalDevice physicalDevice,
|
VkDevice createLogicalDevice(VkPhysicalDevice physicalDevice,
|
||||||
VkPhysicalDeviceFeatures2 const& features, uint32_t graphicsQueueFamilyIndex,
|
VkPhysicalDeviceFeatures2 const& features,
|
||||||
|
VkPhysicalDeviceVulkan11Features const& vk11Features,
|
||||||
|
uint32_t graphicsQueueFamilyIndex,
|
||||||
uint32_t protectedGraphicsQueueFamilyIndex, ExtensionSet const& deviceExtensions,
|
uint32_t protectedGraphicsQueueFamilyIndex, ExtensionSet const& deviceExtensions,
|
||||||
bool requestImageView2DOn3DImage) {
|
bool requestImageView2DOn3DImage) {
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
@@ -359,14 +362,28 @@ VkDevice createLogicalDevice(VkPhysicalDevice physicalDevice,
|
|||||||
|
|
||||||
// We could simply enable all supported features, but since that may have performance
|
// We could simply enable all supported features, but since that may have performance
|
||||||
// consequences let's just enable the features we need.
|
// consequences let's just enable the features we need.
|
||||||
VkPhysicalDeviceFeatures enabledFeatures{
|
VkPhysicalDeviceFeatures enabledFeatures = {
|
||||||
.depthClamp = features.features.depthClamp,
|
.depthClamp = features.features.depthClamp,
|
||||||
.samplerAnisotropy = features.features.samplerAnisotropy,
|
.samplerAnisotropy = features.features.samplerAnisotropy,
|
||||||
.textureCompressionETC2 = features.features.textureCompressionETC2,
|
.textureCompressionETC2 = features.features.textureCompressionETC2,
|
||||||
.textureCompressionBC = features.features.textureCompressionBC,
|
.textureCompressionBC = features.features.textureCompressionBC,
|
||||||
.shaderClipDistance = features.features.shaderClipDistance,
|
.shaderClipDistance = features.features.shaderClipDistance,
|
||||||
};
|
};
|
||||||
deviceCreateInfo.pEnabledFeatures = &enabledFeatures;
|
|
||||||
|
VkPhysicalDeviceFeatures2 enabledFeatures2 = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
||||||
|
.features = enabledFeatures,
|
||||||
|
};
|
||||||
|
chainStruct(&deviceCreateInfo, &enabledFeatures2);
|
||||||
|
|
||||||
|
VkPhysicalDeviceVulkan11Features enabledVk11Features = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES,
|
||||||
|
.multiview = vk11Features.multiview,
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
.samplerYcbcrConversion = vk11Features.samplerYcbcrConversion,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
chainStruct(&deviceCreateInfo, &enabledVk11Features);
|
||||||
|
|
||||||
deviceCreateInfo.enabledExtensionCount = (uint32_t) requestExtensions.size();
|
deviceCreateInfo.enabledExtensionCount = (uint32_t) requestExtensions.size();
|
||||||
deviceCreateInfo.ppEnabledExtensionNames = requestExtensions.data();
|
deviceCreateInfo.ppEnabledExtensionNames = requestExtensions.data();
|
||||||
@@ -383,7 +400,7 @@ VkDevice createLogicalDevice(VkPhysicalDevice physicalDevice,
|
|||||||
|
|
||||||
VkPhysicalDeviceMultiviewFeaturesKHR multiview = {
|
VkPhysicalDeviceMultiviewFeaturesKHR multiview = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR,
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR,
|
||||||
.multiview = VK_TRUE,
|
.multiview = vk11Features.multiview,
|
||||||
.multiviewGeometryShader = VK_FALSE,
|
.multiviewGeometryShader = VK_FALSE,
|
||||||
.multiviewTessellationShader = VK_FALSE,
|
.multiviewTessellationShader = VK_FALSE,
|
||||||
};
|
};
|
||||||
@@ -734,6 +751,7 @@ Driver* VulkanPlatform::createDriver(void* sharedContext,
|
|||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES,
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES,
|
||||||
};
|
};
|
||||||
chainStruct(&context.mPhysicalDeviceFeatures, &queryProtectedMemoryFeatures);
|
chainStruct(&context.mPhysicalDeviceFeatures, &queryProtectedMemoryFeatures);
|
||||||
|
chainStruct(&context.mPhysicalDeviceFeatures, &context.mPhysicalDeviceVk11Features);
|
||||||
chainStruct(&context.mPhysicalDeviceProperties, &protectedMemoryProperties);
|
chainStruct(&context.mPhysicalDeviceProperties, &protectedMemoryProperties);
|
||||||
|
|
||||||
// Initialize the following fields: physicalDeviceProperties, memoryProperties,
|
// Initialize the following fields: physicalDeviceProperties, memoryProperties,
|
||||||
@@ -795,10 +813,10 @@ Driver* VulkanPlatform::createDriver(void* sharedContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mImpl->mDevice == VK_NULL_HANDLE) {
|
if (mImpl->mDevice == VK_NULL_HANDLE) {
|
||||||
mImpl->mDevice =
|
mImpl->mDevice = createLogicalDevice(mImpl->mPhysicalDevice,
|
||||||
createLogicalDevice(mImpl->mPhysicalDevice, context.mPhysicalDeviceFeatures,
|
context.mPhysicalDeviceFeatures, context.mPhysicalDeviceVk11Features,
|
||||||
mImpl->mGraphicsQueueFamilyIndex, mImpl->mProtectedGraphicsQueueFamilyIndex,
|
mImpl->mGraphicsQueueFamilyIndex, mImpl->mProtectedGraphicsQueueFamilyIndex,
|
||||||
deviceExts, requestPortabilitySubsetImageView2DOn3DImage);
|
deviceExts, requestPortabilitySubsetImageView2DOn3DImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_invariant(mImpl->mDevice != VK_NULL_HANDLE);
|
assert_invariant(mImpl->mDevice != VK_NULL_HANDLE);
|
||||||
@@ -826,12 +844,10 @@ Driver* VulkanPlatform::createDriver(void* sharedContext,
|
|||||||
if (!mImpl->mSharedContext) {
|
if (!mImpl->mSharedContext) {
|
||||||
context.mDebugUtilsSupported = setContains(instExts, VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
context.mDebugUtilsSupported = setContains(instExts, VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||||
context.mDebugMarkersSupported = setContains(deviceExts, VK_EXT_DEBUG_MARKER_EXTENSION_NAME);
|
context.mDebugMarkersSupported = setContains(deviceExts, VK_EXT_DEBUG_MARKER_EXTENSION_NAME);
|
||||||
context.mMultiviewEnabled = setContains(deviceExts, VK_KHR_MULTIVIEW_EXTENSION_NAME);
|
|
||||||
} else {
|
} else {
|
||||||
VulkanSharedContext const* scontext = (VulkanSharedContext const*) sharedContext;
|
VulkanSharedContext const* scontext = (VulkanSharedContext const*) sharedContext;
|
||||||
context.mDebugUtilsSupported = scontext->debugUtilsSupported;
|
context.mDebugUtilsSupported = scontext->debugUtilsSupported;
|
||||||
context.mDebugMarkersSupported = scontext->debugMarkersSupported;
|
context.mDebugMarkersSupported = scontext->debugMarkersSupported;
|
||||||
context.mMultiviewEnabled = scontext->multiviewSupported;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the availability of lazily allocated memory
|
// Check the availability of lazily allocated memory
|
||||||
@@ -977,30 +993,6 @@ VkQueue VulkanPlatform::getProtectedGraphicsQueue() const noexcept {
|
|||||||
return mImpl->mProtectedGraphicsQueue;
|
return mImpl->mProtectedGraphicsQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanPlatform::ExternalImageMetadata VulkanPlatform::getExternalImageMetadata(
|
|
||||||
ExternalImageHandleRef externalImage) {
|
|
||||||
return getExternalImageMetadataImpl(externalImage, mImpl->mDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanPlatform::ImageData VulkanPlatform::createExternalImageData(
|
|
||||||
ExternalImageHandleRef externalImage, const ExternalImageMetadata& metadata,
|
|
||||||
uint32_t memoryTypeIndex, VkImageUsageFlags usage) {
|
|
||||||
return createExternalImageDataImpl(externalImage, mImpl->mDevice, metadata, memoryTypeIndex,
|
|
||||||
usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSampler VulkanPlatform::createExternalSampler(SamplerYcbcrConversion chroma,
|
|
||||||
SamplerParams sampler, uint32_t internalFormat) {
|
|
||||||
return createExternalSamplerImpl(mImpl->mDevice, chroma, sampler, internalFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImageView VulkanPlatform::createExternalImageView(SamplerYcbcrConversion chroma,
|
|
||||||
uint32_t internalFormat, VkImage image, VkImageSubresourceRange range,
|
|
||||||
VkImageViewType viewType, VkComponentMapping swizzle) {
|
|
||||||
return createExternalImageViewImpl(mImpl->mDevice, chroma, internalFormat, image, range,
|
|
||||||
viewType, swizzle);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtensionSet VulkanPlatform::getSwapchainInstanceExtensions() const {
|
ExtensionSet VulkanPlatform::getSwapchainInstanceExtensions() const {
|
||||||
return getSwapchainInstanceExtensionsImpl();
|
return getSwapchainInstanceExtensionsImpl();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
#include <backend/platforms/VulkanPlatformAndroid.h>
|
#include <backend/platforms/VulkanPlatformAndroid.h>
|
||||||
|
|
||||||
|
#include "vulkan/VulkanConstants.h"
|
||||||
|
#include "vulkan/VulkanContext.h"
|
||||||
|
#include "vulkan/vulkan_core.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
#include <private/backend/BackendUtilsAndroid.h>
|
#include <private/backend/BackendUtilsAndroid.h>
|
||||||
|
|
||||||
#include "vulkan/VulkanConstants.h"
|
|
||||||
|
|
||||||
#include <utils/Panic.h>
|
#include <utils/Panic.h>
|
||||||
#include "vulkan/utils/Image.h"
|
|
||||||
#include "vulkan/utils/Conversion.h"
|
|
||||||
|
|
||||||
#include <bluevk/BlueVK.h>
|
#include <bluevk/BlueVK.h>
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ VkFormat transformVkFormat(VkFormat format, bool sRGB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isProtectedFromUsage(uint64_t usage) {
|
bool isProtectedFromUsage(uint64_t usage) {
|
||||||
return (usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) ? true : false;
|
return usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<VkFormat, VkImageUsageFlags> getVKFormatAndUsage(const AHardwareBuffer_Desc& desc,
|
std::pair<VkFormat, VkImageUsageFlags> getVKFormatAndUsage(const AHardwareBuffer_Desc& desc,
|
||||||
@@ -120,7 +120,9 @@ std::pair<VkFormat, VkImageUsageFlags> getVKFormatAndUsage(const AHardwareBuffer
|
|||||||
usage = 0;
|
usage = 0;
|
||||||
if (desc.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE) {
|
if (desc.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE) {
|
||||||
usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
|
usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
|
||||||
|
// We shouldn't be using external samplers as input attachments
|
||||||
|
// usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
||||||
}
|
}
|
||||||
if (desc.usage & AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER) {
|
if (desc.usage & AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER) {
|
||||||
if (isDepthFormat) {
|
if (isDepthFormat) {
|
||||||
@@ -136,87 +138,38 @@ std::pair<VkFormat, VkImageUsageFlags> getVKFormatAndUsage(const AHardwareBuffer
|
|||||||
return { format, usage };
|
return { format, usage };
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanPlatform::ImageData allocateExternalImage(AHardwareBuffer* buffer, VkDevice device,
|
std::pair<TextureFormat, TextureUsage> getFilamentFormatAndUsage(const AHardwareBuffer_Desc& desc,
|
||||||
VulkanPlatform::ExternalImageMetadata const& metadata, uint32_t memoryTypeIndex,
|
bool sRGB) {
|
||||||
VkImageUsageFlags usage) {
|
auto const format = mapToFilamentFormat(desc.format, sRGB);
|
||||||
VulkanPlatform::ImageData data;
|
return {
|
||||||
|
format,
|
||||||
// if external format we need to specifiy it in the allocation
|
mapToFilamentUsage(desc.usage, format),
|
||||||
const bool useExternalFormat = metadata.format == VK_FORMAT_UNDEFINED;
|
|
||||||
|
|
||||||
const VkExternalFormatANDROID externalFormat = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID,
|
|
||||||
.pNext = nullptr,
|
|
||||||
// pass down the format (external means we don't have it VK defined)
|
|
||||||
.externalFormat = metadata.externalFormat,
|
|
||||||
};
|
};
|
||||||
const VkExternalMemoryImageCreateInfo externalCreateInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
|
|
||||||
.pNext = useExternalFormat ? &externalFormat : nullptr,
|
|
||||||
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkImageCreateInfo imageInfo{ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
|
|
||||||
imageInfo.pNext = &externalCreateInfo;
|
|
||||||
imageInfo.format = metadata.format;
|
|
||||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
|
||||||
imageInfo.extent = {
|
|
||||||
metadata.width,
|
|
||||||
metadata.height,
|
|
||||||
1u,
|
|
||||||
};
|
|
||||||
imageInfo.mipLevels = 1;
|
|
||||||
imageInfo.arrayLayers = metadata.layers;
|
|
||||||
imageInfo.samples = metadata.samples;
|
|
||||||
imageInfo.usage = usage;
|
|
||||||
|
|
||||||
VkResult result = vkCreateImage(device, &imageInfo, VKALLOC, &data.first);
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
|
||||||
<< "vkCreateImage failed with error=" << static_cast<int32_t>(result);
|
|
||||||
|
|
||||||
// Allocate the memory
|
|
||||||
VkImportAndroidHardwareBufferInfoANDROID androidHardwareBufferInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.buffer = buffer,
|
|
||||||
};
|
|
||||||
VkMemoryDedicatedAllocateInfo memoryDedicatedAllocateInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
|
|
||||||
.pNext = &androidHardwareBufferInfo,
|
|
||||||
.image = data.first,
|
|
||||||
.buffer = VK_NULL_HANDLE,
|
|
||||||
};
|
|
||||||
VkMemoryAllocateInfo allocInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
|
||||||
.pNext = &memoryDedicatedAllocateInfo,
|
|
||||||
.allocationSize = metadata.allocationSize,
|
|
||||||
.memoryTypeIndex = memoryTypeIndex,
|
|
||||||
};
|
|
||||||
result = vkAllocateMemory(device, &allocInfo, VKALLOC, &data.second);
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
|
||||||
<< "vkAllocateMemory failed with error=" << static_cast<int32_t>(result);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}// namespace
|
}// namespace
|
||||||
|
|
||||||
VulkanPlatformAndroid::ExternalImageVulkanAndroid::~ExternalImageVulkanAndroid() = default;
|
VulkanPlatformAndroid::ExternalImageVulkanAndroid::~ExternalImageVulkanAndroid() {
|
||||||
|
if (__builtin_available(android 26, *)) {
|
||||||
|
if (aHardwareBuffer) {
|
||||||
|
AHardwareBuffer_release(aHardwareBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Platform::ExternalImageHandle VulkanPlatformAndroid::createExternalImage(
|
Platform::ExternalImageHandle VulkanPlatformAndroid::createExternalImage(
|
||||||
AHardwareBuffer const* buffer, bool sRGB) noexcept {
|
AHardwareBuffer const* buffer, bool sRGB) noexcept {
|
||||||
if (__builtin_available(android 26, *)) {
|
if (__builtin_available(android 26, *)) {
|
||||||
|
auto bufferImpl = const_cast<AHardwareBuffer*>(buffer);
|
||||||
|
AHardwareBuffer_acquire(bufferImpl);
|
||||||
|
|
||||||
AHardwareBuffer_Desc hardwareBufferDescription = {};
|
AHardwareBuffer_Desc hardwareBufferDescription = {};
|
||||||
AHardwareBuffer_describe(buffer, &hardwareBufferDescription);
|
AHardwareBuffer_describe(buffer, &hardwareBufferDescription);
|
||||||
|
|
||||||
auto* const p = new (std::nothrow) ExternalImageVulkanAndroid;
|
auto* const p = new (std::nothrow) ExternalImageVulkanAndroid;
|
||||||
p->aHardwareBuffer = const_cast<AHardwareBuffer*>(buffer);
|
p->aHardwareBuffer = const_cast<AHardwareBuffer*>(buffer);
|
||||||
p->sRGB = sRGB;
|
p->sRGB = sRGB;
|
||||||
p->height = hardwareBufferDescription.height;
|
|
||||||
p->width = hardwareBufferDescription.width;
|
|
||||||
TextureFormat textureFormat = mapToFilamentFormat(hardwareBufferDescription.format, sRGB);
|
|
||||||
p->format = textureFormat;
|
|
||||||
p->usage = mapToFilamentUsage(hardwareBufferDescription.usage, textureFormat);
|
|
||||||
return Platform::ExternalImageHandle{ p };
|
return Platform::ExternalImageHandle{ p };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,23 +178,20 @@ Platform::ExternalImageHandle VulkanPlatformAndroid::createExternalImage(
|
|||||||
|
|
||||||
VulkanPlatformAndroid::ExternalImageDescAndroid VulkanPlatformAndroid::getExternalImageDesc(
|
VulkanPlatformAndroid::ExternalImageDescAndroid VulkanPlatformAndroid::getExternalImageDesc(
|
||||||
ExternalImageHandleRef externalImage) const noexcept {
|
ExternalImageHandleRef externalImage) const noexcept {
|
||||||
auto const* fvkExternalImage =
|
auto metadata = extractExternalImageMetadata(externalImage);
|
||||||
static_cast<ExternalImageVulkanAndroid const*>(externalImage.get());
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
.width = fvkExternalImage->width,
|
.width = metadata.width,
|
||||||
.height = fvkExternalImage->height,
|
.height = metadata.height,
|
||||||
.format = fvkExternalImage->format,
|
.format = metadata.filamentFormat,
|
||||||
.usage = fvkExternalImage->usage,
|
.usage = metadata.filamentUsage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanPlatform::ExternalImageMetadata VulkanPlatformAndroid::getExternalImageMetadata(
|
VulkanPlatform::ExternalImageMetadata VulkanPlatformAndroid::extractExternalImageMetadata(
|
||||||
ExternalImageHandleRef externalImage) {
|
ExternalImageHandleRef image) const {
|
||||||
auto const* fvkExternalImage =
|
auto const* fvkExternalImage = static_cast<ExternalImageVulkanAndroid const*>(image.get());
|
||||||
static_cast<ExternalImageVulkanAndroid const*>(externalImage.get());
|
|
||||||
|
|
||||||
ExternalImageMetadata metadata;
|
ExternalImageMetadata metadata = {};
|
||||||
AHardwareBuffer* buffer = fvkExternalImage->aHardwareBuffer;
|
AHardwareBuffer* buffer = fvkExternalImage->aHardwareBuffer;
|
||||||
if (__builtin_available(android 26, *)) {
|
if (__builtin_available(android 26, *)) {
|
||||||
AHardwareBuffer_Desc bufferDesc;
|
AHardwareBuffer_Desc bufferDesc;
|
||||||
@@ -249,16 +199,30 @@ VulkanPlatform::ExternalImageMetadata VulkanPlatformAndroid::getExternalImageMet
|
|||||||
metadata.width = bufferDesc.width;
|
metadata.width = bufferDesc.width;
|
||||||
metadata.height = bufferDesc.height;
|
metadata.height = bufferDesc.height;
|
||||||
metadata.layers = bufferDesc.layers;
|
metadata.layers = bufferDesc.layers;
|
||||||
metadata.isProtected = isProtectedFromUsage(bufferDesc.usage);
|
|
||||||
std::tie(metadata.format, metadata.usage) =
|
std::tie(metadata.format, metadata.usage) =
|
||||||
getVKFormatAndUsage(bufferDesc, fvkExternalImage->sRGB);
|
getVKFormatAndUsage(bufferDesc, fvkExternalImage->sRGB);
|
||||||
}
|
std::tie(metadata.filamentFormat, metadata.filamentUsage) =
|
||||||
|
getFilamentFormatAndUsage(bufferDesc, fvkExternalImage->sRGB);
|
||||||
|
|
||||||
|
if (isProtectedFromUsage(bufferDesc.usage)) {
|
||||||
|
metadata.filamentUsage |= TextureUsage::PROTECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: The following seems unnecessary. we should be able to discern directly from the
|
||||||
|
// bufferDesc.
|
||||||
|
if (any(metadata.filamentUsage & TextureUsage::BLIT_SRC)) {
|
||||||
|
metadata.usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (any(metadata.filamentUsage & (TextureUsage::BLIT_DST | TextureUsage::UPLOADABLE))) {
|
||||||
|
metadata.usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||||
|
}
|
||||||
|
}
|
||||||
metadata.samples = VK_SAMPLE_COUNT_1_BIT;
|
metadata.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
|
|
||||||
VkAndroidHardwareBufferFormatPropertiesANDROID formatInfo = {
|
VkAndroidHardwareBufferFormatPropertiesANDROID formatInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID,
|
.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID,
|
||||||
.pNext = nullptr,
|
|
||||||
};
|
};
|
||||||
VkAndroidHardwareBufferPropertiesANDROID properties = {
|
VkAndroidHardwareBufferPropertiesANDROID properties = {
|
||||||
.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID,
|
.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID,
|
||||||
@@ -268,138 +232,116 @@ VulkanPlatform::ExternalImageMetadata VulkanPlatformAndroid::getExternalImageMet
|
|||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
||||||
<< "vkGetAndroidHardwareBufferProperties failed with error="
|
<< "vkGetAndroidHardwareBufferProperties failed with error="
|
||||||
<< static_cast<int32_t>(result);
|
<< static_cast<int32_t>(result);
|
||||||
|
|
||||||
VkFormat bufferPropertiesFormat = transformVkFormat(formatInfo.format, fvkExternalImage->sRGB);
|
VkFormat bufferPropertiesFormat = transformVkFormat(formatInfo.format, fvkExternalImage->sRGB);
|
||||||
FILAMENT_CHECK_POSTCONDITION(metadata.format == bufferPropertiesFormat)
|
FILAMENT_CHECK_POSTCONDITION(metadata.format == bufferPropertiesFormat)
|
||||||
<< "mismatched image format( " << metadata.format << ") and queried format("
|
<< "mismatched image format( " << metadata.format << ") and queried format("
|
||||||
<< bufferPropertiesFormat << ") for external image (AHB)";
|
<< bufferPropertiesFormat << ") for external image (AHB)";
|
||||||
metadata.externalFormat = formatInfo.externalFormat;
|
metadata.externalFormat = formatInfo.externalFormat;
|
||||||
|
|
||||||
|
// Choose either externalFormat > 0 or metadata.format and prefer the latter.
|
||||||
|
if (metadata.externalFormat > 0 && metadata.format != VK_FORMAT_UNDEFINED) {
|
||||||
|
// See VUID-VkImageCreateInfo-pNext-09457
|
||||||
|
metadata.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
|
metadata.externalFormat = 0;
|
||||||
|
}
|
||||||
|
|
||||||
metadata.allocationSize = properties.allocationSize;
|
metadata.allocationSize = properties.allocationSize;
|
||||||
metadata.memoryTypeBits = properties.memoryTypeBits;
|
metadata.memoryTypeBits = properties.memoryTypeBits;
|
||||||
|
|
||||||
|
metadata.ycbcrConversionComponents = formatInfo.samplerYcbcrConversionComponents;
|
||||||
|
metadata.ycbcrModel = formatInfo.suggestedYcbcrModel;
|
||||||
|
metadata.ycbcrRange = formatInfo.suggestedYcbcrRange;
|
||||||
|
metadata.xChromaOffset = formatInfo.suggestedXChromaOffset;
|
||||||
|
metadata.yChromaOffset = formatInfo.suggestedYChromaOffset;
|
||||||
|
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanPlatformAndroid::ImageData VulkanPlatformAndroid::createExternalImageData(
|
VulkanPlatformAndroid::ImageData VulkanPlatformAndroid::createVkImageFromExternal(
|
||||||
ExternalImageHandleRef externalImage, const ExternalImageMetadata& metadata,
|
ExternalImageHandleRef externalImage) const {
|
||||||
uint32_t memoryTypeIndex, VkImageUsageFlags usage) {
|
auto const& metadata = extractExternalImageMetadata(externalImage);
|
||||||
|
|
||||||
auto const* fvkExternalImage =
|
auto const* fvkExternalImage =
|
||||||
static_cast<ExternalImageVulkanAndroid const*>(externalImage.get());
|
static_cast<ExternalImageVulkanAndroid const*>(externalImage.get());
|
||||||
ImageData data = allocateExternalImage(fvkExternalImage->aHardwareBuffer, getDevice(), metadata,
|
AHardwareBuffer* buffer = fvkExternalImage->aHardwareBuffer;
|
||||||
memoryTypeIndex, usage);
|
|
||||||
VkResult result = vkBindImageMemory(getDevice(), data.first, data.second, 0);
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
|
||||||
<< "vkBindImageMemory error=" << static_cast<int32_t>(result);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImageView VulkanPlatform::createExternalImageViewImpl(VkDevice device, SamplerYcbcrConversion chroma,
|
// if external format we need to specifiy it in the allocation
|
||||||
uint32_t internalFormat, VkImage image, VkImageSubresourceRange range,
|
bool const useExternalFormat = metadata.format == VK_FORMAT_UNDEFINED;
|
||||||
VkImageViewType viewType, VkComponentMapping swizzle){
|
|
||||||
VkExternalFormatANDROID externalFormat = {
|
VkExternalFormatANDROID const externalFormat = {
|
||||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID,
|
.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID,
|
||||||
.externalFormat = internalFormat,
|
|
||||||
};
|
|
||||||
|
|
||||||
TextureSwizzle const swizzleArray[] = {chroma.r, chroma.g, chroma.b, chroma.a};
|
|
||||||
VkSamplerYcbcrConversionCreateInfo conversionInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
|
|
||||||
.pNext = &externalFormat,
|
|
||||||
.format = VK_FORMAT_UNDEFINED,
|
|
||||||
.ycbcrModel = fvkutils::getYcbcrModelConversion(chroma.ycbcrModel),
|
|
||||||
.ycbcrRange = fvkutils::getYcbcrRange(chroma.ycbcrRange),
|
|
||||||
.components = fvkutils::getSwizzleMap(swizzleArray),
|
|
||||||
.xChromaOffset = fvkutils::getChromaLocation(chroma.xChromaOffset),
|
|
||||||
.yChromaOffset = fvkutils::getChromaLocation(chroma.yChromaOffset),
|
|
||||||
.chromaFilter = fvkutils::getFilter(chroma.chromaFilter),
|
|
||||||
};
|
|
||||||
VkSamplerYcbcrConversion conversion = VK_NULL_HANDLE;
|
|
||||||
VkResult result = vkCreateSamplerYcbcrConversion(device, &conversionInfo,
|
|
||||||
nullptr, &conversion);
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
|
||||||
<< "Unable to create Ycbcr Conversion."
|
|
||||||
<< " error=" << static_cast<int32_t>(result);
|
|
||||||
|
|
||||||
VkSamplerYcbcrConversionInfo samplerYcbcrConversionInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
|
||||||
.conversion = conversion,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkImageViewCreateInfo viewInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
||||||
.pNext = &samplerYcbcrConversionInfo,
|
|
||||||
.flags = 0,
|
|
||||||
.image = image,
|
|
||||||
.viewType = viewType,
|
|
||||||
.format = VK_FORMAT_UNDEFINED,
|
|
||||||
.components = swizzle,
|
|
||||||
.subresourceRange = range,
|
|
||||||
};
|
|
||||||
VkImageView imageView;
|
|
||||||
result = vkCreateImageView(device, &viewInfo, VKALLOC, &imageView);
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
|
||||||
<< "Unable to create VkImageView."
|
|
||||||
<< " error=" << static_cast<int32_t>(result);
|
|
||||||
|
|
||||||
return imageView;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSampler VulkanPlatform::createExternalSamplerImpl(
|
|
||||||
VkDevice device, SamplerYcbcrConversion chroma, SamplerParams params,
|
|
||||||
uint32_t internalFormat) {
|
|
||||||
VkExternalFormatANDROID externalFormat = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID,
|
|
||||||
.externalFormat = internalFormat,
|
|
||||||
};
|
|
||||||
|
|
||||||
TextureSwizzle const swizzleArray[] = {chroma.r, chroma.g, chroma.b, chroma.a};
|
|
||||||
VkSamplerYcbcrConversionCreateInfo conversionInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
|
|
||||||
.pNext = &externalFormat,
|
|
||||||
.format = VK_FORMAT_UNDEFINED,
|
|
||||||
.ycbcrModel = fvkutils::getYcbcrModelConversion(chroma.ycbcrModel),
|
|
||||||
.ycbcrRange = fvkutils::getYcbcrRange(chroma.ycbcrRange),
|
|
||||||
.components = fvkutils::getSwizzleMap(swizzleArray),
|
|
||||||
.xChromaOffset = fvkutils::getChromaLocation(chroma.xChromaOffset),
|
|
||||||
.yChromaOffset = fvkutils::getChromaLocation(chroma.yChromaOffset),
|
|
||||||
.chromaFilter = fvkutils::getFilter(chroma.chromaFilter),
|
|
||||||
};
|
|
||||||
VkSamplerYcbcrConversion conversion = VK_NULL_HANDLE;
|
|
||||||
VkResult result = vkCreateSamplerYcbcrConversion(device, &conversionInfo,
|
|
||||||
nullptr, &conversion);
|
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
|
||||||
<< "Unable to create Ycbcr Conversion."
|
|
||||||
<< " error=" << static_cast<int32_t>(result);
|
|
||||||
|
|
||||||
VkSamplerYcbcrConversionInfo samplerYcbcrConversionInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.conversion = conversion,
|
.externalFormat = metadata.externalFormat,
|
||||||
|
};
|
||||||
|
VkExternalMemoryImageCreateInfo const externalCreateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
|
||||||
|
.pNext = useExternalFormat ? &externalFormat : nullptr,
|
||||||
|
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
|
||||||
};
|
};
|
||||||
|
|
||||||
VkSamplerCreateInfo samplerInfo = {
|
VkImageCreateInfo const imageInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||||
.pNext = &samplerYcbcrConversionInfo,
|
.pNext = &externalCreateInfo,
|
||||||
.magFilter = fvkutils::getFilter(params.filterMag),
|
.flags = useExternalFormat ? VK_IMAGE_CREATE_ALIAS_BIT : 0u,
|
||||||
.minFilter = fvkutils::getFilter(params.filterMin),
|
.imageType = VK_IMAGE_TYPE_2D,
|
||||||
.mipmapMode = fvkutils::getMipmapMode(params.filterMin),
|
.format = metadata.format,
|
||||||
.addressModeU = fvkutils::getWrapMode(params.wrapS),
|
.extent = {
|
||||||
.addressModeV = fvkutils::getWrapMode(params.wrapT),
|
metadata.width,
|
||||||
.addressModeW = fvkutils::getWrapMode(params.wrapR),
|
metadata.height,
|
||||||
.anisotropyEnable = params.anisotropyLog2 == 0 ? VK_FALSE : VK_TRUE,
|
1u,
|
||||||
.maxAnisotropy = (float)(1u << params.anisotropyLog2),
|
},
|
||||||
.compareEnable = fvkutils::getCompareEnable(params.compareMode),
|
.mipLevels = 1,
|
||||||
.compareOp = fvkutils::getCompareOp(params.compareFunc),
|
.arrayLayers = metadata.layers,
|
||||||
.minLod = 0.0f,
|
.samples = metadata.samples,
|
||||||
.maxLod = fvkutils::getMaxLod(params.filterMin),
|
.usage = metadata.usage,
|
||||||
.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
|
|
||||||
.unnormalizedCoordinates = VK_FALSE,
|
|
||||||
};
|
};
|
||||||
VkSampler sampler;
|
|
||||||
result = vkCreateSampler(device, &samplerInfo, VKALLOC, &sampler);
|
VkDevice const device = getDevice();
|
||||||
|
|
||||||
|
VkImage image;
|
||||||
|
VkResult result = vkCreateImage(device, &imageInfo, VKALLOC, &image);
|
||||||
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
||||||
<< "Unable to create sampler."
|
<< "vkCreateImage failed with error=" << static_cast<int32_t>(result);
|
||||||
<< " error=" << static_cast<int32_t>(result);
|
|
||||||
return sampler;
|
// Allocate the memory
|
||||||
|
VkImportAndroidHardwareBufferInfoANDROID const androidHardwareBufferInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID,
|
||||||
|
.buffer = buffer,
|
||||||
|
};
|
||||||
|
VkMemoryDedicatedAllocateInfo const memoryDedicatedAllocateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
|
||||||
|
.pNext = &androidHardwareBufferInfo,
|
||||||
|
.image = image,
|
||||||
|
.buffer = VK_NULL_HANDLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||||
|
vkGetPhysicalDeviceMemoryProperties(getPhysicalDevice(), &memoryProperties);
|
||||||
|
|
||||||
|
|
||||||
|
VkMemoryPropertyFlags const requiredMemoryFlags =
|
||||||
|
any(metadata.filamentUsage & TextureUsage::UPLOADABLE)
|
||||||
|
? VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
||||||
|
: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||||
|
|
||||||
|
uint32_t const memoryTypeIndex = VulkanContext::selectMemoryType(memoryProperties,
|
||||||
|
metadata.memoryTypeBits, requiredMemoryFlags);
|
||||||
|
|
||||||
|
VkMemoryAllocateInfo const allocInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||||
|
.pNext = &memoryDedicatedAllocateInfo,
|
||||||
|
.allocationSize = metadata.allocationSize,
|
||||||
|
.memoryTypeIndex = memoryTypeIndex,
|
||||||
|
};
|
||||||
|
VkDeviceMemory memory;
|
||||||
|
result = vkAllocateMemory(device, &allocInfo, VKALLOC, &memory);
|
||||||
|
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
||||||
|
<< "vkAllocateMemory failed with error=" << static_cast<int32_t>(result);
|
||||||
|
|
||||||
|
result = vkBindImageMemory(getDevice(), image, memory, 0);
|
||||||
|
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS)
|
||||||
|
<< "vkBindImageMemory error=" << static_cast<int32_t>(result);
|
||||||
|
return { image, memory };
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanPlatform::ExtensionSet VulkanPlatformAndroid::getSwapchainInstanceExtensions() const {
|
VulkanPlatform::ExtensionSet VulkanPlatformAndroid::getSwapchainInstanceExtensions() const {
|
||||||
@@ -427,20 +369,9 @@ VulkanPlatform::SurfaceBundle VulkanPlatformAndroid::createVkSurfaceKHR(void* na
|
|||||||
// Deprecated platform dependent helper methods
|
// Deprecated platform dependent helper methods
|
||||||
VulkanPlatform::ExtensionSet VulkanPlatform::getSwapchainInstanceExtensionsImpl() { return {}; }
|
VulkanPlatform::ExtensionSet VulkanPlatform::getSwapchainInstanceExtensionsImpl() { return {}; }
|
||||||
|
|
||||||
VulkanPlatform::ExternalImageMetadata VulkanPlatform::getExternalImageMetadataImpl(
|
|
||||||
ExternalImageHandleRef externalImage, VkDevice device) {
|
|
||||||
return ExternalImageMetadata{};
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanPlatform::ImageData VulkanPlatform::createExternalImageDataImpl(
|
|
||||||
ExternalImageHandleRef externalImage, VkDevice device,
|
|
||||||
const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex, VkImageUsageFlags usage) {
|
|
||||||
return ImageData{};
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanPlatform::SurfaceBundle VulkanPlatform::createVkSurfaceKHRImpl(void* nativeWindow,
|
VulkanPlatform::SurfaceBundle VulkanPlatform::createVkSurfaceKHRImpl(void* nativeWindow,
|
||||||
VkInstance instance, uint64_t flags) noexcept {
|
VkInstance instance, uint64_t flags) noexcept {
|
||||||
return SurfaceBundle{};
|
return SurfaceBundle{};
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace filament::backend
|
} // namespace filament::backend
|
||||||
|
|||||||
@@ -63,30 +63,6 @@ VulkanPlatform::ExtensionSet VulkanPlatform::getSwapchainInstanceExtensionsImpl(
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanPlatform::ExternalImageMetadata VulkanPlatform::getExternalImageMetadataImpl(
|
|
||||||
ExternalImageHandleRef externalImage, VkDevice device) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanPlatform::ImageData VulkanPlatform::createExternalImageDataImpl(
|
|
||||||
ExternalImageHandleRef externalImage, VkDevice device,
|
|
||||||
const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex, VkImageUsageFlags usage) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSampler VulkanPlatform::createExternalSamplerImpl(VkDevice device,
|
|
||||||
SamplerYcbcrConversion chroma,
|
|
||||||
SamplerParams sampler,
|
|
||||||
uint32_t internalFormat) {
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImageView VulkanPlatform::createExternalImageViewImpl(VkDevice device,
|
|
||||||
SamplerYcbcrConversion chroma, uint32_t internalFormat, VkImage image,
|
|
||||||
VkImageSubresourceRange range, VkImageViewType viewType, VkComponentMapping swizzle) {
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanPlatform::SurfaceBundle VulkanPlatform::createVkSurfaceKHRImpl(void* nativeWindow,
|
VulkanPlatform::SurfaceBundle VulkanPlatform::createVkSurfaceKHRImpl(void* nativeWindow,
|
||||||
VkInstance instance, uint64_t flags) noexcept {
|
VkInstance instance, uint64_t flags) noexcept {
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
|
|||||||
@@ -84,30 +84,6 @@ using namespace bluevk;
|
|||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
VulkanPlatform::ExternalImageMetadata VulkanPlatform::getExternalImageMetadataImpl(
|
|
||||||
ExternalImageHandleRef externalImage, VkDevice device) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanPlatform::ImageData VulkanPlatform::createExternalImageDataImpl(
|
|
||||||
ExternalImageHandleRef externalImage, VkDevice device,
|
|
||||||
const ExternalImageMetadata& metadata, uint32_t memoryTypeIndex, VkImageUsageFlags usage) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSampler VulkanPlatform::createExternalSamplerImpl(VkDevice device,
|
|
||||||
SamplerYcbcrConversion chroma,
|
|
||||||
SamplerParams sampler,
|
|
||||||
uint32_t internalFormat) {
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImageView VulkanPlatform::createExternalImageViewImpl(VkDevice device,
|
|
||||||
SamplerYcbcrConversion chroma, uint32_t internalFormat, VkImage image,
|
|
||||||
VkImageSubresourceRange range, VkImageViewType viewType, VkComponentMapping swizzle) {
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanPlatform::ExtensionSet VulkanPlatform::getSwapchainInstanceExtensionsImpl() {
|
VulkanPlatform::ExtensionSet VulkanPlatform::getSwapchainInstanceExtensionsImpl() {
|
||||||
VulkanPlatform::ExtensionSet const ret = {
|
VulkanPlatform::ExtensionSet const ret = {
|
||||||
#if defined(__linux__) && defined(FILAMENT_SUPPORTS_WAYLAND)
|
#if defined(__linux__) && defined(FILAMENT_SUPPORTS_WAYLAND)
|
||||||
|
|||||||
@@ -668,4 +668,111 @@ VkShaderStageFlags getShaderStageFlags(ShaderStageFlags stageFlags) {
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkSamplerYcbcrModelConversion getYcbcrModelConversion(
|
||||||
|
SamplerYcbcrModelConversion model) {
|
||||||
|
switch (model) {
|
||||||
|
case SamplerYcbcrModelConversion::RGB_IDENTITY:
|
||||||
|
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
|
||||||
|
case SamplerYcbcrModelConversion::YCBCR_IDENTITY:
|
||||||
|
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY;
|
||||||
|
case SamplerYcbcrModelConversion::YCBCR_709:
|
||||||
|
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709;
|
||||||
|
case SamplerYcbcrModelConversion::YCBCR_601:
|
||||||
|
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601;
|
||||||
|
case SamplerYcbcrModelConversion::YCBCR_2020:
|
||||||
|
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020;
|
||||||
|
default:
|
||||||
|
assert_invariant(false &&
|
||||||
|
"Unknown data type, conversion is not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkSamplerYcbcrRange getYcbcrRange(SamplerYcbcrRange range) {
|
||||||
|
switch (range) {
|
||||||
|
case SamplerYcbcrRange::ITU_FULL:
|
||||||
|
return VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
|
||||||
|
case SamplerYcbcrRange::ITU_NARROW:
|
||||||
|
return VK_SAMPLER_YCBCR_RANGE_ITU_NARROW;
|
||||||
|
default:
|
||||||
|
assert_invariant(false &&
|
||||||
|
"Unknown data type, conversion is not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkChromaLocation getChromaLocation(ChromaLocation loc) {
|
||||||
|
switch (loc) {
|
||||||
|
case ChromaLocation::COSITED_EVEN:
|
||||||
|
return VK_CHROMA_LOCATION_COSITED_EVEN;
|
||||||
|
case ChromaLocation::MIDPOINT:
|
||||||
|
return VK_CHROMA_LOCATION_MIDPOINT;
|
||||||
|
default:
|
||||||
|
assert_invariant(false &&
|
||||||
|
"Unknown data type, conversion is not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SamplerYcbcrModelConversion getYcbcrModelConversionFilament(VkSamplerYcbcrModelConversion model) {
|
||||||
|
switch (model) {
|
||||||
|
case VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY:
|
||||||
|
return SamplerYcbcrModelConversion::RGB_IDENTITY;
|
||||||
|
case VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY:
|
||||||
|
return SamplerYcbcrModelConversion::YCBCR_IDENTITY;
|
||||||
|
case VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709:
|
||||||
|
return SamplerYcbcrModelConversion::YCBCR_709;
|
||||||
|
case VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601:
|
||||||
|
return SamplerYcbcrModelConversion::YCBCR_601;
|
||||||
|
case VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020:
|
||||||
|
return SamplerYcbcrModelConversion::YCBCR_2020;
|
||||||
|
default:
|
||||||
|
assert_invariant(false && "Unknown data type, conversion is not supported.");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SamplerYcbcrRange getYcbcrRangeFilament(VkSamplerYcbcrRange range) {
|
||||||
|
switch (range) {
|
||||||
|
case VK_SAMPLER_YCBCR_RANGE_ITU_FULL:
|
||||||
|
return SamplerYcbcrRange::ITU_FULL;
|
||||||
|
case VK_SAMPLER_YCBCR_RANGE_ITU_NARROW:
|
||||||
|
return SamplerYcbcrRange::ITU_NARROW;
|
||||||
|
default:
|
||||||
|
assert_invariant(false && "Unknown data type, conversion is not supported.");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ChromaLocation getChromaLocationFilament(VkChromaLocation loc) {
|
||||||
|
switch (loc) {
|
||||||
|
case VK_CHROMA_LOCATION_COSITED_EVEN:
|
||||||
|
return ChromaLocation::COSITED_EVEN;
|
||||||
|
case VK_CHROMA_LOCATION_MIDPOINT:
|
||||||
|
return ChromaLocation::MIDPOINT;
|
||||||
|
default:
|
||||||
|
assert_invariant(false && "Unknown data type, conversion is not supported.");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureSwizzle getSwizzleFilament(VkComponentSwizzle c, uint8_t rgbaIndex) {
|
||||||
|
switch (c) {
|
||||||
|
case VK_COMPONENT_SWIZZLE_ZERO:
|
||||||
|
return TextureSwizzle::SUBSTITUTE_ZERO;
|
||||||
|
case VK_COMPONENT_SWIZZLE_ONE:
|
||||||
|
return TextureSwizzle::SUBSTITUTE_ONE;
|
||||||
|
case VK_COMPONENT_SWIZZLE_IDENTITY:
|
||||||
|
return (TextureSwizzle) (((uint8_t) TextureSwizzle::CHANNEL_0) + rgbaIndex);
|
||||||
|
case VK_COMPONENT_SWIZZLE_R:
|
||||||
|
return TextureSwizzle::CHANNEL_0;
|
||||||
|
case VK_COMPONENT_SWIZZLE_G:
|
||||||
|
return TextureSwizzle::CHANNEL_1;
|
||||||
|
case VK_COMPONENT_SWIZZLE_B:
|
||||||
|
return TextureSwizzle::CHANNEL_2;
|
||||||
|
case VK_COMPONENT_SWIZZLE_A:
|
||||||
|
return TextureSwizzle::CHANNEL_3;
|
||||||
|
default:
|
||||||
|
assert_invariant(false && "Unknown data type, conversion is not supported.");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace filament::backend::fvkutils
|
} // namespace filament::backend::fvkutils
|
||||||
|
|||||||
@@ -69,6 +69,12 @@ VkSamplerYcbcrModelConversion getYcbcrModelConversion(SamplerYcbcrModelConversio
|
|||||||
VkSamplerYcbcrRange getYcbcrRange(SamplerYcbcrRange range);
|
VkSamplerYcbcrRange getYcbcrRange(SamplerYcbcrRange range);
|
||||||
VkChromaLocation getChromaLocation(ChromaLocation loc);
|
VkChromaLocation getChromaLocation(ChromaLocation loc);
|
||||||
|
|
||||||
|
// Ycbcr related functions
|
||||||
|
SamplerYcbcrModelConversion getYcbcrModelConversionFilament(VkSamplerYcbcrModelConversion model);
|
||||||
|
SamplerYcbcrRange getYcbcrRangeFilament(VkSamplerYcbcrRange range);
|
||||||
|
ChromaLocation getChromaLocationFilament(VkChromaLocation loc);
|
||||||
|
TextureSwizzle getSwizzleFilament(VkComponentSwizzle c, uint8_t rgbaIndex);
|
||||||
|
|
||||||
inline VkImageViewType getViewType(SamplerType target) {
|
inline VkImageViewType getViewType(SamplerType target) {
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case SamplerType::SAMPLER_CUBEMAP:
|
case SamplerType::SAMPLER_CUBEMAP:
|
||||||
|
|||||||
@@ -348,6 +348,10 @@ using SamplerBitmask = utils::bitset64;
|
|||||||
// general.
|
// general.
|
||||||
using InputAttachmentBitmask = utils::bitset64;
|
using InputAttachmentBitmask = utils::bitset64;
|
||||||
|
|
||||||
|
constexpr uint8_t MAX_DESCRIPTOR_SET_BITMASK_BITS =
|
||||||
|
std::max(std::max(sizeof(UniformBufferBitmask), sizeof(SamplerBitmask)),
|
||||||
|
sizeof(InputAttachmentBitmask)) * 8;
|
||||||
|
|
||||||
template<typename Bitmask>
|
template<typename Bitmask>
|
||||||
static constexpr uint8_t getVertexStageShift() noexcept {
|
static constexpr uint8_t getVertexStageShift() noexcept {
|
||||||
// We assume the bottom half of bits are for vertex stages.
|
// We assume the bottom half of bits are for vertex stages.
|
||||||
|
|||||||
@@ -193,49 +193,6 @@ uint8_t reduceSampleCount(uint8_t sampleCount, VkSampleCountFlags mask) {
|
|||||||
return mostSignificantBit((sampleCount - 1) & mask);
|
return mostSignificantBit((sampleCount - 1) & mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSamplerYcbcrModelConversion getYcbcrModelConversion(
|
|
||||||
SamplerYcbcrModelConversion model) {
|
|
||||||
switch (model) {
|
|
||||||
case SamplerYcbcrModelConversion::RGB_IDENTITY:
|
|
||||||
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
|
|
||||||
case SamplerYcbcrModelConversion::YCBCR_IDENTITY:
|
|
||||||
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY;
|
|
||||||
case SamplerYcbcrModelConversion::YCBCR_709:
|
|
||||||
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709;
|
|
||||||
case SamplerYcbcrModelConversion::YCBCR_601:
|
|
||||||
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601;
|
|
||||||
case SamplerYcbcrModelConversion::YCBCR_2020:
|
|
||||||
return VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020;
|
|
||||||
default:
|
|
||||||
assert_invariant(false &&
|
|
||||||
"Unknown data type, conversion is not supported.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSamplerYcbcrRange getYcbcrRange(SamplerYcbcrRange range) {
|
|
||||||
switch (range) {
|
|
||||||
case SamplerYcbcrRange::ITU_FULL:
|
|
||||||
return VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
|
|
||||||
case SamplerYcbcrRange::ITU_NARROW:
|
|
||||||
return VK_SAMPLER_YCBCR_RANGE_ITU_NARROW;
|
|
||||||
default:
|
|
||||||
assert_invariant(false &&
|
|
||||||
"Unknown data type, conversion is not supported.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkChromaLocation getChromaLocation(ChromaLocation loc) {
|
|
||||||
switch (loc) {
|
|
||||||
case ChromaLocation::COSITED_EVEN:
|
|
||||||
return VK_CHROMA_LOCATION_COSITED_EVEN;
|
|
||||||
case ChromaLocation::MIDPOINT:
|
|
||||||
return VK_CHROMA_LOCATION_MIDPOINT;
|
|
||||||
default:
|
|
||||||
assert_invariant(false &&
|
|
||||||
"Unknown data type, conversion is not supported.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace filament::backend::fvkutils
|
} // namespace filament::backend::fvkutils
|
||||||
|
|
||||||
bool operator<(const VkImageSubresourceRange& a, const VkImageSubresourceRange& b) {
|
bool operator<(const VkImageSubresourceRange& a, const VkImageSubresourceRange& b) {
|
||||||
|
|||||||
@@ -23,30 +23,44 @@ namespace test {
|
|||||||
|
|
||||||
using namespace filament::backend;
|
using namespace filament::backend;
|
||||||
|
|
||||||
Shader::Shader(DriverApi& api, Cleanup& cleanup, ShaderConfig config) {
|
Shader::Shader(DriverApi& api, Cleanup& cleanup, ShaderConfig config) : mCleanup(cleanup) {
|
||||||
utils::FixedCapacityVector<DescriptorSetLayoutBinding> kLayouts(config.uniformNames.size());
|
utils::FixedCapacityVector<DescriptorSetLayoutBinding> kLayouts(config.uniforms.size());
|
||||||
for (unsigned char i = 0; i < config.uniformNames.size(); ++i) {
|
for (unsigned char i = 0; i < config.uniforms.size(); ++i) {
|
||||||
kLayouts[i] =
|
kLayouts[i] = {
|
||||||
{ DescriptorType::UNIFORM_BUFFER, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, i };
|
config.uniforms[i].type.value_or(DescriptorType::UNIFORM_BUFFER),
|
||||||
};
|
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, i };
|
||||||
|
}
|
||||||
|
|
||||||
|
// This assumes that the uniforms will all be in a single descriptor set at index 1.
|
||||||
|
// If there are shaders with uniforms in other sets then ShaderConfig will need to be expanded
|
||||||
|
// to accommodate that.
|
||||||
|
size_t kDescriptorSetIndex = 1;
|
||||||
filamat::DescriptorSets descriptors;
|
filamat::DescriptorSets descriptors;
|
||||||
for (unsigned char i = 0; i < config.uniformNames.size(); ++i) {
|
descriptors[kDescriptorSetIndex] = filamat::DescriptorSetInfo(config.uniforms.size());
|
||||||
descriptors[i + 1] = {{ config.uniformNames[i], kLayouts[i], {}}};
|
for (unsigned char i = 0; i < config.uniforms.size(); ++i) {
|
||||||
|
descriptors[kDescriptorSetIndex][i] = {
|
||||||
|
config.uniforms[i].name, kLayouts[i], config.uniforms[i].samplerInfo };
|
||||||
}
|
}
|
||||||
ShaderGenerator shaderGen(
|
ShaderGenerator shaderGen(
|
||||||
std::move(config.vertexShader), std::move(config.fragmentShader), BackendTest::sBackend,
|
std::move(config.vertexShader), std::move(config.fragmentShader), BackendTest::sBackend,
|
||||||
BackendTest::sIsMobilePlatform, std::move(descriptors));
|
BackendTest::sIsMobilePlatform, std::move(descriptors));
|
||||||
Program prog = shaderGen.getProgram(api);
|
Program prog = shaderGen.getProgram(api);
|
||||||
for (unsigned char i = 0; i < config.uniformNames.size(); ++i) {
|
|
||||||
prog.descriptorBindings(1, {{ config.uniformNames[i], DescriptorType::UNIFORM_BUFFER, i }});
|
Program::DescriptorBindingsInfo bindingsInfo(config.uniforms.size());
|
||||||
|
for (unsigned char i = 0; i < config.uniforms.size(); ++i) {
|
||||||
|
bindingsInfo[i] = {
|
||||||
|
config.uniforms[i].name,
|
||||||
|
config.uniforms[i].type.value_or(DescriptorType::UNIFORM_BUFFER), i };
|
||||||
}
|
}
|
||||||
|
prog.descriptorBindings(1, bindingsInfo);
|
||||||
mProgram = cleanup.add(api.createProgram(std::move(prog)));
|
mProgram = cleanup.add(api.createProgram(std::move(prog)));
|
||||||
|
|
||||||
mDescriptorSetLayout = cleanup.add(
|
mDescriptorSetLayout = cleanup.add(
|
||||||
api.createDescriptorSetLayout(DescriptorSetLayout{ kLayouts }));
|
api.createDescriptorSetLayout(DescriptorSetLayout{ kLayouts }));
|
||||||
|
}
|
||||||
|
|
||||||
mDescriptorSet = cleanup.add(api.createDescriptorSet(mDescriptorSetLayout));
|
filament::backend::DescriptorSetHandle Shader::createDescriptorSet(DriverApi& api) const {
|
||||||
|
return mCleanup.add(api.createDescriptorSet(mDescriptorSetLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
filament::backend::ProgramHandle Shader::getProgram() const {
|
filament::backend::ProgramHandle Shader::getProgram() const {
|
||||||
@@ -57,8 +71,4 @@ filament::backend::DescriptorSetLayoutHandle Shader::getDescriptorSetLayout() co
|
|||||||
return mDescriptorSetLayout;
|
return mDescriptorSetLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
filament::backend::DescriptorSetHandle Shader::getDescriptorSet() const {
|
|
||||||
return mDescriptorSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace test
|
} // namespace test
|
||||||
|
|||||||
@@ -18,14 +18,22 @@
|
|||||||
#define TNT_SHADER_H
|
#define TNT_SHADER_H
|
||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
|
#include "private/filament/SamplerInterfaceBlock.h"
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
|
struct UniformConfig {
|
||||||
|
utils::CString name;
|
||||||
|
// If not specified this will be DescriptorType::UNIFORM_BUFFER
|
||||||
|
std::optional<filament::backend::DescriptorType> type;
|
||||||
|
std::optional<filament::SamplerInterfaceBlock::SamplerInfo> samplerInfo;
|
||||||
|
};
|
||||||
|
|
||||||
// All describing a shader that should be created.
|
// All describing a shader that should be created.
|
||||||
struct ShaderConfig {
|
struct ShaderConfig {
|
||||||
std::string vertexShader;
|
std::string vertexShader;
|
||||||
std::string fragmentShader;
|
std::string fragmentShader;
|
||||||
std::vector<utils::CString> uniformNames;
|
std::vector<UniformConfig> uniforms;
|
||||||
};
|
};
|
||||||
|
|
||||||
// All values describing a uniform.
|
// All values describing a uniform.
|
||||||
@@ -35,6 +43,7 @@ struct ResolvedUniformBindingConfig {
|
|||||||
uint32_t byteOffset;
|
uint32_t byteOffset;
|
||||||
filament::backend::descriptor_set_t set;
|
filament::backend::descriptor_set_t set;
|
||||||
filament::backend::descriptor_binding_t binding;
|
filament::backend::descriptor_binding_t binding;
|
||||||
|
std::optional<filament::backend::DescriptorSetHandle> descriptorSet;
|
||||||
};
|
};
|
||||||
|
|
||||||
// An equivalent to ResolvedUniformBindingConfig with all fields optional.
|
// An equivalent to ResolvedUniformBindingConfig with all fields optional.
|
||||||
@@ -46,6 +55,7 @@ struct UniformBindingConfig {
|
|||||||
std::optional<uint32_t> byteOffset;
|
std::optional<uint32_t> byteOffset;
|
||||||
std::optional<filament::backend::descriptor_set_t> set;
|
std::optional<filament::backend::descriptor_set_t> set;
|
||||||
std::optional<filament::backend::descriptor_binding_t> binding;
|
std::optional<filament::backend::descriptor_binding_t> binding;
|
||||||
|
std::optional<filament::backend::DescriptorSetHandle> descriptorSet;
|
||||||
|
|
||||||
template<typename UniformType>
|
template<typename UniformType>
|
||||||
ResolvedUniformBindingConfig resolve();
|
ResolvedUniformBindingConfig resolve();
|
||||||
@@ -79,12 +89,14 @@ public:
|
|||||||
|
|
||||||
filament::backend::ProgramHandle getProgram() const;
|
filament::backend::ProgramHandle getProgram() const;
|
||||||
filament::backend::DescriptorSetLayoutHandle getDescriptorSetLayout() const;
|
filament::backend::DescriptorSetLayoutHandle getDescriptorSetLayout() const;
|
||||||
filament::backend::DescriptorSetHandle getDescriptorSet() const;
|
|
||||||
|
filament::backend::DescriptorSetHandle createDescriptorSet(
|
||||||
|
filament::backend::DriverApi& api) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Cleanup& mCleanup;
|
||||||
filament::backend::ProgramHandle mProgram;
|
filament::backend::ProgramHandle mProgram;
|
||||||
filament::backend::DescriptorSetLayoutHandle mDescriptorSetLayout;
|
filament::backend::DescriptorSetLayoutHandle mDescriptorSetLayout;
|
||||||
filament::backend::DescriptorSetHandle mDescriptorSet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename UniformType>
|
template<typename UniformType>
|
||||||
@@ -95,7 +107,8 @@ ResolvedUniformBindingConfig UniformBindingConfig::resolve() {
|
|||||||
.bufferSize = bufferSize.value_or(resolvedDataSize),
|
.bufferSize = bufferSize.value_or(resolvedDataSize),
|
||||||
.byteOffset = byteOffset.value_or(0),
|
.byteOffset = byteOffset.value_or(0),
|
||||||
.set = set.value_or(1),
|
.set = set.value_or(1),
|
||||||
.binding = binding.value_or(0)
|
.binding = binding.value_or(0),
|
||||||
|
.descriptorSet = descriptorSet
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,9 +133,16 @@ void Shader::bindUniform(filament::backend::DriverApi& api,
|
|||||||
UniformBindingConfig config) const {
|
UniformBindingConfig config) const {
|
||||||
auto resolvedConfig = config.resolve<UniformType>();
|
auto resolvedConfig = config.resolve<UniformType>();
|
||||||
|
|
||||||
api.updateDescriptorSetBuffer(getDescriptorSet(), resolvedConfig.binding, hwBuffer, 0,
|
filament::backend::DescriptorSetHandle descriptorSet;
|
||||||
|
if (resolvedConfig.descriptorSet.has_value()) {
|
||||||
|
descriptorSet = *resolvedConfig.descriptorSet;
|
||||||
|
} else {
|
||||||
|
descriptorSet = createDescriptorSet(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
api.updateDescriptorSetBuffer(descriptorSet, resolvedConfig.binding, hwBuffer, 0,
|
||||||
resolvedConfig.bufferSize);
|
resolvedConfig.bufferSize);
|
||||||
api.bindDescriptorSet(getDescriptorSet(), resolvedConfig.set, {});
|
api.bindDescriptorSet(descriptorSet, resolvedConfig.set, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename UniformType>
|
template<typename UniformType>
|
||||||
|
|||||||
253
filament/backend/test/SharedShaders.cpp
Normal file
253
filament/backend/test/SharedShaders.cpp
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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 "SharedShaders.h"
|
||||||
|
|
||||||
|
#include "Shader.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
using namespace filament::backend;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// A shader stored in pieces so that uniform declarations can be injected.
|
||||||
|
struct ShaderText {
|
||||||
|
std::string mPrefix;
|
||||||
|
std::string mBody;
|
||||||
|
|
||||||
|
std::string withUniform(const std::string& uniformText) const {
|
||||||
|
return absl::StrFormat("%s\n%s\n%s", mPrefix.c_str(), uniformText.c_str(), mBody.c_str());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::optional<ShaderText> GetGlslVertexShader(VertexShaderType type) {
|
||||||
|
switch (type) {
|
||||||
|
case VertexShaderType::Noop: {
|
||||||
|
return ShaderText{
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
layout(location = 0) in vec4 mesh_position;
|
||||||
|
)", R"(
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
||||||
|
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
||||||
|
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
||||||
|
gl_Position.y = -gl_Position.y;
|
||||||
|
#endif
|
||||||
|
})" };
|
||||||
|
}
|
||||||
|
case VertexShaderType::Simple: {
|
||||||
|
return ShaderText{
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
layout(location = 0) in vec4 mesh_position;
|
||||||
|
)", R"(
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(
|
||||||
|
mesh_position.xy * (params.scaleMinusOne.xy + 1.0) + params.offset.xy,
|
||||||
|
params.scaleMinusOne.z + 1.0,
|
||||||
|
1.0);
|
||||||
|
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
||||||
|
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
||||||
|
gl_Position.y = -gl_Position.y;
|
||||||
|
#endif
|
||||||
|
})" };
|
||||||
|
}
|
||||||
|
case VertexShaderType::Textured: {
|
||||||
|
return ShaderText{
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
layout(location = 0) in vec4 mesh_position;
|
||||||
|
layout(location = 0) out vec2 uv;
|
||||||
|
)", R"(
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
||||||
|
uv = (mesh_position.xy * 0.5 + 0.5);
|
||||||
|
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
||||||
|
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
||||||
|
gl_Position.y = -gl_Position.y;
|
||||||
|
#endif
|
||||||
|
})" };
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<ShaderText> GetGlslFragmentShader(FragmentShaderType type) {
|
||||||
|
switch (type) {
|
||||||
|
case FragmentShaderType::White: {
|
||||||
|
return ShaderText{
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
precision mediump int; precision highp float;
|
||||||
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
)", R"(
|
||||||
|
void main() {
|
||||||
|
fragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
})" };
|
||||||
|
}
|
||||||
|
case FragmentShaderType::SolidColored: {
|
||||||
|
return ShaderText{
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
precision mediump int; precision highp float;
|
||||||
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
)", R"(
|
||||||
|
void main() {
|
||||||
|
fragColor = params.color;
|
||||||
|
})" };
|
||||||
|
}
|
||||||
|
case FragmentShaderType::Textured: {
|
||||||
|
return ShaderText{
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
precision mediump int; precision highp float;
|
||||||
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
layout(location = 0) in vec2 uv;
|
||||||
|
)", R"(
|
||||||
|
void main() {
|
||||||
|
fragColor = texture(test_tex, uv);
|
||||||
|
})" };
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> GetGlslUniform(ShaderUniformType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ShaderUniformType::None: {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
case ShaderUniformType::Simple: {
|
||||||
|
return R"(
|
||||||
|
layout(binding = 0, set = 1) uniform Params {
|
||||||
|
highp vec4 color;
|
||||||
|
// Use scaleMinusOne instead of scale so that a 0 initialized value is a good default
|
||||||
|
highp vec4 scaleMinusOne;
|
||||||
|
highp vec4 offset;
|
||||||
|
} params;
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
case ShaderUniformType::SimpleWithPadding: {
|
||||||
|
return R"(
|
||||||
|
layout(binding = 0, set = 1) uniform Params {
|
||||||
|
highp vec4 padding[4]; // offset of 64 bytes
|
||||||
|
|
||||||
|
highp vec4 color;
|
||||||
|
// Use scaleMinusOne instead of scale so that a 0 initialized value is a good default
|
||||||
|
highp vec4 scaleMinusOne;
|
||||||
|
highp vec4 offset;
|
||||||
|
} params;
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
case ShaderUniformType::Sampler: {
|
||||||
|
return R"(
|
||||||
|
layout(location = 0, set = 1) uniform sampler2D test_tex;
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<UniformConfig> GetUniformConfig(ShaderUniformType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ShaderUniformType::None: {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
case ShaderUniformType::Simple: {
|
||||||
|
return {{ "Params" }};
|
||||||
|
}
|
||||||
|
case ShaderUniformType::SimpleWithPadding: {
|
||||||
|
return {{ "Params" }};
|
||||||
|
}
|
||||||
|
case ShaderUniformType::Sampler: {
|
||||||
|
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo{
|
||||||
|
"backend_test", "test_tex", 0,
|
||||||
|
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
|
||||||
|
return {{
|
||||||
|
"test_tex", DescriptorType::SAMPLER, samplerInfo
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderLanguage getShaderLanguage(const Backend& backend) {
|
||||||
|
switch (backend) {
|
||||||
|
case Backend::METAL:
|
||||||
|
return ShaderLanguage::MSL;
|
||||||
|
case Backend::WEBGPU:
|
||||||
|
return ShaderLanguage::WGSL;
|
||||||
|
case Backend::VULKAN:
|
||||||
|
case Backend::NOOP:
|
||||||
|
case Backend::OPENGL:
|
||||||
|
default: {
|
||||||
|
return ShaderLanguage::GLSL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Shader SharedShaders::makeShader(filament::backend::DriverApi& api, Cleanup& cleanup,
|
||||||
|
ShaderRequest request) {
|
||||||
|
std::optional<ShaderText> vertex;
|
||||||
|
std::optional<ShaderText> fragment;
|
||||||
|
std::optional<std::string> uniform;
|
||||||
|
if (getShaderLanguage(BackendTest::sBackend) != ShaderLanguage::GLSL) {
|
||||||
|
// TODO: If any shaders need backend/shader language specific shaders rather than transpiled
|
||||||
|
// versions of the GLSL shader, check environment.
|
||||||
|
}
|
||||||
|
vertex = GetGlslVertexShader(request.mVertexType);
|
||||||
|
fragment = GetGlslFragmentShader(request.mFragmentType);
|
||||||
|
uniform = GetGlslUniform(request.mUniformType);
|
||||||
|
if (vertex.has_value() && fragment.has_value() && uniform.has_value()) {
|
||||||
|
return Shader(
|
||||||
|
api, cleanup, ShaderConfig{
|
||||||
|
vertex->withUniform(*uniform), fragment->withUniform(*uniform),
|
||||||
|
GetUniformConfig(request.mUniformType)}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SharedShaders::getVertexShaderText(VertexShaderType vertex, ShaderUniformType uniform) {
|
||||||
|
std::optional<ShaderText> vertexText = GetGlslVertexShader(vertex);
|
||||||
|
std::optional<std::string> uniformText = GetGlslUniform(uniform);
|
||||||
|
if (!vertexText.has_value() || !uniformText.has_value()) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
return vertexText->withUniform(*uniformText);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SharedShaders::getFragmentShaderText(FragmentShaderType fragment,
|
||||||
|
ShaderUniformType uniform) {
|
||||||
|
std::optional<ShaderText> fragmentText = GetGlslFragmentShader(fragment);
|
||||||
|
std::optional<std::string> uniformText = GetGlslUniform(uniform);
|
||||||
|
if (!fragmentText.has_value() || !uniformText.has_value()) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
return fragmentText->withUniform(*uniformText);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
50
filament/backend/test/SharedShaders.h
Normal file
50
filament/backend/test/SharedShaders.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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_SHAREDSHADERS_H
|
||||||
|
#define TNT_SHAREDSHADERS_H
|
||||||
|
|
||||||
|
#include "Shader.h"
|
||||||
|
#include "SharedShadersConstants.h"
|
||||||
|
#include "Lifetimes.h"
|
||||||
|
#include "PlatformRunner.h"
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
enum class ShaderLanguage : uint8_t {
|
||||||
|
GLSL,
|
||||||
|
MSL,
|
||||||
|
WGSL
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ShaderRequest {
|
||||||
|
VertexShaderType mVertexType;
|
||||||
|
FragmentShaderType mFragmentType;
|
||||||
|
ShaderUniformType mUniformType;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SharedShaders {
|
||||||
|
public:
|
||||||
|
static Shader makeShader(filament::backend::DriverApi& api, Cleanup& cleanup,
|
||||||
|
ShaderRequest request);
|
||||||
|
static std::string getVertexShaderText(VertexShaderType vertex, ShaderUniformType uniform);
|
||||||
|
static std::string getFragmentShaderText(FragmentShaderType fragment,
|
||||||
|
ShaderUniformType uniform);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
|
||||||
|
#endif //TNT_SHAREDSHADERS_H
|
||||||
63
filament/backend/test/SharedShadersConstants.h
Normal file
63
filament/backend/test/SharedShadersConstants.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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_SHAREDSHADERSCONSTANTS_H
|
||||||
|
#define TNT_SHAREDSHADERSCONSTANTS_H
|
||||||
|
|
||||||
|
#include "math/mathfwd.h"
|
||||||
|
|
||||||
|
enum class ShaderUniformType : uint8_t {
|
||||||
|
None,
|
||||||
|
Simple,
|
||||||
|
SimpleWithPadding,
|
||||||
|
Sampler,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleMaterialParams {
|
||||||
|
filament::math::float4 color;
|
||||||
|
// 1.0 will be added to this value before use.
|
||||||
|
// The XY values are used to scale position inputs and the Z value is used to set the output
|
||||||
|
// position's Z value.
|
||||||
|
filament::math::float4 scaleMinusOne;
|
||||||
|
// Offset will be applied after scale
|
||||||
|
filament::math::float4 offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleWithPaddingMaterialParams {
|
||||||
|
// The associated uniform structure in the shader will have 64 bytes of padding at the beginning
|
||||||
|
// So users of this struct will need to add 64 bytes to its size and offset all uniform writes.
|
||||||
|
filament::math::float4 color;
|
||||||
|
// 1.0 will be added to this value before use.
|
||||||
|
// The XY values are used to scale position inputs and the Z value is used to set the output
|
||||||
|
// position's Z value.
|
||||||
|
filament::math::float4 scaleMinusOne;
|
||||||
|
// Offset will be applied after scale
|
||||||
|
filament::math::float4 offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class VertexShaderType : uint8_t {
|
||||||
|
Noop,
|
||||||
|
Simple,
|
||||||
|
Textured
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class FragmentShaderType : uint8_t {
|
||||||
|
White,
|
||||||
|
SolidColored,
|
||||||
|
Textured
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //TNT_SHAREDSHADERSCONSTANTS_H
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "ImageExpectations.h"
|
#include "ImageExpectations.h"
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <utils/Hash.h>
|
#include <utils/Hash.h>
|
||||||
@@ -40,48 +41,14 @@ using namespace filament::backend;
|
|||||||
using namespace filament::math;
|
using namespace filament::math;
|
||||||
using namespace utils;
|
using namespace utils;
|
||||||
|
|
||||||
struct MaterialParams {
|
|
||||||
float4 color;
|
|
||||||
float4 scale;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BlitTest : public BackendTest {
|
class BlitTest : public BackendTest {
|
||||||
public:
|
public:
|
||||||
BlitTest() : mCleanup(getDriverApi()) {}
|
BlitTest() : mCleanup(getDriverApi()) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Shader createShader();
|
|
||||||
|
|
||||||
Cleanup mCleanup;
|
Cleanup mCleanup;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* const triangleVs = R"(#version 450 core
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
layout(binding = 0, set = 1) uniform Params { highp vec4 color; highp vec4 scale; } params;
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4((mesh_position.xy + 0.5) * params.scale.xy, params.scale.z, 1.0);
|
|
||||||
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
|
||||||
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
|
||||||
gl_Position.y = -gl_Position.y;
|
|
||||||
#endif
|
|
||||||
})";
|
|
||||||
|
|
||||||
static const char* const triangleFs = R"(#version 450 core
|
|
||||||
precision mediump int; precision highp float;
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
layout(binding = 0, set = 1) uniform Params { highp vec4 color; highp vec4 scale; } params;
|
|
||||||
void main() {
|
|
||||||
fragColor = params.color;
|
|
||||||
})";
|
|
||||||
|
|
||||||
Shader BlitTest::createShader() {
|
|
||||||
return Shader(getDriverApi(), mCleanup, ShaderConfig{
|
|
||||||
.vertexShader = triangleVs,
|
|
||||||
.fragmentShader = triangleFs,
|
|
||||||
.uniformNames = { "Params" },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t toUintColor(float4 color) {
|
static uint32_t toUintColor(float4 color) {
|
||||||
color = saturate(color);
|
color = saturate(color);
|
||||||
uint32_t r = color.r * 255.0f;
|
uint32_t r = color.r * 255.0f;
|
||||||
@@ -313,7 +280,11 @@ TEST_F(BlitTest, ColorResolve) {
|
|||||||
constexpr auto kColorTexFormat = TextureFormat::RGBA8;
|
constexpr auto kColorTexFormat = TextureFormat::RGBA8;
|
||||||
constexpr int kSampleCount = 4;
|
constexpr int kSampleCount = 4;
|
||||||
|
|
||||||
Shader shader = createShader();
|
Shader shader = SharedShaders::makeShader(api, mCleanup, ShaderRequest{
|
||||||
|
.mVertexType = VertexShaderType::Simple,
|
||||||
|
.mFragmentType = FragmentShaderType::SolidColored,
|
||||||
|
.mUniformType = ShaderUniformType::Simple,
|
||||||
|
});
|
||||||
|
|
||||||
// Create a VertexBuffer, IndexBuffer, and RenderPrimitive.
|
// Create a VertexBuffer, IndexBuffer, and RenderPrimitive.
|
||||||
TrianglePrimitive const triangle(api);
|
TrianglePrimitive const triangle(api);
|
||||||
@@ -356,14 +327,15 @@ TEST_F(BlitTest, ColorResolve) {
|
|||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
state.rasterState.culling = CullingMode::NONE;
|
state.rasterState.culling = CullingMode::NONE;
|
||||||
|
|
||||||
auto ubuffer = mCleanup.add(api.createBufferObject(sizeof(MaterialParams),
|
auto ubuffer = mCleanup.add(api.createBufferObject(sizeof(SimpleMaterialParams),
|
||||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
||||||
// Draw red triangle into srcRenderTarget.
|
// Draw red triangle into srcRenderTarget.
|
||||||
shader.uploadUniform(api, ubuffer, MaterialParams{
|
shader.uploadUniform(api, ubuffer, SimpleMaterialParams{
|
||||||
.color = float4(1, 0, 0, 1),
|
.color = float4(1, 0, 0, 1),
|
||||||
.scale = float4(1, 1, 0.5, 0),
|
.scaleMinusOne = float4(0, 0, -0.5, 0),
|
||||||
|
.offset = float4(0.5, 0.5, 0, 0),
|
||||||
});
|
});
|
||||||
shader.bindUniform<MaterialParams>(api, ubuffer);
|
shader.bindUniform<SimpleMaterialParams>(api, ubuffer);
|
||||||
|
|
||||||
// FIXME: on Metal this triangle is not drawn. Can't understand why.
|
// FIXME: on Metal this triangle is not drawn. Can't understand why.
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,72 +18,18 @@
|
|||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Shaders
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
|
|
||||||
layout(location = 0) out uvec4 indices;
|
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform Params {
|
|
||||||
highp vec4 padding[4]; // offset of 64 bytes
|
|
||||||
|
|
||||||
highp vec4 color;
|
|
||||||
highp vec4 offset;
|
|
||||||
} params;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy + params.offset.xy, 0.0, 1.0);
|
|
||||||
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
|
||||||
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
|
||||||
gl_Position.y = -gl_Position.y;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
std::string fragment (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
|
|
||||||
layout(binding = 0, set = 1) uniform Params {
|
|
||||||
highp vec4 padding[4]; // offset of 64 bytes
|
|
||||||
|
|
||||||
highp vec4 color;
|
|
||||||
highp vec4 offset;
|
|
||||||
} params;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
fragColor = vec4(params.color.rgb, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
)");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
using namespace filament;
|
using namespace filament;
|
||||||
using namespace filament::backend;
|
using namespace filament::backend;
|
||||||
|
|
||||||
// In the shader, these MaterialParams are offset by 64 bytes into the uniform buffer to test buffer
|
|
||||||
// updates with offset.
|
|
||||||
struct MaterialParams {
|
|
||||||
math::float4 color;
|
|
||||||
math::float4 offset;
|
|
||||||
};
|
|
||||||
static_assert(sizeof(MaterialParams) == 8 * sizeof(float));
|
|
||||||
// Uniform config for writing MaterialParams to the shader uniform with 64 bytes of padding.
|
// Uniform config for writing MaterialParams to the shader uniform with 64 bytes of padding.
|
||||||
const UniformBindingConfig kBindingConfig = {
|
const UniformBindingConfig kBindingConfig = {
|
||||||
.dataSize = sizeof(MaterialParams),
|
.dataSize = sizeof(SimpleMaterialParams),
|
||||||
.bufferSize = sizeof(MaterialParams) + 64,
|
.bufferSize = sizeof(SimpleMaterialParams) + 64,
|
||||||
.byteOffset = 64
|
.byteOffset = 64
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,8 +39,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
Shader createShader() {
|
Shader createShader() {
|
||||||
return Shader(getDriverApi(), mCleanup, ShaderConfig{
|
return SharedShaders::makeShader(getDriverApi(), mCleanup, ShaderRequest{
|
||||||
vertex, fragment, {"Params"}
|
.mVertexType = VertexShaderType::Simple,
|
||||||
|
.mFragmentType = FragmentShaderType::SolidColored,
|
||||||
|
.mUniformType = ShaderUniformType::SimpleWithPadding
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +77,7 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
|||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
fullViewport(params);
|
fullViewport(params);
|
||||||
params.flags.clear = TargetBufferFlags::COLOR;
|
params.flags.clear = TargetBufferFlags::COLOR;
|
||||||
params.clearColor = {0.f, 1.f, 0.f, 1.f};
|
params.clearColor = { 0.f, 1.f, 0.f, 1.f };
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
@@ -144,17 +92,18 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
|||||||
// Create a uniform buffer.
|
// Create a uniform buffer.
|
||||||
// We use STATIC here, even though the buffer is updated, to force the Metal backend to use
|
// We use STATIC here, even though the buffer is updated, to force the Metal backend to use
|
||||||
// a GPU buffer, which is more interesting to test.
|
// a GPU buffer, which is more interesting to test.
|
||||||
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(MaterialParams) + 64,
|
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(SimpleMaterialParams) + 64,
|
||||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
||||||
|
|
||||||
shader.bindUniform<MaterialParams>(api, ubuffer, kBindingConfig);
|
shader.bindUniform<SimpleMaterialParams>(api, ubuffer, kBindingConfig);
|
||||||
|
|
||||||
api.startCapture(0);
|
api.startCapture(0);
|
||||||
|
|
||||||
// Upload the uniform, but with an offset to accommodate the padding in the shader's
|
// Upload the uniform, but with an offset to accommodate the padding in the shader's
|
||||||
// uniform definition.
|
// uniform definition.
|
||||||
shader.uploadUniform(api, ubuffer, kBindingConfig, MaterialParams{
|
shader.uploadUniform(api, ubuffer, kBindingConfig, SimpleMaterialParams{
|
||||||
.color = { 1.0f, 1.0f, 1.0f, 1.0f },
|
.color = { 1.0f, 1.0f, 1.0f, 1.0f },
|
||||||
|
.scaleMinusOne = { 0.0, 0.0, 0.0, 0.0 },
|
||||||
.offset = { 0.0f, 0.0f, 0.0f, 0.0f }
|
.offset = { 0.0f, 0.0f, 0.0f, 0.0f }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -165,19 +114,21 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
|||||||
size_t triangleIndex = 0;
|
size_t triangleIndex = 0;
|
||||||
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
|
for (float i = -1.0f; i < 1.0f; i += 0.2f) {
|
||||||
const float low = i, high = i + 0.2;
|
const float low = i, high = i + 0.2;
|
||||||
const filament::math::float2 v[3] {{low, low}, {high, low}, {low, high}};
|
const filament::math::float2 v[3]{{ low, low },
|
||||||
|
{ high, low },
|
||||||
|
{ low, high }};
|
||||||
triangle.updateVertices(v);
|
triangle.updateVertices(v);
|
||||||
|
|
||||||
if (updateIndices) {
|
if (updateIndices) {
|
||||||
if (triangleIndex % 2 == 0) {
|
if (triangleIndex % 2 == 0) {
|
||||||
// Upload each index separately, to test offsets.
|
// Upload each index separately, to test offsets.
|
||||||
const TrianglePrimitive::index_type i[3] {0, 1, 2};
|
const TrianglePrimitive::index_type i[3]{ 0, 1, 2 };
|
||||||
triangle.updateIndices(i + 0, 1, 0);
|
triangle.updateIndices(i + 0, 1, 0);
|
||||||
triangle.updateIndices(i + 1, 1, 1);
|
triangle.updateIndices(i + 1, 1, 1);
|
||||||
triangle.updateIndices(i + 2, 1, 2);
|
triangle.updateIndices(i + 2, 1, 2);
|
||||||
} else {
|
} else {
|
||||||
// This effectively hides this triangle.
|
// This effectively hides this triangle.
|
||||||
const TrianglePrimitive::index_type i[3] {0, 0, 0};
|
const TrianglePrimitive::index_type i[3]{ 0, 0, 0 };
|
||||||
triangle.updateIndices(i);
|
triangle.updateIndices(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,28 +171,29 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
|
|||||||
// Create a uniform buffer.
|
// Create a uniform buffer.
|
||||||
// We use STATIC here, even though the buffer is updated, to force the Metal backend to use a
|
// We use STATIC here, even though the buffer is updated, to force the Metal backend to use a
|
||||||
// GPU buffer, which is more interesting to test.
|
// GPU buffer, which is more interesting to test.
|
||||||
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(MaterialParams) + 64,
|
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(SimpleMaterialParams) + 64,
|
||||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
||||||
|
|
||||||
shader.bindUniform<MaterialParams>(api, ubuffer, kBindingConfig);
|
shader.bindUniform<SimpleMaterialParams>(api, ubuffer, kBindingConfig);
|
||||||
|
|
||||||
// Create a render target.
|
// Create a render target.
|
||||||
auto colorTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
auto colorTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||||
TextureFormat::RGBA8, 1, 512, 512, 1, TextureUsage::COLOR_ATTACHMENT));
|
TextureFormat::RGBA8, 1, 512, 512, 1, TextureUsage::COLOR_ATTACHMENT));
|
||||||
auto renderTarget = cleanup.add(api.createRenderTarget(
|
auto renderTarget = cleanup.add(api.createRenderTarget(
|
||||||
TargetBufferFlags::COLOR0, 512, 512, 1, 0, {{colorTexture}}, {}, {}));
|
TargetBufferFlags::COLOR0, 512, 512, 1, 0, {{ colorTexture }}, {}, {}));
|
||||||
|
|
||||||
// Upload uniforms for the first triangle.
|
// Upload uniforms for the first triangle.
|
||||||
// Upload the uniform, but with an offset to accommodate the padding in the shader's
|
// Upload the uniform, but with an offset to accommodate the padding in the shader's
|
||||||
// uniform definition.
|
// uniform definition.
|
||||||
shader.uploadUniform(api, ubuffer, kBindingConfig, MaterialParams{
|
shader.uploadUniform(api, ubuffer, kBindingConfig, SimpleMaterialParams{
|
||||||
.color = { 1.0f, 0.0f, 0.5f, 1.0f },
|
.color = { 1.0f, 0.0f, 0.5f, 1.0f },
|
||||||
|
.scaleMinusOne = { 0.0f, 0.0f, 0.0f, 0.0f },
|
||||||
.offset = { 0.0f, 0.0f, 0.0f, 0.0f }
|
.offset = { 0.0f, 0.0f, 0.0f, 0.0f }
|
||||||
});
|
});
|
||||||
|
|
||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
params.flags.clear = TargetBufferFlags::COLOR;
|
params.flags.clear = TargetBufferFlags::COLOR;
|
||||||
params.clearColor = {0.f, 0.f, 1.f, 1.f};
|
params.clearColor = { 0.f, 0.f, 1.f, 1.f };
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
params.viewport.height = 512;
|
params.viewport.height = 512;
|
||||||
@@ -250,18 +202,18 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
|
|||||||
renderTarget, swapChain, shader.getProgram(), params);
|
renderTarget, swapChain, shader.getProgram(), params);
|
||||||
|
|
||||||
// Upload uniforms for the second triangle. To test partial buffer updates, we'll only update
|
// Upload uniforms for the second triangle. To test partial buffer updates, we'll only update
|
||||||
// color.b, color.a, offset.x, and offset.y.
|
// color.b, color.a, scaleMinusOne, offset.x, and offset.y.
|
||||||
shader.uploadUniform(api, ubuffer, UniformBindingConfig{
|
const UniformBindingConfig partialBindingConfig = {
|
||||||
.dataSize = sizeof(std::array<float, 4>),
|
.dataSize = sizeof(float) * 8,
|
||||||
.bufferSize = kBindingConfig.bufferSize,
|
.bufferSize = sizeof(SimpleMaterialParams) + 64,
|
||||||
.byteOffset = *kBindingConfig.byteOffset + offsetof(MaterialParams, color.b),
|
.byteOffset = 64 + offsetof(SimpleMaterialParams, color.b)
|
||||||
},
|
};
|
||||||
std::array<float, 4>{
|
shader.uploadUniform(api, ubuffer, partialBindingConfig,
|
||||||
// color.b, color.a
|
std::array<float, 8>{
|
||||||
1.0f, 1.0f,
|
1.0f, 1.0f, // color.b, color.a
|
||||||
// offset.x, offset.y
|
0.0f, 0.0f, 0.0f, 0.0f, // scale
|
||||||
0.5f, 0.5f }
|
0.5f, 0.5f // offset.x, offset.y
|
||||||
);
|
});
|
||||||
|
|
||||||
params.flags.clear = TargetBufferFlags::NONE;
|
params.flags.clear = TargetBufferFlags::NONE;
|
||||||
params.flags.discardStart = TargetBufferFlags::NONE;
|
params.flags.discardStart = TargetBufferFlags::NONE;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
@@ -96,16 +96,6 @@ struct MaterialParams {
|
|||||||
float unused;
|
float unused;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void uploadUniforms(DriverApi& dapi, Handle<HwBufferObject> ubh, MaterialParams params) {
|
|
||||||
MaterialParams* tmp = new MaterialParams(params);
|
|
||||||
auto cb = [](void* buffer, size_t size, void* user) {
|
|
||||||
MaterialParams* sp = (MaterialParams*) buffer;
|
|
||||||
delete sp;
|
|
||||||
};
|
|
||||||
BufferDescriptor bd(tmp, sizeof(MaterialParams), cb);
|
|
||||||
dapi.updateBufferObject(ubh, std::move(bd), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dumpScreenshot(DriverApi& dapi, Handle<HwRenderTarget> rt) {
|
static void dumpScreenshot(DriverApi& dapi, Handle<HwRenderTarget> rt) {
|
||||||
const size_t size = kTexWidth * kTexHeight * 4;
|
const size_t size = kTexWidth * kTexHeight * 4;
|
||||||
void* buffer = calloc(1, size);
|
void* buffer = calloc(1, size);
|
||||||
@@ -140,38 +130,13 @@ TEST_F(BackendTest, FeedbackLoops) {
|
|||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
|
|
||||||
// Create a program.
|
// Create a program.
|
||||||
ProgramHandle program;
|
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||||
{
|
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
|
||||||
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
|
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
|
||||||
filamat::DescriptorSets descriptors;
|
Shader shader = Shader(api, cleanup, ShaderConfig {
|
||||||
descriptors[1] = {
|
.vertexShader = fullscreenVs,
|
||||||
{ "test_tex", { DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 },
|
.fragmentShader = fullscreenFs,
|
||||||
samplerInfo },
|
.uniforms = {{"test_tex", DescriptorType::SAMPLER, samplerInfo}, {"Params"}}
|
||||||
{ "Params", { DescriptorType::UNIFORM_BUFFER, ShaderStageFlags::FRAGMENT, 1 }, {} }
|
});
|
||||||
};
|
|
||||||
ShaderGenerator shaderGen(fullscreenVs, fullscreenFs, sBackend, sIsMobilePlatform,
|
|
||||||
std::move(descriptors));
|
|
||||||
Program prog = shaderGen.getProgram(api);
|
|
||||||
prog.descriptorBindings(1, {
|
|
||||||
{ "test_tex", DescriptorType::SAMPLER, 0 },
|
|
||||||
{ "Params", DescriptorType::UNIFORM_BUFFER, 1 }
|
|
||||||
});
|
|
||||||
program = cleanup.add(api.createProgram(std::move(prog)));
|
|
||||||
}
|
|
||||||
|
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = cleanup.add(api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
DescriptorType::UNIFORM_BUFFER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 1,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}}));
|
|
||||||
|
|
||||||
|
|
||||||
TrianglePrimitive const triangle(getDriverApi());
|
TrianglePrimitive const triangle(getDriverApi());
|
||||||
|
|
||||||
@@ -218,8 +183,8 @@ TEST_F(BackendTest, FeedbackLoops) {
|
|||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
state.program = program;
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { descriptorSetLayout };
|
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
||||||
|
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
@@ -233,20 +198,24 @@ TEST_F(BackendTest, FeedbackLoops) {
|
|||||||
params.viewport.width = kTexWidth >> targetLevel;
|
params.viewport.width = kTexWidth >> targetLevel;
|
||||||
params.viewport.height = kTexHeight >> targetLevel;
|
params.viewport.height = kTexHeight >> targetLevel;
|
||||||
|
|
||||||
|
auto descriptorSet = shader.createDescriptorSet(api);
|
||||||
auto textureView = passCleanup.add(api.createTextureView(texture, sourceLevel, 1));
|
auto textureView = passCleanup.add(api.createTextureView(texture, sourceLevel, 1));
|
||||||
DescriptorSetHandle descriptorSet = passCleanup.add(api.createDescriptorSet(descriptorSetLayout));
|
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, textureView, {
|
api.updateDescriptorSetTexture(descriptorSet, 0, textureView, {
|
||||||
.filterMag = SamplerMagFilter::LINEAR,
|
.filterMag = SamplerMagFilter::LINEAR,
|
||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||||
});
|
});
|
||||||
api.updateDescriptorSetBuffer(descriptorSet, 1, ubuffer, 0, sizeof(MaterialParams));
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
|
||||||
|
|
||||||
uploadUniforms(getDriverApi(), ubuffer, {
|
UniformBindingConfig uniformBinding{
|
||||||
|
.binding = 1,
|
||||||
|
.descriptorSet = descriptorSet
|
||||||
|
};
|
||||||
|
shader.bindUniform<MaterialParams>(api, ubuffer, uniformBinding);
|
||||||
|
shader.uploadUniform(api, ubuffer, uniformBinding, MaterialParams{
|
||||||
.fbWidth = float(params.viewport.width),
|
.fbWidth = float(params.viewport.width),
|
||||||
.fbHeight = float(params.viewport.height),
|
.fbHeight = float(params.viewport.height),
|
||||||
.sourceLevel = float(sourceLevel),
|
.sourceLevel = float(sourceLevel),
|
||||||
});
|
});
|
||||||
|
|
||||||
api.beginRenderPass(renderTargets[targetLevel], params);
|
api.beginRenderPass(renderTargets[targetLevel], params);
|
||||||
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
|
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
|
||||||
api.endRenderPass();
|
api.endRenderPass();
|
||||||
@@ -262,20 +231,24 @@ TEST_F(BackendTest, FeedbackLoops) {
|
|||||||
params.viewport.width = kTexWidth >> targetLevel;
|
params.viewport.width = kTexWidth >> targetLevel;
|
||||||
params.viewport.height = kTexHeight >> targetLevel;
|
params.viewport.height = kTexHeight >> targetLevel;
|
||||||
|
|
||||||
|
auto descriptorSet = shader.createDescriptorSet(api);
|
||||||
auto textureView = passCleanup.add(api.createTextureView(texture, sourceLevel, 1));
|
auto textureView = passCleanup.add(api.createTextureView(texture, sourceLevel, 1));
|
||||||
DescriptorSetHandle descriptorSet = passCleanup.add(api.createDescriptorSet(descriptorSetLayout));
|
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, textureView, {
|
api.updateDescriptorSetTexture(descriptorSet, 0, textureView, {
|
||||||
.filterMag = SamplerMagFilter::LINEAR,
|
.filterMag = SamplerMagFilter::LINEAR,
|
||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||||
});
|
});
|
||||||
api.updateDescriptorSetBuffer(descriptorSet, 1, ubuffer, 0, sizeof(MaterialParams));
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
|
||||||
|
|
||||||
uploadUniforms(getDriverApi(), ubuffer, {
|
UniformBindingConfig uniformBinding{
|
||||||
.fbWidth = float(params.viewport.width),
|
.binding = 1,
|
||||||
.fbHeight = float(params.viewport.height),
|
.descriptorSet = descriptorSet
|
||||||
.sourceLevel = float(sourceLevel),
|
};
|
||||||
|
shader.bindUniform<MaterialParams>(api, ubuffer, uniformBinding);
|
||||||
|
shader.uploadUniform(api, ubuffer, uniformBinding, MaterialParams{
|
||||||
|
.fbWidth = float(params.viewport.width),
|
||||||
|
.fbHeight = float(params.viewport.height),
|
||||||
|
.sourceLevel = float(sourceLevel),
|
||||||
});
|
});
|
||||||
|
|
||||||
api.beginRenderPass(renderTargets[targetLevel], params);
|
api.beginRenderPass(renderTargets[targetLevel], params);
|
||||||
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
|
api.draw(state, triangle.getRenderPrimitive(), 0, 3, 1);
|
||||||
api.endRenderPass();
|
api.endRenderPass();
|
||||||
|
|||||||
@@ -18,16 +18,14 @@
|
|||||||
|
|
||||||
#include "BackendTestUtils.h"
|
#include "BackendTestUtils.h"
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "SharedShaders.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
#include <backend/Handle.h>
|
#include <backend/Handle.h>
|
||||||
|
|
||||||
#include "private/filament/SamplerInterfaceBlock.h"
|
#include "private/filament/SamplerInterfaceBlock.h"
|
||||||
|
|
||||||
#include <math/half.h>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@@ -42,19 +40,6 @@ namespace {
|
|||||||
// Shaders
|
// Shaders
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
|
||||||
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
|
||||||
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
|
||||||
gl_Position.y *= -1.0f;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
std::string fragmentTemplate (R"(#version 450 core
|
std::string fragmentTemplate (R"(#version 450 core
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec4 fragColor;
|
||||||
@@ -119,6 +104,15 @@ namespace test {
|
|||||||
|
|
||||||
template<typename componentType> inline componentType getMaxValue();
|
template<typename componentType> inline componentType getMaxValue();
|
||||||
|
|
||||||
|
class LoadImageTest : public BackendTest {
|
||||||
|
public:
|
||||||
|
LoadImageTest() {
|
||||||
|
mVertexShader = SharedShaders::getVertexShaderText(VertexShaderType::Noop,
|
||||||
|
ShaderUniformType::None);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string mVertexShader;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
inline std::string stringReplace(const std::string& find, const std::string& replace,
|
inline std::string stringReplace(const std::string& find, const std::string& replace,
|
||||||
@@ -216,7 +210,7 @@ static SamplerFormat getSamplerFormat(TextureFormat textureFormat) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BackendTest, UpdateImage2D) {
|
TEST_F(LoadImageTest, UpdateImage2D) {
|
||||||
|
|
||||||
// All of these test cases should result in the same rendered image, and thus the same hash.
|
// All of these test cases should result in the same rendered image, and thus the same hash.
|
||||||
static const uint32_t expectedHash = 3644679986;
|
static const uint32_t expectedHash = 3644679986;
|
||||||
@@ -306,28 +300,14 @@ TEST_F(BackendTest, UpdateImage2D) {
|
|||||||
// Create a program.
|
// Create a program.
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||||
SamplerType::SAMPLER_2D, getSamplerFormat(t.textureFormat), Precision::HIGH, false };
|
SamplerType::SAMPLER_2D, getSamplerFormat(t.textureFormat), Precision::HIGH, false };
|
||||||
filamat::DescriptorSets descriptors;
|
|
||||||
descriptors[1] = { { "test_tex", { DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 },
|
|
||||||
samplerInfo } };
|
|
||||||
|
|
||||||
std::string const fragment = stringReplace("{samplerType}",
|
std::string const fragment = stringReplace("{samplerType}",
|
||||||
getSamplerTypeName(t.textureFormat), fragmentTemplate);
|
getSamplerTypeName(t.textureFormat), fragmentTemplate);
|
||||||
ShaderGenerator shaderGen(
|
Shader shader(api, cleanup, ShaderConfig{
|
||||||
vertex, fragment, sBackend, sIsMobilePlatform, std::move(descriptors));
|
.vertexShader = mVertexShader,
|
||||||
|
.fragmentShader= fragment,
|
||||||
Program prog = shaderGen.getProgram(api);
|
.uniforms = {{"test_tex", DescriptorType::SAMPLER, samplerInfo}}
|
||||||
prog.descriptorBindings(1, {{"test_tex", DescriptorType::SAMPLER, 0}});
|
});
|
||||||
|
|
||||||
ProgramHandle const program = cleanup.add(api.createProgram(std::move(prog)));
|
|
||||||
|
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = cleanup.add(api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}}));
|
|
||||||
|
|
||||||
DescriptorSetHandle descriptorSet = cleanup.add(api.createDescriptorSet(descriptorSetLayout));
|
|
||||||
|
|
||||||
// Create a Texture.
|
// Create a Texture.
|
||||||
auto usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
auto usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
||||||
@@ -349,14 +329,15 @@ TEST_F(BackendTest, UpdateImage2D) {
|
|||||||
checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 512, t.bufferPadding));
|
checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 512, t.bufferPadding));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DescriptorSetHandle descriptorSet = shader.createDescriptorSet(api);
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
||||||
.filterMag = SamplerMagFilter::NEAREST,
|
.filterMag = SamplerMagFilter::NEAREST,
|
||||||
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 1, {});
|
||||||
|
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, descriptorSetLayout }},
|
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
||||||
defaultRenderTarget, swapChain, program);
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
readPixelsAndAssertHash(t.name, 512, 512, defaultRenderTarget, expectedHash);
|
readPixelsAndAssertHash(t.name, 512, 512, defaultRenderTarget, expectedHash);
|
||||||
|
|
||||||
@@ -370,8 +351,9 @@ TEST_F(BackendTest, UpdateImage2D) {
|
|||||||
flushAndWait();
|
flushAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BackendTest, UpdateImageSRGB) {
|
TEST_F(LoadImageTest, UpdateImageSRGB) {
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
|
Cleanup cleanup(api);
|
||||||
api.startCapture();
|
api.startCapture();
|
||||||
|
|
||||||
PixelDataFormat const pixelFormat = PixelDataFormat::RGBA;
|
PixelDataFormat const pixelFormat = PixelDataFormat::RGBA;
|
||||||
@@ -379,36 +361,23 @@ TEST_F(BackendTest, UpdateImageSRGB) {
|
|||||||
TextureFormat const textureFormat = TextureFormat::SRGB8_A8;
|
TextureFormat const textureFormat = TextureFormat::SRGB8_A8;
|
||||||
|
|
||||||
// Create a platform-specific SwapChain and make it current.
|
// Create a platform-specific SwapChain and make it current.
|
||||||
auto swapChain = createSwapChain();
|
auto swapChain = cleanup.add(createSwapChain());
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
auto defaultRenderTarget = api.createDefaultRenderTarget(0);
|
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
||||||
|
|
||||||
// Create a program.
|
// Create a program.
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||||
SamplerType::SAMPLER_2D, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
SamplerType::SAMPLER_2D, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
||||||
filamat::DescriptorSets descriptors;
|
|
||||||
descriptors[1] = { { "test_tex", { DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 },
|
|
||||||
samplerInfo } };
|
|
||||||
|
|
||||||
std::string const fragment = stringReplace("{samplerType}",
|
std::string const fragment = stringReplace("{samplerType}",
|
||||||
getSamplerTypeName(textureFormat), fragmentTemplate);
|
getSamplerTypeName(textureFormat), fragmentTemplate);
|
||||||
ShaderGenerator shaderGen(
|
Shader shader(api, cleanup, ShaderConfig{
|
||||||
vertex, fragment, sBackend, sIsMobilePlatform, std::move(descriptors));
|
.vertexShader = mVertexShader, .fragmentShader = fragment, .uniforms = {{
|
||||||
Program prog = shaderGen.getProgram(api);
|
"text_tex", DescriptorType::SAMPLER, samplerInfo
|
||||||
prog.descriptorBindings(1, {{"test_tex", DescriptorType::SAMPLER, 0}});
|
}}});
|
||||||
ProgramHandle const program = api.createProgram(std::move(prog));
|
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}});
|
|
||||||
|
|
||||||
DescriptorSetHandle descriptorSet = api.createDescriptorSet(descriptorSetLayout);
|
|
||||||
|
|
||||||
// Create a texture.
|
// Create a texture.
|
||||||
Handle<HwTexture> const texture = api.createTexture(SamplerType::SAMPLER_2D, 1,
|
Handle<HwTexture> const texture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||||
textureFormat, 1, 512, 512, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE);
|
textureFormat, 1, 512, 512, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE));
|
||||||
|
|
||||||
// Create image data.
|
// Create image data.
|
||||||
size_t components; int bpp;
|
size_t components; int bpp;
|
||||||
@@ -436,6 +405,7 @@ TEST_F(BackendTest, UpdateImageSRGB) {
|
|||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
|
|
||||||
// Update samplers.
|
// Update samplers.
|
||||||
|
DescriptorSetHandle descriptorSet = shader.createDescriptorSet(api);
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
||||||
.filterMag = SamplerMagFilter::LINEAR,
|
.filterMag = SamplerMagFilter::LINEAR,
|
||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||||
@@ -443,8 +413,8 @@ TEST_F(BackendTest, UpdateImageSRGB) {
|
|||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 1, {});
|
||||||
|
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, descriptorSetLayout }},
|
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
||||||
defaultRenderTarget, swapChain, program);
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
static const uint32_t expectedHash = 359858623;
|
static const uint32_t expectedHash = 359858623;
|
||||||
readPixelsAndAssertHash("UpdateImageSRGB", 512, 512, defaultRenderTarget, expectedHash);
|
readPixelsAndAssertHash("UpdateImageSRGB", 512, 512, defaultRenderTarget, expectedHash);
|
||||||
@@ -453,21 +423,14 @@ TEST_F(BackendTest, UpdateImageSRGB) {
|
|||||||
api.commit(swapChain);
|
api.commit(swapChain);
|
||||||
api.endFrame(0);
|
api.endFrame(0);
|
||||||
|
|
||||||
api.destroyDescriptorSet(descriptorSet);
|
|
||||||
api.destroyDescriptorSetLayout(descriptorSetLayout);
|
|
||||||
api.destroyProgram(program);
|
|
||||||
api.destroySwapChain(swapChain);
|
|
||||||
api.destroyRenderTarget(defaultRenderTarget);
|
|
||||||
|
|
||||||
// This ensures all driver commands have finished before exiting the test.
|
// This ensures all driver commands have finished before exiting the test.
|
||||||
api.finish();
|
api.finish();
|
||||||
api.stopCapture();
|
api.stopCapture();
|
||||||
|
|
||||||
flushAndWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BackendTest, UpdateImageMipLevel) {
|
TEST_F(LoadImageTest, UpdateImageMipLevel) {
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
|
Cleanup cleanup(api);
|
||||||
api.startCapture();
|
api.startCapture();
|
||||||
|
|
||||||
PixelDataFormat pixelFormat = PixelDataFormat::RGBA;
|
PixelDataFormat pixelFormat = PixelDataFormat::RGBA;
|
||||||
@@ -475,38 +438,27 @@ TEST_F(BackendTest, UpdateImageMipLevel) {
|
|||||||
TextureFormat textureFormat = TextureFormat::RGBA32F;
|
TextureFormat textureFormat = TextureFormat::RGBA32F;
|
||||||
|
|
||||||
// Create a platform-specific SwapChain and make it current.
|
// Create a platform-specific SwapChain and make it current.
|
||||||
auto swapChain = createSwapChain();
|
auto swapChain = cleanup.add(createSwapChain());
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
auto defaultRenderTarget = api.createDefaultRenderTarget(0);
|
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
||||||
|
|
||||||
// Create a program.
|
// Create a program.
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||||
SamplerType::SAMPLER_2D, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
SamplerType::SAMPLER_2D, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
||||||
filamat::DescriptorSets descriptors;
|
|
||||||
descriptors[1] = { { "test_tex", { DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 },
|
|
||||||
samplerInfo } };
|
|
||||||
std::string const fragment = stringReplace("{samplerType}",
|
std::string const fragment = stringReplace("{samplerType}",
|
||||||
getSamplerTypeName(textureFormat), fragmentUpdateImageMip);
|
getSamplerTypeName(textureFormat), fragmentUpdateImageMip);
|
||||||
ShaderGenerator shaderGen(
|
Shader shader(api, cleanup, ShaderConfig {
|
||||||
vertex, fragment, sBackend, sIsMobilePlatform, std::move(descriptors));
|
.vertexShader = mVertexShader,
|
||||||
Program prog = shaderGen.getProgram(api);
|
.fragmentShader = fragment,
|
||||||
prog.descriptorBindings(1, {{"test_tex", DescriptorType::SAMPLER, 0}});
|
.uniforms = {{"test_tex", DescriptorType::SAMPLER, samplerInfo}}
|
||||||
ProgramHandle const program = api.createProgram(std::move(prog));
|
});
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}});
|
|
||||||
|
|
||||||
DescriptorSetHandle descriptorSet = api.createDescriptorSet(descriptorSetLayout);
|
|
||||||
|
|
||||||
// Create a texture with 3 mip levels.
|
// Create a texture with 3 mip levels.
|
||||||
// Base level: 1024
|
// Base level: 1024
|
||||||
// Level 1: 512 <-- upload data and sample from this level
|
// Level 1: 512 <-- upload data and sample from this level
|
||||||
// Level 2: 256
|
// Level 2: 256
|
||||||
Handle<HwTexture> texture = api.createTexture(SamplerType::SAMPLER_2D, 3,
|
Handle<HwTexture> texture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 3,
|
||||||
textureFormat, 1, 1024, 1024, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE);
|
textureFormat, 1, 1024, 1024, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE));
|
||||||
|
|
||||||
// Create image data.
|
// Create image data.
|
||||||
PixelBufferDescriptor descriptor = checkerboardPixelBuffer(pixelFormat, pixelType, 512);
|
PixelBufferDescriptor descriptor = checkerboardPixelBuffer(pixelFormat, pixelType, 512);
|
||||||
@@ -515,6 +467,7 @@ TEST_F(BackendTest, UpdateImageMipLevel) {
|
|||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
|
|
||||||
// Update samplers.
|
// Update samplers.
|
||||||
|
DescriptorSetHandle descriptorSet = shader.createDescriptorSet(api);
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
||||||
.filterMag = SamplerMagFilter::LINEAR,
|
.filterMag = SamplerMagFilter::LINEAR,
|
||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||||
@@ -522,8 +475,8 @@ TEST_F(BackendTest, UpdateImageMipLevel) {
|
|||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 1, {});
|
||||||
|
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, descriptorSetLayout }},
|
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
||||||
defaultRenderTarget, swapChain, program);
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
static const uint32_t expectedHash = 3644679986;
|
static const uint32_t expectedHash = 3644679986;
|
||||||
readPixelsAndAssertHash("UpdateImageMipLevel", 512, 512, defaultRenderTarget, expectedHash);
|
readPixelsAndAssertHash("UpdateImageMipLevel", 512, 512, defaultRenderTarget, expectedHash);
|
||||||
@@ -532,21 +485,14 @@ TEST_F(BackendTest, UpdateImageMipLevel) {
|
|||||||
api.commit(swapChain);
|
api.commit(swapChain);
|
||||||
api.endFrame(0);
|
api.endFrame(0);
|
||||||
|
|
||||||
api.destroyDescriptorSet(descriptorSet);
|
|
||||||
api.destroyDescriptorSetLayout(descriptorSetLayout);
|
|
||||||
api.destroyProgram(program);
|
|
||||||
api.destroySwapChain(swapChain);
|
|
||||||
api.destroyRenderTarget(defaultRenderTarget);
|
|
||||||
|
|
||||||
// This ensures all driver commands have finished before exiting the test.
|
// This ensures all driver commands have finished before exiting the test.
|
||||||
api.finish();
|
api.finish();
|
||||||
api.stopCapture();
|
api.stopCapture();
|
||||||
|
|
||||||
flushAndWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BackendTest, UpdateImage3D) {
|
TEST_F(LoadImageTest, UpdateImage3D) {
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
|
Cleanup cleanup(api);
|
||||||
api.startCapture();
|
api.startCapture();
|
||||||
|
|
||||||
PixelDataFormat pixelFormat = PixelDataFormat::RGBA;
|
PixelDataFormat pixelFormat = PixelDataFormat::RGBA;
|
||||||
@@ -556,35 +502,24 @@ TEST_F(BackendTest, UpdateImage3D) {
|
|||||||
TextureUsage usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
TextureUsage usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
||||||
|
|
||||||
// Create a platform-specific SwapChain and make it current.
|
// Create a platform-specific SwapChain and make it current.
|
||||||
auto swapChain = createSwapChain();
|
auto swapChain = cleanup.add(createSwapChain());
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
auto defaultRenderTarget = api.createDefaultRenderTarget(0);
|
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
||||||
|
|
||||||
// Create a program.
|
// Create a program.
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||||
SamplerType::SAMPLER_2D_ARRAY, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
SamplerType::SAMPLER_2D_ARRAY, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
||||||
filamat::DescriptorSets descriptors;
|
|
||||||
descriptors[1] = { { "test_tex", { DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 },
|
|
||||||
samplerInfo } };
|
|
||||||
std::string fragment = stringReplace("{samplerType}",
|
std::string fragment = stringReplace("{samplerType}",
|
||||||
getSamplerTypeName(samplerType), fragmentUpdateImage3DTemplate);
|
getSamplerTypeName(samplerType), fragmentUpdateImage3DTemplate);
|
||||||
ShaderGenerator shaderGen(
|
Shader shader(api, cleanup, ShaderConfig {
|
||||||
vertex, fragment, sBackend, sIsMobilePlatform, std::move(descriptors));
|
.vertexShader = mVertexShader,
|
||||||
Program prog = shaderGen.getProgram(api);
|
.fragmentShader = fragment,
|
||||||
prog.descriptorBindings(1, {{ "test_tex", DescriptorType::SAMPLER, 0 }});
|
.uniforms = {{"test_tex", DescriptorType::SAMPLER, samplerInfo}}
|
||||||
ProgramHandle const program = api.createProgram(std::move(prog));
|
});
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}});
|
|
||||||
|
|
||||||
DescriptorSetHandle descriptorSet = api.createDescriptorSet(descriptorSetLayout);
|
|
||||||
|
|
||||||
// Create a texture.
|
// Create a texture.
|
||||||
Handle<HwTexture> texture = api.createTexture(samplerType, 1,
|
Handle<HwTexture> texture = cleanup.add(api.createTexture(samplerType, 1,
|
||||||
textureFormat, 1, 512, 512, 4, usage);
|
textureFormat, 1, 512, 512, 4, usage));
|
||||||
|
|
||||||
// Create image data for all 4 layers.
|
// Create image data for all 4 layers.
|
||||||
size_t components; int bpp;
|
size_t components; int bpp;
|
||||||
@@ -606,6 +541,7 @@ TEST_F(BackendTest, UpdateImage3D) {
|
|||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
|
|
||||||
// Update samplers.
|
// Update samplers.
|
||||||
|
DescriptorSetHandle descriptorSet = shader.createDescriptorSet(api);
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {
|
||||||
.filterMag = SamplerMagFilter::LINEAR,
|
.filterMag = SamplerMagFilter::LINEAR,
|
||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||||
@@ -613,8 +549,8 @@ TEST_F(BackendTest, UpdateImage3D) {
|
|||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 1, {});
|
||||||
|
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, descriptorSetLayout }},
|
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
||||||
defaultRenderTarget, swapChain, program);
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
static const uint32_t expectedHash = 3644679986;
|
static const uint32_t expectedHash = 3644679986;
|
||||||
readPixelsAndAssertHash("UpdateImage3D", 512, 512, defaultRenderTarget, expectedHash);
|
readPixelsAndAssertHash("UpdateImage3D", 512, 512, defaultRenderTarget, expectedHash);
|
||||||
@@ -623,17 +559,9 @@ TEST_F(BackendTest, UpdateImage3D) {
|
|||||||
api.commit(swapChain);
|
api.commit(swapChain);
|
||||||
api.endFrame(0);
|
api.endFrame(0);
|
||||||
|
|
||||||
api.destroyDescriptorSet(descriptorSet);
|
|
||||||
api.destroyDescriptorSetLayout(descriptorSetLayout);
|
|
||||||
api.destroyProgram(program);
|
|
||||||
api.destroySwapChain(swapChain);
|
|
||||||
api.destroyRenderTarget(defaultRenderTarget);
|
|
||||||
|
|
||||||
// This ensures all driver commands have finished before exiting the test.
|
// This ensures all driver commands have finished before exiting the test.
|
||||||
api.finish();
|
api.finish();
|
||||||
api.stopCapture();
|
api.stopCapture();
|
||||||
|
|
||||||
flushAndWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace test
|
} // namespace test
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -26,21 +27,6 @@ namespace {
|
|||||||
// Shaders
|
// Shaders
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
|
|
||||||
layout(location = 0) out uvec4 indices;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
|
||||||
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
|
||||||
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
|
||||||
gl_Position.y = -gl_Position.y;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
std::string fragment (R"(#version 450 core
|
std::string fragment (R"(#version 450 core
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec4 fragColor;
|
||||||
@@ -71,10 +57,12 @@ TEST_F(BackendTest, MRT) {
|
|||||||
auto swapChain = cleanup.add(createSwapChain());
|
auto swapChain = cleanup.add(createSwapChain());
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
|
|
||||||
// Create a program.
|
Shader shader(api, cleanup, ShaderConfig{
|
||||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform);
|
.vertexShader = SharedShaders::getVertexShaderText(VertexShaderType::Noop,
|
||||||
Program p = shaderGen.getProgram(api);
|
ShaderUniformType::None),
|
||||||
auto program = cleanup.add(api.createProgram(std::move(p)));
|
.fragmentShader = fragment,
|
||||||
|
.uniforms = {}
|
||||||
|
});
|
||||||
|
|
||||||
TrianglePrimitive triangle(api);
|
TrianglePrimitive triangle(api);
|
||||||
|
|
||||||
@@ -122,7 +110,7 @@ TEST_F(BackendTest, MRT) {
|
|||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = program;
|
state.program = shader.getProgram();
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
#include "BackendTestUtils.h"
|
#include "BackendTestUtils.h"
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
@@ -34,18 +35,7 @@ namespace {
|
|||||||
// Shaders
|
// Shaders
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
std::string fragmentTexturedLod (R"(#version 450 core
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
layout(location = 0) out vec2 uv;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
|
||||||
uv = (mesh_position.xy * 0.5 + 0.5);
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
std::string fragment (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec4 fragColor;
|
||||||
layout(location = 0) in vec2 uv;
|
layout(location = 0) in vec2 uv;
|
||||||
@@ -57,18 +47,6 @@ void main() {
|
|||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
|
||||||
std::string whiteFragment (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
layout(location = 0) in vec2 uv;
|
|
||||||
|
|
||||||
layout(location = 0, set = 1) uniform sampler2D backend_test_sib_tex;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
fragColor = vec4(1.0);
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
@@ -88,39 +66,25 @@ TEST_F(BackendTest, TextureViewLod) {
|
|||||||
auto swapChain = cleanup.add(createSwapChain());
|
auto swapChain = cleanup.add(createSwapChain());
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
|
|
||||||
// Create a program that draws only white.
|
Shader whiteShader = SharedShaders::makeShader(api, cleanup, ShaderRequest {
|
||||||
Handle<HwProgram> whiteProgram;
|
.mVertexType = VertexShaderType::Textured,
|
||||||
{
|
.mFragmentType = FragmentShaderType::White,
|
||||||
ShaderGenerator shaderGen(vertex, whiteFragment, sBackend, sIsMobilePlatform);
|
.mUniformType = ShaderUniformType::Sampler
|
||||||
Program p = shaderGen.getProgram(api);
|
});
|
||||||
p.descriptorBindings(0, {{"backend_test_sib_tex", DescriptorType::SAMPLER, 0}});
|
|
||||||
whiteProgram = cleanup.add(api.createProgram(std::move(p)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a program that samples a texture.
|
// Create a program that samples a texture.
|
||||||
Handle<HwProgram> textureProgram;
|
std::string vertexShader = SharedShaders::getVertexShaderText(
|
||||||
{
|
VertexShaderType::Textured, ShaderUniformType::Sampler);
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "backend_test", "sib_tex", 0,
|
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo {
|
||||||
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
|
"backend_test", "sib_tex", 0,
|
||||||
filamat::DescriptorSets descriptors;
|
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
|
||||||
descriptors[1] = { { "backend_test_sib_tex",
|
Shader texturedShader(api, cleanup, ShaderConfig {
|
||||||
{ DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 }, samplerInfo } };
|
.vertexShader = vertexShader,
|
||||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform, std::move(descriptors));
|
.fragmentShader = fragmentTexturedLod,
|
||||||
Program p = shaderGen.getProgram(api);
|
.uniforms = {{
|
||||||
p.descriptorBindings(0, {{"backend_test_sib_tex", DescriptorType::SAMPLER, 0}});
|
"backend_test_sib_tex", DescriptorType::SAMPLER, samplerInfo
|
||||||
textureProgram = cleanup.add(api.createProgram(std::move(p)));
|
}}
|
||||||
}
|
});
|
||||||
|
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = cleanup.add(api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}}));
|
|
||||||
|
|
||||||
DescriptorSetHandle descriptorSet[2];
|
|
||||||
descriptorSet[0] = cleanup.add(api.createDescriptorSet(descriptorSetLayout));
|
|
||||||
descriptorSet[1] = cleanup.add(api.createDescriptorSet(descriptorSetLayout));
|
|
||||||
|
|
||||||
// Create a texture that has 4 mip levels. Each level is a different color.
|
// Create a texture that has 4 mip levels. Each level is a different color.
|
||||||
// Level 0: 128x128 (red)
|
// Level 0: 128x128 (red)
|
||||||
@@ -129,9 +93,10 @@ TEST_F(BackendTest, TextureViewLod) {
|
|||||||
// Level 3: 16x16 (yellow)
|
// Level 3: 16x16 (yellow)
|
||||||
const size_t kTextureSize = 128;
|
const size_t kTextureSize = 128;
|
||||||
const size_t kMipLevels = 4;
|
const size_t kMipLevels = 4;
|
||||||
Handle<HwTexture> texture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, kMipLevels,
|
Handle<HwTexture> texture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D,
|
||||||
TextureFormat::RGBA8, 1, kTextureSize, kTextureSize, 1,
|
kMipLevels, TextureFormat::RGBA8, 1, kTextureSize, kTextureSize, 1,
|
||||||
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT | TextureUsage::UPLOADABLE));
|
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT
|
||||||
|
| TextureUsage::UPLOADABLE));
|
||||||
|
|
||||||
// Create image data.
|
// Create image data.
|
||||||
auto pixelFormat = PixelDataFormat::RGBA;
|
auto pixelFormat = PixelDataFormat::RGBA;
|
||||||
@@ -179,7 +144,7 @@ TEST_F(BackendTest, TextureViewLod) {
|
|||||||
params.flags.discardStart = TargetBufferFlags::NONE;
|
params.flags.discardStart = TargetBufferFlags::NONE;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
PipelineState ps = {};
|
PipelineState ps = {};
|
||||||
ps.program = whiteProgram;
|
ps.program = whiteShader.getProgram();
|
||||||
ps.rasterState.colorWrite = true;
|
ps.rasterState.colorWrite = true;
|
||||||
ps.rasterState.depthWrite = false;
|
ps.rasterState.depthWrite = false;
|
||||||
api.beginRenderPass(renderTarget, params);
|
api.beginRenderPass(renderTarget, params);
|
||||||
@@ -187,7 +152,8 @@ TEST_F(BackendTest, TextureViewLod) {
|
|||||||
api.endRenderPass();
|
api.endRenderPass();
|
||||||
}
|
}
|
||||||
|
|
||||||
backend::Handle<HwRenderTarget> defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
backend::Handle<HwRenderTarget> defaultRenderTarget =
|
||||||
|
cleanup.add(api.createDefaultRenderTarget(0));
|
||||||
|
|
||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
fullViewport(params);
|
fullViewport(params);
|
||||||
@@ -197,18 +163,19 @@ TEST_F(BackendTest, TextureViewLod) {
|
|||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = textureProgram;
|
state.program = texturedShader.getProgram();
|
||||||
state.pipelineLayout.setLayout = { descriptorSetLayout };
|
state.pipelineLayout.setLayout = { texturedShader.getDescriptorSetLayout() };
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = SamplerCompareFunc::A;
|
state.rasterState.depthFunc = SamplerCompareFunc::A;
|
||||||
state.rasterState.culling = CullingMode::NONE;
|
state.rasterState.culling = CullingMode::NONE;
|
||||||
|
|
||||||
api.updateDescriptorSetTexture(descriptorSet[0], 0, texture13, {
|
DescriptorSetHandle descriptorSet13 = texturedShader.createDescriptorSet(api);
|
||||||
|
api.updateDescriptorSetTexture(descriptorSet13, 0, texture13, {
|
||||||
.filterMag = SamplerMagFilter::NEAREST,
|
.filterMag = SamplerMagFilter::NEAREST,
|
||||||
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet[0], 0, {});
|
api.bindDescriptorSet(descriptorSet13, 0, {});
|
||||||
|
|
||||||
// Render a triangle to the screen, sampling from mip level 1.
|
// Render a triangle to the screen, sampling from mip level 1.
|
||||||
// Because the min level is 1, the result color should be the white triangle drawn in the
|
// Because the min level is 1, the result color should be the white triangle drawn in the
|
||||||
@@ -221,11 +188,12 @@ TEST_F(BackendTest, TextureViewLod) {
|
|||||||
// Adjust the base mip to 2.
|
// Adjust the base mip to 2.
|
||||||
auto texture22 = cleanup.add(api.createTextureView(texture, 2, 2));
|
auto texture22 = cleanup.add(api.createTextureView(texture, 2, 2));
|
||||||
|
|
||||||
api.updateDescriptorSetTexture(descriptorSet[1], 0, texture22, {
|
DescriptorSetHandle descriptorSet22 = texturedShader.createDescriptorSet(api);
|
||||||
|
api.updateDescriptorSetTexture(descriptorSet22, 0, texture22, {
|
||||||
.filterMag = SamplerMagFilter::NEAREST,
|
.filterMag = SamplerMagFilter::NEAREST,
|
||||||
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet[1], 0, {});
|
api.bindDescriptorSet(descriptorSet22, 0, {});
|
||||||
|
|
||||||
// Render a second, smaller, triangle, again sampling from mip level 1.
|
// Render a second, smaller, triangle, again sampling from mip level 1.
|
||||||
// This triangle should be yellow striped.
|
// This triangle should be yellow striped.
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -26,7 +27,7 @@ namespace {
|
|||||||
// Shaders
|
// Shaders
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
std::string vertex(R"(#version 450 core
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
layout(location = 0) in vec4 mesh_position;
|
||||||
|
|
||||||
@@ -46,16 +47,6 @@ void main() {
|
|||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
|
||||||
std::string fragment (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
fragColor = vec4(1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
)");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
@@ -78,9 +69,11 @@ TEST_F(BackendTest, MissingRequiredAttributes) {
|
|||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
|
|
||||||
// Create a program.
|
// Create a program.
|
||||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform);
|
Shader shader(api, cleanup, ShaderConfig{
|
||||||
Program p = shaderGen.getProgram(api);
|
.vertexShader = vertex,
|
||||||
auto program = cleanup.add(api.createProgram(std::move(p)));
|
.fragmentShader = SharedShaders::getFragmentShaderText(FragmentShaderType::White,
|
||||||
|
ShaderUniformType::None),
|
||||||
|
});
|
||||||
|
|
||||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
||||||
|
|
||||||
@@ -89,12 +82,12 @@ TEST_F(BackendTest, MissingRequiredAttributes) {
|
|||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
fullViewport(params);
|
fullViewport(params);
|
||||||
params.flags.clear = TargetBufferFlags::COLOR;
|
params.flags.clear = TargetBufferFlags::COLOR;
|
||||||
params.clearColor = {0.f, 1.f, 0.f, 1.f};
|
params.clearColor = { 0.f, 1.f, 0.f, 1.f };
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = program;
|
state.program = shader.getProgram();
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
#include "BackendTestUtils.h"
|
#include "BackendTestUtils.h"
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <utils/Hash.h>
|
#include <utils/Hash.h>
|
||||||
@@ -30,6 +31,7 @@ using namespace filament;
|
|||||||
using namespace filament::backend;
|
using namespace filament::backend;
|
||||||
|
|
||||||
#ifndef FILAMENT_IOS
|
#ifndef FILAMENT_IOS
|
||||||
|
|
||||||
#include <imageio/ImageEncoder.h>
|
#include <imageio/ImageEncoder.h>
|
||||||
#include <image/ColorTransform.h>
|
#include <image/ColorTransform.h>
|
||||||
|
|
||||||
@@ -42,20 +44,7 @@ namespace {
|
|||||||
// Shaders
|
// Shaders
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
std::string fragmentFloat(R"(#version 450 core
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
|
||||||
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
|
||||||
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
|
||||||
gl_Position.y = -gl_Position.y;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
std::string fragmentFloat (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
|
||||||
@@ -65,7 +54,7 @@ void main() {
|
|||||||
|
|
||||||
)");
|
)");
|
||||||
|
|
||||||
std::string fragmentUint (R"(#version 450 core
|
std::string fragmentUint(R"(#version 450 core
|
||||||
|
|
||||||
layout(location = 0) out uvec4 fragColor;
|
layout(location = 0) out uvec4 fragColor;
|
||||||
|
|
||||||
@@ -108,7 +97,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
size_t samples = 1;
|
size_t samples = 1;
|
||||||
|
|
||||||
// The size of the actual render target, taking mip level into account;
|
// The size of the actual render target, taking mip level into account;
|
||||||
size_t getRenderTargetSize () const {
|
size_t getRenderTargetSize() const {
|
||||||
return std::max(size_t(1), renderTargetBaseSize >> mipLevel);
|
return std::max(size_t(1), renderTargetBaseSize >> mipLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,11 +127,11 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void exportScreenshot(void* pixelData) const {
|
void exportScreenshot(void* pixelData) const {
|
||||||
#ifndef FILAMENT_IOS
|
#ifndef FILAMENT_IOS
|
||||||
const size_t width = readRect.width, height = readRect.height;
|
const size_t width = readRect.width, height = readRect.height;
|
||||||
LinearImage image(width, height, 4);
|
LinearImage image(width, height, 4);
|
||||||
if (format == PixelDataFormat::RGBA && type == PixelDataType::UBYTE) {
|
if (format == PixelDataFormat::RGBA && type == PixelDataType::UBYTE) {
|
||||||
image = toLinearWithAlpha<uint8_t>(width, height, width * 4, (uint8_t*) pixelData);
|
image = toLinearWithAlpha<uint8_t>(width, height, width * 4, (uint8_t*)pixelData);
|
||||||
}
|
}
|
||||||
if (format == PixelDataFormat::RGBA && type == PixelDataType::FLOAT) {
|
if (format == PixelDataFormat::RGBA && type == PixelDataType::FLOAT) {
|
||||||
memcpy(image.getPixelRef(), pixelData, width * height * sizeof(math::float4));
|
memcpy(image.getPixelRef(), pixelData, width * height * sizeof(math::float4));
|
||||||
@@ -151,13 +140,13 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
std::ofstream outputStream(png.c_str(), std::ios::binary | std::ios::trunc);
|
std::ofstream outputStream(png.c_str(), std::ios::binary | std::ios::trunc);
|
||||||
ImageEncoder::encode(outputStream, ImageEncoder::Format::PNG, image, "",
|
ImageEncoder::encode(outputStream, ImageEncoder::Format::PNG, image, "",
|
||||||
png.c_str());
|
png.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void exportRawBytes(void* pixelData) const {
|
void exportRawBytes(void* pixelData) const {
|
||||||
std::string out = std::string(testName) + ".raw";
|
std::string out = std::string(testName) + ".raw";
|
||||||
std::ofstream outputStream(out.c_str(), std::ios::binary | std::ios::trunc);
|
std::ofstream outputStream(out.c_str(), std::ios::binary | std::ios::trunc);
|
||||||
outputStream.write((char*) pixelData, getBufferSizeBytes());
|
outputStream.write((char*)pixelData, getBufferSizeBytes());
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,22 +229,20 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
DriverApi& api = getDriverApi();
|
DriverApi& api = getDriverApi();
|
||||||
Cleanup cleanup(api);
|
Cleanup cleanup(api);
|
||||||
|
|
||||||
// Create programs.
|
std::string vertexShader = SharedShaders::getVertexShaderText(VertexShaderType::Noop,
|
||||||
Handle<HwProgram> programFloat, programUint;
|
ShaderUniformType::None);
|
||||||
{
|
Shader floatShader(api, cleanup, ShaderConfig{
|
||||||
ShaderGenerator shaderGen(vertex, fragmentFloat, sBackend, sIsMobilePlatform);
|
.vertexShader = vertexShader,
|
||||||
Program p = shaderGen.getProgram(api);
|
.fragmentShader = fragmentFloat,
|
||||||
programFloat = cleanup.add(api.createProgram(std::move(p)));
|
.uniforms = {}
|
||||||
}
|
});
|
||||||
{
|
Shader uintShader(api, cleanup, ShaderConfig{
|
||||||
ShaderGenerator shaderGen(vertex, fragmentUint, sBackend, sIsMobilePlatform);
|
.vertexShader = vertexShader,
|
||||||
Program p = shaderGen.getProgram(api);
|
.fragmentShader = fragmentUint,
|
||||||
programUint = cleanup.add(api.createProgram(std::move(p)));
|
.uniforms = {}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
for (const auto& t: testCases) {
|
||||||
for (const auto& t : testCases)
|
|
||||||
{
|
|
||||||
// Create a platform-specific SwapChain and make it current.
|
// Create a platform-specific SwapChain and make it current.
|
||||||
Handle<HwSwapChain> swapChain;
|
Handle<HwSwapChain> swapChain;
|
||||||
if (t.useDefaultRT) {
|
if (t.useDefaultRT) {
|
||||||
@@ -292,7 +279,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
fullViewport(params);
|
fullViewport(params);
|
||||||
params.flags.clear = TargetBufferFlags::COLOR;
|
params.flags.clear = TargetBufferFlags::COLOR;
|
||||||
params.clearColor = {0.f, 0.f, 1.f, 1.f};
|
params.clearColor = { 0.f, 0.f, 1.f, 1.f };
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
params.viewport.height = t.getRenderTargetSize();
|
params.viewport.height = t.getRenderTargetSize();
|
||||||
@@ -305,9 +292,9 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
api.beginRenderPass(renderTarget, params);
|
api.beginRenderPass(renderTarget, params);
|
||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = programFloat;
|
state.program = floatShader.getProgram();
|
||||||
if (isUnsignedIntFormat(t.textureFormat)) {
|
if (isUnsignedIntFormat(t.textureFormat)) {
|
||||||
state.program = programUint;
|
state.program = uintShader.getProgram();
|
||||||
}
|
}
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
@@ -325,7 +312,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
Handle<HwRenderTarget> mipLevelOneRT = localCleanup.add(api.createRenderTarget(
|
Handle<HwRenderTarget> mipLevelOneRT = localCleanup.add(api.createRenderTarget(
|
||||||
TargetBufferFlags::COLOR, renderTargetBaseSize, renderTargetBaseSize, 1, 0,
|
TargetBufferFlags::COLOR, renderTargetBaseSize, renderTargetBaseSize, 1, 0,
|
||||||
{{ texture }}, {}, {}));
|
{{ texture }}, {}, {}));
|
||||||
p.clearColor = {1.f, 0.f, 0.f, 1.f};
|
p.clearColor = { 1.f, 0.f, 0.f, 1.f };
|
||||||
api.beginRenderPass(mipLevelOneRT, p);
|
api.beginRenderPass(mipLevelOneRT, p);
|
||||||
api.endRenderPass();
|
api.endRenderPass();
|
||||||
}
|
}
|
||||||
@@ -335,28 +322,28 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
|||||||
|
|
||||||
PixelBufferDescriptor descriptor(buffer, t.getBufferSizeBytes(), t.format, t.type,
|
PixelBufferDescriptor descriptor(buffer, t.getBufferSizeBytes(), t.format, t.type,
|
||||||
t.alignment, t.left, t.top, t.getPixelBufferStride(), [](void* buffer, size_t size,
|
t.alignment, t.left, t.top, t.getPixelBufferStride(), [](void* buffer, size_t size,
|
||||||
void* user) {
|
void* user) {
|
||||||
const auto* test = (const TestCase*) user;
|
const auto* test = (const TestCase*)user;
|
||||||
assert_invariant(test);
|
assert_invariant(test);
|
||||||
|
|
||||||
test->exportScreenshot(buffer);
|
test->exportScreenshot(buffer);
|
||||||
//test->exportRawBytes(buffer);
|
//test->exportRawBytes(buffer);
|
||||||
|
|
||||||
// Hash the contents of the buffer and check that they match.
|
// Hash the contents of the buffer and check that they match.
|
||||||
uint32_t hash = utils::hash::murmur3((const uint32_t*) buffer, size / 4, 0);
|
uint32_t hash = utils::hash::murmur3((const uint32_t*)buffer, size / 4, 0);
|
||||||
|
|
||||||
ASSERT_EQ(test->hash, hash) << test->testName <<
|
ASSERT_EQ(test->hash, hash) << test->testName <<
|
||||||
" failed: hashes do not match." << std::endl;
|
" failed: hashes do not match." << std::endl;
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}, (void*) &t);
|
}, (void*)&t);
|
||||||
|
|
||||||
api.readPixels(renderTarget, t.readRect.x, t.readRect.y, t.readRect.width,
|
api.readPixels(renderTarget, t.readRect.x, t.readRect.y, t.readRect.width,
|
||||||
t.readRect.height, std::move(descriptor));
|
t.readRect.height, std::move(descriptor));
|
||||||
|
|
||||||
// Now render red over what was just rendered. This ensures that readPixels captures the
|
// Now render red over what was just rendered. This ensures that readPixels captures the
|
||||||
// state of rendering between render passes.
|
// state of rendering between render passes.
|
||||||
params.clearColor = {1.f, 0.f, 0.f, 1.f};
|
params.clearColor = { 1.f, 0.f, 0.f, 1.f };
|
||||||
api.beginRenderPass(renderTarget, params);
|
api.beginRenderPass(renderTarget, params);
|
||||||
api.endRenderPass();
|
api.endRenderPass();
|
||||||
|
|
||||||
@@ -376,25 +363,27 @@ TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
|||||||
Cleanup cleanup(api);
|
Cleanup cleanup(api);
|
||||||
|
|
||||||
// Create a platform-specific SwapChain and make it current.
|
// Create a platform-specific SwapChain and make it current.
|
||||||
auto swapChain = cleanup.add(api.createSwapChainHeadless(renderTargetSize, renderTargetSize, 0));
|
auto swapChain = cleanup.add(
|
||||||
|
api.createSwapChainHeadless(renderTargetSize, renderTargetSize, 0));
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
|
|
||||||
// Create a program.
|
Shader shader = SharedShaders::makeShader(api, cleanup, ShaderRequest{
|
||||||
ShaderGenerator shaderGen(vertex, fragmentFloat, sBackend, sIsMobilePlatform);
|
.mVertexType = VertexShaderType::Noop,
|
||||||
Program p = shaderGen.getProgram(api);
|
.mFragmentType = FragmentShaderType::White,
|
||||||
auto program = cleanup.add(api.createProgram(std::move(p)));
|
.mUniformType = ShaderUniformType::None
|
||||||
|
});
|
||||||
|
|
||||||
// Create a Texture and RenderTarget to render into.
|
// Create a Texture and RenderTarget to render into.
|
||||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||||
Handle<HwTexture> texture = cleanup.add(api.createTexture(
|
Handle<HwTexture> texture = cleanup.add(api.createTexture(
|
||||||
SamplerType::SAMPLER_2D, // target
|
SamplerType::SAMPLER_2D, // target
|
||||||
1, // levels
|
1, // levels
|
||||||
TextureFormat::RGBA8, // format
|
TextureFormat::RGBA8, // format
|
||||||
1, // samples
|
1, // samples
|
||||||
renderTargetSize, // width
|
renderTargetSize, // width
|
||||||
renderTargetSize, // height
|
renderTargetSize, // height
|
||||||
1, // depth
|
1, // depth
|
||||||
usage)); // usage
|
usage)); // usage
|
||||||
|
|
||||||
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createRenderTarget(
|
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createRenderTarget(
|
||||||
TargetBufferFlags::COLOR,
|
TargetBufferFlags::COLOR,
|
||||||
@@ -411,7 +400,7 @@ TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
|||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
fullViewport(params);
|
fullViewport(params);
|
||||||
params.flags.clear = TargetBufferFlags::COLOR;
|
params.flags.clear = TargetBufferFlags::COLOR;
|
||||||
params.clearColor = {0.f, 0.f, 1.f, 1.f};
|
params.clearColor = { 0.f, 0.f, 1.f, 1.f };
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
params.viewport.height = renderTargetSize;
|
params.viewport.height = renderTargetSize;
|
||||||
@@ -420,7 +409,7 @@ TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
|||||||
void* buffer = calloc(1, renderTargetSize * renderTargetSize * 4);
|
void* buffer = calloc(1, renderTargetSize * renderTargetSize * 4);
|
||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = program;
|
state.program = shader.getProgram();
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
@@ -444,11 +433,12 @@ TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
|||||||
PixelBufferDescriptor descriptor(buffer, renderTargetSize * renderTargetSize * 4,
|
PixelBufferDescriptor descriptor(buffer, renderTargetSize * renderTargetSize * 4,
|
||||||
PixelDataFormat::RGBA, PixelDataType::UBYTE, 1, 0, 0, renderTargetSize,
|
PixelDataFormat::RGBA, PixelDataType::UBYTE, 1, 0, 0, renderTargetSize,
|
||||||
[](void* buffer, size_t size, void* user) {
|
[](void* buffer, size_t size, void* user) {
|
||||||
ReadPixelsTest* test = (ReadPixelsTest*) user;
|
ReadPixelsTest* test = (ReadPixelsTest*)user;
|
||||||
test->readPixelsFinished = true;
|
test->readPixelsFinished = true;
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
api.readPixels(renderTarget, 0, 0, renderTargetSize, renderTargetSize, std::move(descriptor));
|
api.readPixels(renderTarget, 0, 0, renderTargetSize, renderTargetSize,
|
||||||
|
std::move(descriptor));
|
||||||
api.commit(swapChain);
|
api.commit(swapChain);
|
||||||
api.endFrame(0);
|
api.endFrame(0);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
@@ -28,42 +29,19 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Shaders
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
layout(location = 0) out vec2 uv;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
|
||||||
uv = (mesh_position.xy * 0.5 + 0.5);
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
std::string fragment (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
layout(location = 0) in vec2 uv;
|
|
||||||
|
|
||||||
layout(location = 0, set = 1) uniform sampler2D test_tex;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
fragColor = texture(test_tex, uv);
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
using namespace filament;
|
using namespace filament;
|
||||||
using namespace filament::backend;
|
using namespace filament::backend;
|
||||||
|
|
||||||
|
Shader createShader(DriverApi& api, Cleanup& cleanup, Backend backend) {
|
||||||
|
return SharedShaders::makeShader(api, cleanup, ShaderRequest{
|
||||||
|
.mVertexType = VertexShaderType::Textured,
|
||||||
|
.mFragmentType = FragmentShaderType::Textured,
|
||||||
|
.mUniformType = ShaderUniformType::Sampler
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Rendering an external image without setting any data should not crash.
|
// Rendering an external image without setting any data should not crash.
|
||||||
TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
@@ -73,57 +51,41 @@ TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
|||||||
|
|
||||||
auto swapChain = cleanup.add(createSwapChain());
|
auto swapChain = cleanup.add(createSwapChain());
|
||||||
|
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
Shader shader = createShader(api, cleanup, sBackend);
|
||||||
SamplerType::SAMPLER_EXTERNAL, SamplerFormat::FLOAT, Precision::HIGH, false };
|
|
||||||
filamat::DescriptorSets descriptors;
|
|
||||||
descriptors[1] = { { "test_tex", { DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 },
|
|
||||||
samplerInfo } };
|
|
||||||
ShaderGenerator shaderGen(
|
|
||||||
vertex, fragment, sBackend, sIsMobilePlatform, std::move(descriptors));
|
|
||||||
|
|
||||||
// Create a program that samples a texture.
|
backend::Handle<HwRenderTarget> defaultRenderTarget = cleanup.add(
|
||||||
Program p = shaderGen.getProgram(api);
|
api.createDefaultRenderTarget(0));
|
||||||
p.descriptorBindings(1, {{"test_tex", DescriptorType::SAMPLER, 0}});
|
|
||||||
backend::Handle<HwProgram> program = cleanup.add(api.createProgram(std::move(p)));
|
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = cleanup.add(api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}}));
|
|
||||||
|
|
||||||
DescriptorSetHandle descriptorSet = cleanup.add(api.createDescriptorSet(descriptorSetLayout));
|
|
||||||
|
|
||||||
backend::Handle<HwRenderTarget> defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
|
||||||
|
|
||||||
// Create a texture that will be backed by an external image.
|
// Create a texture that will be backed by an external image.
|
||||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||||
const NativeView& view = getNativeView();
|
const NativeView& view = getNativeView();
|
||||||
backend::Handle<HwTexture> texture = cleanup.add(api.createTexture(
|
backend::Handle<HwTexture> texture = cleanup.add(api.createTexture(
|
||||||
SamplerType::SAMPLER_EXTERNAL, // target
|
SamplerType::SAMPLER_EXTERNAL, // target
|
||||||
1, // levels
|
1, // levels
|
||||||
TextureFormat::RGBA8, // format
|
TextureFormat::RGBA8, // format
|
||||||
1, // samples
|
1, // samples
|
||||||
view.width, // width
|
view.width, // width
|
||||||
view.height, // height
|
view.height, // height
|
||||||
1, // depth
|
1, // depth
|
||||||
usage)); // usage
|
usage)); // usage
|
||||||
|
|
||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
fullViewport(params);
|
fullViewport(params);
|
||||||
params.flags.clear = TargetBufferFlags::COLOR;
|
params.flags.clear = TargetBufferFlags::COLOR;
|
||||||
params.clearColor = {0.f, 1.f, 0.f, 1.f};
|
params.clearColor = { 0.f, 1.f, 0.f, 1.f };
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = program;
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { descriptorSetLayout };
|
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
state.rasterState.culling = CullingMode::NONE;
|
state.rasterState.culling = CullingMode::NONE;
|
||||||
|
|
||||||
|
DescriptorSetHandle descriptorSet = shader.createDescriptorSet(api);
|
||||||
|
|
||||||
api.startCapture(0);
|
api.startCapture(0);
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
@@ -155,29 +117,11 @@ TEST_F(BackendTest, RenderExternalImage) {
|
|||||||
|
|
||||||
auto swapChain = cleanup.add(createSwapChain());
|
auto swapChain = cleanup.add(createSwapChain());
|
||||||
|
|
||||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
Shader shader = createShader(api, cleanup, sBackend);
|
||||||
SamplerType::SAMPLER_EXTERNAL, SamplerFormat::FLOAT, Precision::HIGH, false };
|
DescriptorSetHandle descriptorSet = shader.createDescriptorSet(api);
|
||||||
filamat::DescriptorSets descriptors;
|
|
||||||
descriptors[1] = { { "test_tex", { DescriptorType::SAMPLER, ShaderStageFlags::FRAGMENT, 0 },
|
|
||||||
samplerInfo } };
|
|
||||||
ShaderGenerator shaderGen(
|
|
||||||
vertex, fragment, sBackend, sIsMobilePlatform, std::move(descriptors));
|
|
||||||
|
|
||||||
// Create a program that samples a texture.
|
backend::Handle<HwRenderTarget> defaultRenderTarget = cleanup.add(
|
||||||
Program p = shaderGen.getProgram(api);
|
api.createDefaultRenderTarget(0));
|
||||||
p.descriptorBindings(1, {{"test_tex", DescriptorType::SAMPLER, 0}});
|
|
||||||
auto program = cleanup.add(api.createProgram(std::move(p)));
|
|
||||||
|
|
||||||
DescriptorSetLayoutHandle descriptorSetLayout = cleanup.add(api.createDescriptorSetLayout({
|
|
||||||
{{
|
|
||||||
DescriptorType::SAMPLER,
|
|
||||||
ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, 0,
|
|
||||||
DescriptorFlags::NONE, 0
|
|
||||||
}}}));
|
|
||||||
|
|
||||||
DescriptorSetHandle descriptorSet = cleanup.add(api.createDescriptorSet(descriptorSetLayout));
|
|
||||||
|
|
||||||
backend::Handle<HwRenderTarget> defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget(0));
|
|
||||||
|
|
||||||
// require users to create two Filament textures and have two material parameters
|
// require users to create two Filament textures and have two material parameters
|
||||||
// add a "plane" parameter to setExternalImage
|
// add a "plane" parameter to setExternalImage
|
||||||
@@ -198,10 +142,12 @@ TEST_F(BackendTest, RenderExternalImage) {
|
|||||||
values[1] = values[0];
|
values[1] = values[0];
|
||||||
values[2] = values[0];
|
values[2] = values[0];
|
||||||
values[3] = values[0];
|
values[3] = values[0];
|
||||||
CFDictionaryRef options = CFDictionaryCreate(kCFAllocatorDefault, (const void**) keys, (const void**) values, 4, nullptr, nullptr);
|
CFDictionaryRef options = CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys,
|
||||||
|
(const void**)values, 4, nullptr, nullptr);
|
||||||
CVPixelBufferRef pixBuffer = nullptr;
|
CVPixelBufferRef pixBuffer = nullptr;
|
||||||
CVReturn status =
|
CVReturn status =
|
||||||
CVPixelBufferCreate(kCFAllocatorDefault, 1024, 1024, kCVPixelFormatType_32BGRA, options, &pixBuffer);
|
CVPixelBufferCreate(kCFAllocatorDefault, 1024, 1024, kCVPixelFormatType_32BGRA, options,
|
||||||
|
&pixBuffer);
|
||||||
assert(status == kCVReturnSuccess);
|
assert(status == kCVReturnSuccess);
|
||||||
|
|
||||||
// Fill image with checker-pattern.
|
// Fill image with checker-pattern.
|
||||||
@@ -210,7 +156,7 @@ TEST_F(BackendTest, RenderExternalImage) {
|
|||||||
const uint32_t black = 0xFF000000;
|
const uint32_t black = 0xFF000000;
|
||||||
CVReturn lockStatus = CVPixelBufferLockBaseAddress(pixBuffer, 0);
|
CVReturn lockStatus = CVPixelBufferLockBaseAddress(pixBuffer, 0);
|
||||||
assert(lockStatus == kCVReturnSuccess);
|
assert(lockStatus == kCVReturnSuccess);
|
||||||
uint32_t* pix = (uint32_t*) CVPixelBufferGetBaseAddressOfPlane(pixBuffer, 0);
|
uint32_t* pix = (uint32_t*)CVPixelBufferGetBaseAddressOfPlane(pixBuffer, 0);
|
||||||
assert(pix);
|
assert(pix);
|
||||||
for (size_t r = 0; r < 1024; r++) {
|
for (size_t r = 0; r < 1024; r++) {
|
||||||
for (size_t c = 0; c < 1024; c++) {
|
for (size_t c = 0; c < 1024; c++) {
|
||||||
@@ -230,13 +176,13 @@ TEST_F(BackendTest, RenderExternalImage) {
|
|||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
fullViewport(params);
|
fullViewport(params);
|
||||||
params.flags.clear = TargetBufferFlags::COLOR;
|
params.flags.clear = TargetBufferFlags::COLOR;
|
||||||
params.clearColor = {0.f, 1.f, 0.f, 1.f};
|
params.clearColor = { 0.f, 1.f, 0.f, 1.f };
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = program;
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { descriptorSetLayout };
|
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
@@ -247,7 +193,6 @@ TEST_F(BackendTest, RenderExternalImage) {
|
|||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
|
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {});
|
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {});
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 1, {});
|
||||||
|
|
||||||
// Render a triangle.
|
// Render a triangle.
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <utils/Hash.h>
|
#include <utils/Hash.h>
|
||||||
@@ -27,23 +28,6 @@ namespace test {
|
|||||||
using namespace filament;
|
using namespace filament;
|
||||||
using namespace filament::backend;
|
using namespace filament::backend;
|
||||||
|
|
||||||
static const char* const triangleVs = R"(#version 450 core
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
|
||||||
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
|
||||||
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
|
||||||
gl_Position.y = -gl_Position.y;
|
|
||||||
#endif
|
|
||||||
})";
|
|
||||||
|
|
||||||
static const char* const triangleFs = R"(#version 450 core
|
|
||||||
precision mediump int; precision highp float;
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
void main() {
|
|
||||||
fragColor = vec4(1.0f);
|
|
||||||
})";
|
|
||||||
|
|
||||||
TEST_F(BackendTest, ScissorViewportRegion) {
|
TEST_F(BackendTest, ScissorViewportRegion) {
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
|
|
||||||
@@ -85,10 +69,11 @@ TEST_F(BackendTest, ScissorViewportRegion) {
|
|||||||
auto swapChain = cleanup.add(api.createSwapChainHeadless(256, 256, 0));
|
auto swapChain = cleanup.add(api.createSwapChainHeadless(256, 256, 0));
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
|
|
||||||
// Create a program.
|
Shader shader = SharedShaders::makeShader(api, cleanup, ShaderRequest{
|
||||||
ShaderGenerator shaderGen(triangleVs, triangleFs, sBackend, sIsMobilePlatform);
|
.mVertexType = VertexShaderType::Noop,
|
||||||
Program p = shaderGen.getProgram(api);
|
.mFragmentType = FragmentShaderType::White,
|
||||||
ProgramHandle program = cleanup.add(api.createProgram(std::move(p)));
|
.mUniformType = ShaderUniformType::None,
|
||||||
|
});
|
||||||
|
|
||||||
// Create source color and depth textures.
|
// Create source color and depth textures.
|
||||||
Handle<HwTexture> srcTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, kNumLevels,
|
Handle<HwTexture> srcTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, kNumLevels,
|
||||||
@@ -133,7 +118,7 @@ TEST_F(BackendTest, ScissorViewportRegion) {
|
|||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
PipelineState ps = {};
|
PipelineState ps = {};
|
||||||
ps.program = program;
|
ps.program = shader.getProgram();
|
||||||
ps.rasterState.colorWrite = true;
|
ps.rasterState.colorWrite = true;
|
||||||
ps.rasterState.depthWrite = false;
|
ps.rasterState.depthWrite = false;
|
||||||
|
|
||||||
@@ -175,10 +160,11 @@ TEST_F(BackendTest, ScissorViewportEdgeCases) {
|
|||||||
auto swapChain = cleanup.add(api.createSwapChainHeadless(256, 256, 0));
|
auto swapChain = cleanup.add(api.createSwapChainHeadless(256, 256, 0));
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
|
|
||||||
// Create a program.
|
Shader shader = SharedShaders::makeShader(api, cleanup, ShaderRequest{
|
||||||
ShaderGenerator shaderGen(triangleVs, triangleFs, sBackend, sIsMobilePlatform);
|
.mVertexType = VertexShaderType::Noop,
|
||||||
Program p = shaderGen.getProgram(api);
|
.mFragmentType = FragmentShaderType::White,
|
||||||
ProgramHandle program = cleanup.add(api.createProgram(std::move(p)));
|
.mUniformType = ShaderUniformType::None,
|
||||||
|
});
|
||||||
|
|
||||||
// Create a source color textures.
|
// Create a source color textures.
|
||||||
Handle<HwTexture> srcTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
Handle<HwTexture> srcTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||||
@@ -220,7 +206,7 @@ TEST_F(BackendTest, ScissorViewportEdgeCases) {
|
|||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|
||||||
PipelineState ps = {};
|
PipelineState ps = {};
|
||||||
ps.program = program;
|
ps.program = shader.getProgram();
|
||||||
ps.rasterState.colorWrite = true;
|
ps.rasterState.colorWrite = true;
|
||||||
ps.rasterState.depthWrite = false;
|
ps.rasterState.depthWrite = false;
|
||||||
|
|
||||||
|
|||||||
@@ -17,43 +17,13 @@
|
|||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
|
|
||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "ShaderGenerator.h"
|
#include "Shader.h"
|
||||||
|
#include "SharedShaders.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
using namespace filament;
|
using namespace filament;
|
||||||
using namespace filament::backend;
|
using namespace filament::backend;
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Shaders
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
std::string vertex (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 mesh_position;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(mesh_position.xy, 0.0, 1.0);
|
|
||||||
#if defined(TARGET_VULKAN_ENVIRONMENT)
|
|
||||||
// In Vulkan, clip space is Y-down. In OpenGL and Metal, clip space is Y-up.
|
|
||||||
gl_Position.y = -gl_Position.y;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
std::string fragment (R"(#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
fragColor = vec4(1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
)");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
// 1. Clear the stencil buffer to all zeroes.
|
// 1. Clear the stencil buffer to all zeroes.
|
||||||
@@ -64,7 +34,7 @@ namespace test {
|
|||||||
class BasicStencilBufferTest : public BackendTest {
|
class BasicStencilBufferTest : public BackendTest {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Handle<HwSwapChain> mSwapChain;
|
Handle <HwSwapChain> mSwapChain;
|
||||||
ProgramHandle mProgram;
|
ProgramHandle mProgram;
|
||||||
Cleanup mCleanup;
|
Cleanup mCleanup;
|
||||||
|
|
||||||
@@ -77,21 +47,23 @@ public:
|
|||||||
mSwapChain = mCleanup.add(createSwapChain());
|
mSwapChain = mCleanup.add(createSwapChain());
|
||||||
api.makeCurrent(mSwapChain, mSwapChain);
|
api.makeCurrent(mSwapChain, mSwapChain);
|
||||||
|
|
||||||
// Create a program.
|
Shader shader = SharedShaders::makeShader(api, mCleanup, ShaderRequest{
|
||||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform);
|
.mVertexType = VertexShaderType::Noop,
|
||||||
Program p = shaderGen.getProgram(api);
|
.mFragmentType = FragmentShaderType::White,
|
||||||
mProgram = mCleanup.add(api.createProgram(std::move(p)));
|
.mUniformType = ShaderUniformType::None
|
||||||
|
});
|
||||||
|
mProgram = shader.getProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunTest(Handle<HwRenderTarget> renderTarget) {
|
void RunTest(Handle <HwRenderTarget> renderTarget) {
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
|
|
||||||
// We'll be using a triangle as geometry.
|
// We'll be using a triangle as geometry.
|
||||||
TrianglePrimitive smallTriangle(api);
|
TrianglePrimitive smallTriangle(api);
|
||||||
static filament::math::float2 vertices[3] = {
|
static filament::math::float2 vertices[3] = {
|
||||||
{ -0.5, -0.5 },
|
{ -0.5, -0.5 },
|
||||||
{ 0.5, -0.5 },
|
{ 0.5, -0.5 },
|
||||||
{ -0.5, 0.5 }
|
{ -0.5, 0.5 }
|
||||||
};
|
};
|
||||||
smallTriangle.updateVertices(vertices);
|
smallTriangle.updateVertices(vertices);
|
||||||
TrianglePrimitive triangle(api);
|
TrianglePrimitive triangle(api);
|
||||||
@@ -100,7 +72,7 @@ public:
|
|||||||
// Render a small triangle only to the stencil buffer, increasing the stencil buffer to 1.
|
// Render a small triangle only to the stencil buffer, increasing the stencil buffer to 1.
|
||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
params.flags.clear = TargetBufferFlags::COLOR0 | TargetBufferFlags::STENCIL;
|
params.flags.clear = TargetBufferFlags::COLOR0 | TargetBufferFlags::STENCIL;
|
||||||
params.viewport = {0, 0, 512, 512};
|
params.viewport = { 0, 0, 512, 512 };
|
||||||
params.clearColor = math::float4(0.0f, 0.0f, 1.0f, 1.0f);
|
params.clearColor = math::float4(0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
params.clearStencil = 0u;
|
params.clearStencil = 0u;
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
@@ -153,7 +125,7 @@ TEST_F(BasicStencilBufferTest, StencilBuffer) {
|
|||||||
TextureFormat::STENCIL8, 1, 512, 512, 1, TextureUsage::STENCIL_ATTACHMENT));
|
TextureFormat::STENCIL8, 1, 512, 512, 1, TextureUsage::STENCIL_ATTACHMENT));
|
||||||
auto renderTarget = cleanup.add(api.createRenderTarget(
|
auto renderTarget = cleanup.add(api.createRenderTarget(
|
||||||
TargetBufferFlags::COLOR0 | TargetBufferFlags::STENCIL, 512, 512, 1, 0,
|
TargetBufferFlags::COLOR0 | TargetBufferFlags::STENCIL, 512, 512, 1, 0,
|
||||||
{{colorTexture}}, {}, {{stencilTexture}}));
|
{{ colorTexture }}, {}, {{ stencilTexture }}));
|
||||||
|
|
||||||
RunTest(renderTarget);
|
RunTest(renderTarget);
|
||||||
|
|
||||||
@@ -171,10 +143,11 @@ TEST_F(BasicStencilBufferTest, DepthAndStencilBuffer) {
|
|||||||
auto colorTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
auto colorTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||||
TextureFormat::RGBA8, 1, 512, 512, 1, TextureUsage::COLOR_ATTACHMENT));
|
TextureFormat::RGBA8, 1, 512, 512, 1, TextureUsage::COLOR_ATTACHMENT));
|
||||||
auto depthStencilTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
auto depthStencilTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||||
TextureFormat::DEPTH24_STENCIL8, 1, 512, 512, 1, TextureUsage::STENCIL_ATTACHMENT | TextureUsage::DEPTH_ATTACHMENT));
|
TextureFormat::DEPTH24_STENCIL8, 1, 512, 512, 1,
|
||||||
|
TextureUsage::STENCIL_ATTACHMENT | TextureUsage::DEPTH_ATTACHMENT));
|
||||||
auto renderTarget = cleanup.add(api.createRenderTarget(
|
auto renderTarget = cleanup.add(api.createRenderTarget(
|
||||||
TargetBufferFlags::COLOR0 | TargetBufferFlags::STENCIL, 512, 512, 1, 0,
|
TargetBufferFlags::COLOR0 | TargetBufferFlags::STENCIL, 512, 512, 1, 0,
|
||||||
{{colorTexture}}, {depthStencilTexture}, {{depthStencilTexture}}));
|
{{ colorTexture }}, { depthStencilTexture }, {{ depthStencilTexture }}));
|
||||||
|
|
||||||
RunTest(renderTarget);
|
RunTest(renderTarget);
|
||||||
|
|
||||||
@@ -194,15 +167,17 @@ TEST_F(BasicStencilBufferTest, StencilBufferMSAA) {
|
|||||||
// Pass 1: Render a triangle into (an auto-created) MSAA color buffer using the stencil test.
|
// Pass 1: Render a triangle into (an auto-created) MSAA color buffer using the stencil test.
|
||||||
// Performs an auto-resolve on the color.
|
// Performs an auto-resolve on the color.
|
||||||
auto colorTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
auto colorTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||||
TextureFormat::RGBA8, 1, 512, 512, 1, TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE));
|
TextureFormat::RGBA8, 1, 512, 512, 1,
|
||||||
|
TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE));
|
||||||
auto depthStencilTextureMSAA = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
auto depthStencilTextureMSAA = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||||
TextureFormat::DEPTH24_STENCIL8, 4, 512, 512, 1, TextureUsage::STENCIL_ATTACHMENT | TextureUsage::DEPTH_ATTACHMENT));
|
TextureFormat::DEPTH24_STENCIL8, 4, 512, 512, 1,
|
||||||
|
TextureUsage::STENCIL_ATTACHMENT | TextureUsage::DEPTH_ATTACHMENT));
|
||||||
auto renderTarget0 = cleanup.add(api.createRenderTarget(
|
auto renderTarget0 = cleanup.add(api.createRenderTarget(
|
||||||
TargetBufferFlags::DEPTH_AND_STENCIL, 512, 512, 4, 0,
|
TargetBufferFlags::DEPTH_AND_STENCIL, 512, 512, 4, 0,
|
||||||
{{}}, {depthStencilTextureMSAA}, {depthStencilTextureMSAA}));
|
{{}}, { depthStencilTextureMSAA }, { depthStencilTextureMSAA }));
|
||||||
auto renderTarget1 = cleanup.add(api.createRenderTarget(
|
auto renderTarget1 = cleanup.add(api.createRenderTarget(
|
||||||
TargetBufferFlags::COLOR0 | TargetBufferFlags::DEPTH_AND_STENCIL, 512, 512, 4, 0,
|
TargetBufferFlags::COLOR0 | TargetBufferFlags::DEPTH_AND_STENCIL, 512, 512, 4, 0,
|
||||||
{{colorTexture}}, {depthStencilTextureMSAA}, {depthStencilTextureMSAA}));
|
{{ colorTexture }}, { depthStencilTextureMSAA }, { depthStencilTextureMSAA }));
|
||||||
|
|
||||||
api.startCapture(0);
|
api.startCapture(0);
|
||||||
|
|
||||||
@@ -210,8 +185,8 @@ TEST_F(BasicStencilBufferTest, StencilBufferMSAA) {
|
|||||||
TrianglePrimitive smallTriangle(api);
|
TrianglePrimitive smallTriangle(api);
|
||||||
static filament::math::float2 vertices[3] = {
|
static filament::math::float2 vertices[3] = {
|
||||||
{ -0.5, -0.5 },
|
{ -0.5, -0.5 },
|
||||||
{ 0.5, -0.5 },
|
{ 0.5, -0.5 },
|
||||||
{ -0.5, 0.5 }
|
{ -0.5, 0.5 }
|
||||||
};
|
};
|
||||||
smallTriangle.updateVertices(vertices);
|
smallTriangle.updateVertices(vertices);
|
||||||
TrianglePrimitive triangle(api);
|
TrianglePrimitive triangle(api);
|
||||||
@@ -220,7 +195,7 @@ TEST_F(BasicStencilBufferTest, StencilBufferMSAA) {
|
|||||||
// Render a small triangle only to the stencil buffer, increasing the stencil buffer to 1.
|
// Render a small triangle only to the stencil buffer, increasing the stencil buffer to 1.
|
||||||
RenderPassParams params = {};
|
RenderPassParams params = {};
|
||||||
params.flags.clear = TargetBufferFlags::STENCIL;
|
params.flags.clear = TargetBufferFlags::STENCIL;
|
||||||
params.viewport = {0, 0, 512, 512};
|
params.viewport = { 0, 0, 512, 512 };
|
||||||
params.clearStencil = 0u;
|
params.clearStencil = 0u;
|
||||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
|
|||||||
@@ -317,6 +317,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
size_t metalUploadBufferSizeBytes = 512 * 1024;
|
size_t metalUploadBufferSizeBytes = 512 * 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action to take if a Drawable cannot be acquired.
|
||||||
|
*
|
||||||
|
* Each frame rendered requires a CAMetalDrawable texture, which is
|
||||||
|
* presented on-screen at the completion of each frame. These are
|
||||||
|
* limited and provided round-robin style by the system.
|
||||||
|
*/
|
||||||
|
bool metalDisablePanicOnDrawableFailure = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to `true` to forcibly disable parallel shader compilation in the backend.
|
* Set to `true` to forcibly disable parallel shader compilation in the backend.
|
||||||
* Currently only honored by the GL and Metal backends.
|
* Currently only honored by the GL and Metal backends.
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ Engine* FEngine::create(Builder const& builder) {
|
|||||||
.forceGLES2Context = instance->getConfig().forceGLES2Context,
|
.forceGLES2Context = instance->getConfig().forceGLES2Context,
|
||||||
.stereoscopicType = instance->getConfig().stereoscopicType,
|
.stereoscopicType = instance->getConfig().stereoscopicType,
|
||||||
.assertNativeWindowIsValid = instance->features.backend.opengl.assert_native_window_is_valid,
|
.assertNativeWindowIsValid = instance->features.backend.opengl.assert_native_window_is_valid,
|
||||||
|
.metalDisablePanicOnDrawableFailure = instance->getConfig().metalDisablePanicOnDrawableFailure,
|
||||||
};
|
};
|
||||||
instance->mDriver = platform->createDriver(sharedContext, driverConfig);
|
instance->mDriver = platform->createDriver(sharedContext, driverConfig);
|
||||||
|
|
||||||
@@ -733,6 +734,7 @@ int FEngine::loop() {
|
|||||||
.forceGLES2Context = mConfig.forceGLES2Context,
|
.forceGLES2Context = mConfig.forceGLES2Context,
|
||||||
.stereoscopicType = mConfig.stereoscopicType,
|
.stereoscopicType = mConfig.stereoscopicType,
|
||||||
.assertNativeWindowIsValid = features.backend.opengl.assert_native_window_is_valid,
|
.assertNativeWindowIsValid = features.backend.opengl.assert_native_window_is_valid,
|
||||||
|
.metalDisablePanicOnDrawableFailure = mConfig.metalDisablePanicOnDrawableFailure,
|
||||||
};
|
};
|
||||||
mDriver = mPlatform->createDriver(mSharedGLContext, driverConfig);
|
mDriver = mPlatform->createDriver(mSharedGLContext, driverConfig);
|
||||||
|
|
||||||
|
|||||||
109
test/code-correctness/src/run.py
Normal file
109
test/code-correctness/src/run.py
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import glob
|
||||||
|
import yaml
|
||||||
|
import hashlib
|
||||||
|
import concurrent.futures
|
||||||
|
import re
|
||||||
|
|
||||||
|
from utils import execute, ArgParseImpl
|
||||||
|
|
||||||
|
def get_line(file_name, offset):
|
||||||
|
with open(f'{file_name}', 'rb') as file:
|
||||||
|
bytes = file.read()[0:offset]
|
||||||
|
f_str = bytes.decode('utf-8')
|
||||||
|
return len(f_str.split('\n'))
|
||||||
|
return -1
|
||||||
|
|
||||||
|
def get_func_name(msg):
|
||||||
|
pattern = r"\'(.+)\'"
|
||||||
|
res = re.findall(pattern, msg)
|
||||||
|
if len(res) > 0:
|
||||||
|
return res[0].replace("'", '')
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def run_tidy(files):
|
||||||
|
files_str = ' '.join(files)
|
||||||
|
hid = hashlib.md5(files_str.encode('utf-8')).hexdigest()
|
||||||
|
_, _ = execute(f'clang-tidy --export-fixes=/tmp/{hid}.yaml --quiet --checks=-*,bugprone-exception-escape {files_str}')
|
||||||
|
results = []
|
||||||
|
with open(f'/tmp/{hid}.yaml', 'r') as file:
|
||||||
|
data = yaml.safe_load(file)
|
||||||
|
for d in data['Diagnostics']:
|
||||||
|
if d['DiagnosticName'] != 'bugprone-exception-escape':
|
||||||
|
continue
|
||||||
|
msg = d['DiagnosticMessage']
|
||||||
|
fpath = msg['FilePath']
|
||||||
|
offset = msg['FileOffset']
|
||||||
|
line_num = get_line(fpath, offset)
|
||||||
|
results.append((msg['FilePath'].replace(f'{os.getcwd()}/', ''), line_num, get_func_name(msg['Message'])))
|
||||||
|
return results
|
||||||
|
|
||||||
|
def exception_escape_test():
|
||||||
|
files = glob.glob('filament/**/*.mm', recursive=True) + \
|
||||||
|
glob.glob('filament/**/*.cpp', recursive=True) + \
|
||||||
|
glob.glob('filament/**/*.h', recursive=True)
|
||||||
|
|
||||||
|
num_workers = 5 # Number of threads to spawn
|
||||||
|
part_len = len(files) // num_workers
|
||||||
|
workloads = []
|
||||||
|
for i in range(num_workers):
|
||||||
|
next = min(len(files), part_len)
|
||||||
|
workloads.append(files[0:next])
|
||||||
|
files = files[next:]
|
||||||
|
|
||||||
|
all_results = []
|
||||||
|
with concurrent.futures.ThreadPoolExecutor(max_workers=num_workers) as executor:
|
||||||
|
future_to_worker_id = {executor.submit(run_tidy, workloads[i]): i for i in range(num_workers)}
|
||||||
|
|
||||||
|
for future in concurrent.futures.as_completed(future_to_worker_id):
|
||||||
|
worker_id = future_to_worker_id[future]
|
||||||
|
try:
|
||||||
|
all_results.extend(future.result())
|
||||||
|
except Exception as exc:
|
||||||
|
print(f"Main: Worker {worker_id} generated an exception: {exc}")
|
||||||
|
test_name = 'code-correctness::exception-escape'
|
||||||
|
failure_str_lines = []
|
||||||
|
if len(all_results) > 0:
|
||||||
|
failure_str_lines.append(f'Number of failures: {len(all_results)}')
|
||||||
|
for fname, line_num, msg in all_results:
|
||||||
|
failure_str_lines.append(f'{fname}({line_num}): {msg}()')
|
||||||
|
return (len(all_results) == 0, failure_str_lines)
|
||||||
|
|
||||||
|
TESTS = [
|
||||||
|
(exception_escape_test,
|
||||||
|
'exception-escape',
|
||||||
|
'\'an exception may be thrown in a function which should not throw exceptions\'')
|
||||||
|
]
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
has_failures = False
|
||||||
|
for test_func, test_name, test_desc in TESTS:
|
||||||
|
result, res_strs = test_func()
|
||||||
|
ss = ' ' * 4
|
||||||
|
if result:
|
||||||
|
print(f'[{test_name}] PASSED')
|
||||||
|
else:
|
||||||
|
has_failures = True
|
||||||
|
print(f'[{test_name}] FAILED')
|
||||||
|
print(f'{ss}Description: \'{test_desc}\'')
|
||||||
|
for s in res_strs:
|
||||||
|
print(f'{ss}{s}')
|
||||||
|
if has_failures:
|
||||||
|
# TODO: Enable this when we've fixed all the exception-escape errors
|
||||||
|
#exit(1)
|
||||||
|
pass
|
||||||
|
|
||||||
68
test/code-correctness/src/utils.py
Normal file
68
test/code-correctness/src/utils.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# Copyright (C) 2024 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.
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def execute(cmd,
|
||||||
|
cwd=None,
|
||||||
|
capture_output=True,
|
||||||
|
stdin=None,
|
||||||
|
env=None,
|
||||||
|
raise_errors=False):
|
||||||
|
in_env = os.environ
|
||||||
|
in_env.update(env if env else {})
|
||||||
|
home = os.environ['HOME']
|
||||||
|
if f'{home}/bin' not in in_env['PATH']:
|
||||||
|
in_env['PATH'] = in_env['PATH'] + f':{home}/bin'
|
||||||
|
|
||||||
|
stdout = subprocess.PIPE if capture_output else sys.stdout
|
||||||
|
stderr = subprocess.PIPE if capture_output else sys.stdout
|
||||||
|
output = ''
|
||||||
|
err_output = ''
|
||||||
|
return_code = -1
|
||||||
|
kwargs = {
|
||||||
|
'cwd': cwd,
|
||||||
|
'env': in_env,
|
||||||
|
'stdout': stdout,
|
||||||
|
'stderr': stderr,
|
||||||
|
'stdin': stdin,
|
||||||
|
'universal_newlines': True
|
||||||
|
}
|
||||||
|
if capture_output:
|
||||||
|
process = subprocess.Popen(cmd.split(' '), **kwargs)
|
||||||
|
output, err_output = process.communicate()
|
||||||
|
return_code = process.returncode
|
||||||
|
else:
|
||||||
|
return_code = subprocess.call(cmd.split(' '), **kwargs)
|
||||||
|
|
||||||
|
if return_code:
|
||||||
|
# Error
|
||||||
|
if raise_errors:
|
||||||
|
raise subprocess.CalledProcessError(return_code, cmd)
|
||||||
|
if output:
|
||||||
|
if type(output) != str:
|
||||||
|
try:
|
||||||
|
output = output.decode('utf-8').strip()
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
print('cannot decode ', output, file=sys.stderr)
|
||||||
|
return return_code, (output if return_code == 0 else err_output)
|
||||||
|
|
||||||
|
class ArgParseImpl(argparse.ArgumentParser):
|
||||||
|
def error(self, message):
|
||||||
|
sys.stderr.write('error: %s\n' % message)
|
||||||
|
self.print_help()
|
||||||
|
sys.exit(1)
|
||||||
28
test/code-correctness/test.sh
Normal file
28
test/code-correctness/test.sh
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
CODE_CORRECTNESS_TEST_DIR="$(pwd)/test/code-correctness"
|
||||||
|
|
||||||
|
# Check if the clang-tidy command exists and is executable
|
||||||
|
if ! command -v clang-tidy > /dev/null 2>&1; then
|
||||||
|
# If command -v fails (returns a non-zero exit status), clang-tidy is not found
|
||||||
|
echo "Error: clang-tidy command not found." >&2
|
||||||
|
echo "Please install clang-tidy or ensure it is in your system's PATH." >&2
|
||||||
|
exit 1 # Exit the script with an error code (conventionally non-zero for failure)
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -e && set -x && \
|
||||||
|
python3 ${CODE_CORRECTNESS_TEST_DIR}/src/run.py
|
||||||
15
third_party/dawn/tnt/CMakeLists.txt
vendored
15
third_party/dawn/tnt/CMakeLists.txt
vendored
@@ -33,22 +33,36 @@ if (ANDROID AND FILAMENT_BUILD_FILAMAT)
|
|||||||
tint_lang_core
|
tint_lang_core
|
||||||
tint_lang_core_constant
|
tint_lang_core_constant
|
||||||
tint_lang_core_intrinsic
|
tint_lang_core_intrinsic
|
||||||
|
tint_lang_core_ir
|
||||||
|
tint_lang_core_ir_transform
|
||||||
|
tint_lang_core_ir_type
|
||||||
tint_lang_core_type
|
tint_lang_core_type
|
||||||
|
tint_lang_spirv
|
||||||
|
tint_lang_spirv_intrinsic
|
||||||
|
tint_lang_spirv_ir
|
||||||
tint_lang_spirv_reader
|
tint_lang_spirv_reader
|
||||||
tint_lang_spirv_reader_ast_lower
|
tint_lang_spirv_reader_ast_lower
|
||||||
tint_lang_spirv_reader_ast_parser
|
tint_lang_spirv_reader_ast_parser
|
||||||
tint_lang_spirv_reader_common
|
tint_lang_spirv_reader_common
|
||||||
|
tint_lang_spirv_reader_lower
|
||||||
|
tint_lang_spirv_reader_parser
|
||||||
|
tint_lang_spirv_type
|
||||||
|
tint_lang_spirv_validate
|
||||||
tint_lang_spirv_writer
|
tint_lang_spirv_writer
|
||||||
tint_lang_wgsl
|
tint_lang_wgsl
|
||||||
tint_lang_wgsl_ast
|
tint_lang_wgsl_ast
|
||||||
tint_lang_wgsl_ast_transform
|
tint_lang_wgsl_ast_transform
|
||||||
|
tint_lang_wgsl_common
|
||||||
tint_lang_wgsl_features
|
tint_lang_wgsl_features
|
||||||
tint_lang_wgsl_intrinsic
|
tint_lang_wgsl_intrinsic
|
||||||
|
tint_lang_wgsl_ir
|
||||||
tint_lang_wgsl_program
|
tint_lang_wgsl_program
|
||||||
tint_lang_wgsl_resolver
|
tint_lang_wgsl_resolver
|
||||||
tint_lang_wgsl_sem
|
tint_lang_wgsl_sem
|
||||||
tint_lang_wgsl_writer
|
tint_lang_wgsl_writer
|
||||||
tint_lang_wgsl_writer_ast_printer
|
tint_lang_wgsl_writer_ast_printer
|
||||||
|
tint_lang_wgsl_writer_ir_to_program
|
||||||
|
tint_lang_wgsl_writer_raise
|
||||||
tint_results
|
tint_results
|
||||||
tint_utils
|
tint_utils
|
||||||
tint_utils_diagnostic
|
tint_utils_diagnostic
|
||||||
@@ -58,6 +72,7 @@ if (ANDROID AND FILAMENT_BUILD_FILAMAT)
|
|||||||
tint_utils_strconv
|
tint_utils_strconv
|
||||||
tint_utils_symbol
|
tint_utils_symbol
|
||||||
tint_utils_text
|
tint_utils_text
|
||||||
|
tint_utils_text_generator
|
||||||
)
|
)
|
||||||
|
|
||||||
# Use the following no-op definitions to introduce a library and its dependency.
|
# Use the following no-op definitions to introduce a library and its dependency.
|
||||||
|
|||||||
Reference in New Issue
Block a user