Skip to content

Commit

Permalink
Add fixes for the extension and unique_ptr creation
Browse files Browse the repository at this point in the history
Signed-off-by: Rodrigo Holztrattner <quic_rholztra@quicinc.com>
  • Loading branch information
RodrigoHolztrattner-QuIC authored and carlosadcq committed Jan 9, 2024
1 parent 8d95c2c commit 55b1d30
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 97 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ samples/hello-gltf/assets_tmp/
samples/rotatedCopy/assets_tmp/
samples/shaderResolveTonemap/assets_tmp/
samples/SubPass/assets_tmp/
samples/BloomImageProcessing/assets_tmp/
project/tools/ktx.dll
project/tools/ktxinfo.exe
project/tools/toktx.exe
2 changes: 1 addition & 1 deletion framework/code/graphicsApi/graphicsApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ auto* apiCast(T* rBase) {
template<class T_GFXAPI, typename T>
auto apiCast(std::unique_ptr<T>&& rBase) {
using tDerived = typename T::template tApiDerived<T_GFXAPI>;
return std::unique_ptr<tDerived>(static_cast<tDerived*>(rBase.get()));
return std::unique_ptr<tDerived>(static_cast<tDerived*>(rBase.release()));
}


Expand Down
6 changes: 6 additions & 0 deletions framework/code/main/frameworkApplicationBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
#include "system/os_common.h"

// Bring in the timestamp (and assign to a variable)
// Temporary fix for Android not building the timestamp, upstream cmake update will fix this in a future update
#if defined(_WIN32)
#include "../../project/buildtimestamp.h"
#else
#define BUILD_TIMESTAMP "UNDEFINED"
#endif

const char* const FrameworkApplicationBase::sm_BuildTimestamp = BUILD_TIMESTAMP;


Expand Down
5 changes: 5 additions & 0 deletions framework/code/mesh/instanceGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <glm/gtx/norm.hpp>
#define EIGEN_INITIALIZE_MATRICES_BY_ZERO
#define EIGEN_MPL2_ONLY

#if defined(_WIN32)
#define EIGEN_HAS_STD_RESULT_OF 0
#endif

#include <eigen/Eigen/Dense>
#include <map>
#include <algorithm>
Expand Down
6 changes: 3 additions & 3 deletions framework/code/texture/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,18 @@ std::unique_ptr<Texture> CreateTextureObject(GraphicsApiBase& gfxApi, const Crea

/// Create texture from a memory buffer.
template<typename T_GFXAPI>
TextureT<T_GFXAPI> CreateTextureFromBuffer( T_GFXAPI& gfxApi, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName = nullptr )
TextureT<T_GFXAPI> CreateTextureFromBuffer( T_GFXAPI& gfxApi, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName = nullptr, uint32_t extraFlags = 0 )
{
assert( 0 && "Expecting CreateTextureFromBuffer (per graphics api) to be used" );
return {};
}

/// Create texture (unique_ptr) (generally for render target usage). Uses CreateTexObjectInfo structure to define texture creation parameters.
template<typename T_GFXAPI>
std::unique_ptr<Texture> CreateTextureFromBuffer( GraphicsApiBase& gfxApi, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName = nullptr )
std::unique_ptr<Texture> CreateTextureFromBuffer( GraphicsApiBase& gfxApi, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName = nullptr, uint32_t extraFlags = 0 )
{
auto pTexture = std::make_unique<TextureT<T_GFXAPI>>();
*pTexture = std::move( CreateTextureFromBuffer( static_cast<T_GFXAPI&>( gfxApi ), pData, DataSize, Width, Height, Depth, Format, SamplerMode, Filter, pName ) );
*pTexture = std::move( CreateTextureFromBuffer( static_cast<T_GFXAPI&>( gfxApi ), pData, DataSize, Width, Height, Depth, Format, SamplerMode, Filter, pName, extraFlags) );
return pTexture;
}

Expand Down
2 changes: 1 addition & 1 deletion framework/code/texture/textureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class TextureManager
virtual std::unique_ptr<Texture> CreateTextureObjectView( GraphicsApiBase& gfxApi, const Texture& original, TextureFormat viewFormat ) = 0;

/// Create texture from a block of texture data in memory (with correct format, span etc).
virtual std::unique_ptr<Texture> CreateTextureFromBuffer( GraphicsApiBase&, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName) = 0;
virtual std::unique_ptr<Texture> CreateTextureFromBuffer( GraphicsApiBase&, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName, uint32_t extraFlags = 0) = 0;

/// Get a 'default' sampler for the given address mode (all other sampler settings assumed to be 'normal' ie linearly sampled etc)
virtual const Sampler* const GetSampler( SamplerAddressMode ) const = 0;
Expand Down
3 changes: 2 additions & 1 deletion framework/code/texture/vulkan/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ TextureT<Vulkan> CreateTextureObjectView( Vulkan& vulkan, const TextureT<Vulkan>

//-----------------------------------------------------------------------------
template<>
TextureT<Vulkan> CreateTextureFromBuffer<Vulkan>( Vulkan& vulkan, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName )
TextureT<Vulkan> CreateTextureFromBuffer<Vulkan>( Vulkan& vulkan, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName, uint32_t extraFlags )
//-----------------------------------------------------------------------------
{
if (pName == nullptr)
Expand All @@ -742,6 +742,7 @@ TextureT<Vulkan> CreateTextureFromBuffer<Vulkan>( Vulkan& vulkan, const void* pD
uint32_t MipLevels = 1;
VkFormat vkFormat = TextureFormatToVk( Format );
VkImageUsageFlags FinalUsage = ( VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT );
FinalUsage |= (VkImageUsageFlags)extraFlags;
VkImageLayout FinalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

// Image creation info. Will change below based on need
Expand Down
2 changes: 1 addition & 1 deletion framework/code/texture/vulkan/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ TextureT<Vulkan> CreateTextureObject<Vulkan>( Vulkan&, const CreateTexObjectInfo

/// Template specialization for Vulkan CreateTextureFromBuffer
template<>
TextureT<Vulkan> CreateTextureFromBuffer<Vulkan>( Vulkan&, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName );
TextureT<Vulkan> CreateTextureFromBuffer<Vulkan>( Vulkan&, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName, uint32_t extraFlags );

/// Create a texture that views (aliases) another texture but using a different texture format (must be 'related' formats, which formats are related is dependant on graphics api)
TextureT<Vulkan> CreateTextureObjectView( Vulkan&, const TextureT<Vulkan>& original, TextureFormat viewFormat );
Expand Down
4 changes: 2 additions & 2 deletions framework/code/texture/vulkan/textureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ std::unique_ptr<Texture> TextureManagerT<Vulkan>::CreateTextureObject(GraphicsAp
}

//-----------------------------------------------------------------------------
std::unique_ptr<Texture> TextureManagerT<Vulkan>::CreateTextureFromBuffer( GraphicsApiBase& gfxApi, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName )
std::unique_ptr<Texture> TextureManagerT<Vulkan>::CreateTextureFromBuffer( GraphicsApiBase& gfxApi, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName, uint32_t extraFlags)
//-----------------------------------------------------------------------------
{
auto pTexture = std::make_unique<TextureT<Vulkan>>();
*pTexture = ::CreateTextureFromBuffer( static_cast<Vulkan&>( gfxApi ), pData, DataSize, Width, Height, Depth, Format, SamplerMode, Filter, pName );
*pTexture = ::CreateTextureFromBuffer( static_cast<Vulkan&>( gfxApi ), pData, DataSize, Width, Height, Depth, Format, SamplerMode, Filter, pName, extraFlags);
return pTexture;
}

Expand Down
2 changes: 1 addition & 1 deletion framework/code/texture/vulkan/textureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TextureManagerT<Vulkan> final : public TextureManager

/// Create texture from a block of texture data in memory (with correct format, span etc).
/// Implements the base class virtual function.
std::unique_ptr<Texture> CreateTextureFromBuffer( GraphicsApiBase&, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName ) override;
std::unique_ptr<Texture> CreateTextureFromBuffer( GraphicsApiBase&, const void* pData, size_t DataSize, uint32_t Width, uint32_t Height, uint32_t Depth, TextureFormat Format, SamplerAddressMode SamplerMode, SamplerFilter Filter, const char* pName, uint32_t extraFlags = 0 ) override;

/// Create a texture that views (aliases) another texture but using a different texture format (must be 'related' formats, which formats are related is dependant on graphics api)
/// Implements the base class virtual function.
Expand Down
53 changes: 0 additions & 53 deletions samples/BloomImageProcessing/01_CompileShaders.bat

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ adb uninstall com.quic.BloomImageProcessing
@echo ****************************************
@echo Install ..\..\build\android\BloomImageProcessing\outputs\apk\debug\BloomImageProcessing-debug.apk
@echo ****************************************
adb install -r ..\..\build\android\BloomImageProcessing\outputs\apk\debug\BloomImageProcessing-debug.apk
adb install -r -g ..\..\build\android\BloomImageProcessing\outputs\apk\debug\BloomImageProcessing-debug.apk

@echo.
@echo ****************************************
Expand Down
18 changes: 2 additions & 16 deletions samples/BloomImageProcessing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ The following dependencies must be installed and the appropriate locations shoul
* CMake
* Android Studio

### Pre-Build

Compile the underlying shaders to .spv by running the batch file below:

```
01_CompileShaders.bat
```

And convert the needed textures to the correct format using the batch file below:

```
02_PrepareMedia.bat
```

### Build

Once the dependencies are installed and shaders compiled, building this sample .apk/.exe is as simple as running any of the batch files from the framework root directory, accordingly to your target system:
Expand All @@ -45,13 +31,13 @@ Once the dependencies are installed and shaders compiled, building this sample .
To deploy the media files and the .apk to a connected device, run the batch file below:

```
03_Install_APK.bat
01_Install_APK.bat
```

Optionally you can change the default configurations for this sample by upating the file **app_config.txt** and running the batch file below:

```
04_InstallConfig.bat
02_InstallConfig.bat
```

## Android Studio
Expand Down
41 changes: 36 additions & 5 deletions samples/BloomImageProcessing/code/main/bloom-image-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ VAR(bool, gUseExtension, true, kVariableNonpersistent);
VAR(unsigned, gBlurFilterSize, 7, kVariableNonpersistent);

#if OS_ANDROID
#define SHADERFILE(f) "./Shaders/" f
#define TEXTUREFILE(f) "./Textures/" f
#define SHADERFILE(f) "./Media/Shaders/" f
#define TEXTUREFILE(f) "./Media/Textures/" f
#else
#define SHADERFILE(f) "./Media/Shaders/" f
#define TEXTUREFILE(f) "./Media/Textures/" f
Expand Down Expand Up @@ -177,7 +177,22 @@ bool BloomImageprocessing::Initialize(uintptr_t windowHandle, uintptr_t hInstanc

if (ii == 1) // H
{
m_weightTextures[ii] = apiCast<Vulkan>(m_TextureManager->CreateTextureFromBuffer(*pVulkan, pHalfTexData, gBlurFilterSize * sizeof(float16), gBlurFilterSize, 1, 1, weightFormat, SamplerAddressMode::ClampEdge, SamplerFilter::Nearest/*, usageFlags, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL*/, nullptr));
#if 0
m_weightTextures[ii] = LoadTextureFromBuffer(
pVulkan, pHalfTexData, gBlurFilterSize * sizeof(float16),
gBlurFilterSize, 1, 1, weightFormat,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_FILTER_NEAREST,
usageFlags, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
#endif
m_weightTextures[ii] =
apiCast<Vulkan>(m_TextureManager->CreateTextureFromBuffer(
*pVulkan, pHalfTexData, gBlurFilterSize * sizeof(float16),
gBlurFilterSize, 1, 1, weightFormat,
SamplerAddressMode::ClampEdge,
SamplerFilter::Nearest,
nullptr,
(uint32_t)usageFlags));


weightViewInfo.filterCenter.x = gBlurFilterSize / 2;
weightViewInfo.filterCenter.y = 0;
Expand All @@ -186,7 +201,22 @@ bool BloomImageprocessing::Initialize(uintptr_t windowHandle, uintptr_t hInstanc
}
else // V
{
m_weightTextures[ii] = apiCast<Vulkan>(m_TextureManager->CreateTextureFromBuffer(*pVulkan, pHalfTexData, gBlurFilterSize * sizeof(float16), 1, gBlurFilterSize, 1, weightFormat, SamplerAddressMode::ClampEdge, SamplerFilter::Nearest/*, usageFlags, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL*/, nullptr));
#if 0
m_weightTextures[ii] = LoadTextureFromBuffer(
pVulkan, pHalfTexData, gBlurFilterSize * sizeof(float16), 1,
gBlurFilterSize, 1, weightFormat,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_FILTER_NEAREST,
usageFlags, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
#endif

m_weightTextures[ii] =
apiCast<Vulkan>(m_TextureManager->CreateTextureFromBuffer(
*pVulkan, pHalfTexData, gBlurFilterSize * sizeof(float16),
1, gBlurFilterSize, 1, weightFormat,
SamplerAddressMode::ClampEdge,
SamplerFilter::Nearest,
nullptr,
(uint32_t)usageFlags));

weightViewInfo.filterCenter.x = 0;
weightViewInfo.filterCenter.y = gBlurFilterSize / 2;
Expand All @@ -203,8 +233,9 @@ bool BloomImageprocessing::Initialize(uintptr_t windowHandle, uintptr_t hInstanc
}
}
}


if (pVulkan->IsTextureFormatSupported(TextureFormat::ASTC_4x4_UNORM_BLOCK))
if (/*pVulkan->IsTextureFormatSupported(TextureFormat::ASTC_4x4_UNORM_BLOCK)*/ false)
{
m_sourceTexture = apiCast<Vulkan>(m_TextureManager->GetOrLoadTexture(*m_AssetManager, TEXTUREFILE("painting_astc.ktx"), SamplerAddressMode::ClampEdge));
}
Expand Down
33 changes: 33 additions & 0 deletions samples/BloomImageProcessing/shaders/BlurBase-Horizontal-Ext.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//============================================================================================================
//
//
// Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
//
//============================================================================================================

#version 450

#extension GL_QCOM_image_processing : require

precision mediump float; precision mediump int;

layout(location = 0) noperspective in vec2 in_TEXCOORD0;

layout(set = 0, binding = 0, std140) uniform WeightInfo
{
vec4 weights[8];
} _Globals;


layout(set = 0, binding = 1) uniform texture2D SourceTexture;
layout(set = 0, binding = 2) uniform sampler SourceSampler;
layout(set = 0, binding = 3) uniform texture2DArray BloomWeightTexture;
layout(set = 0, binding = 4) uniform sampler BloomWeightSampler;

layout(location = 0) out vec4 FragColor;

void main()
{
FragColor = textureWeightedQCOM(sampler2D(SourceTexture, SourceSampler), in_TEXCOORD0, sampler2DArray(BloomWeightTexture, BloomWeightSampler));
}
38 changes: 38 additions & 0 deletions samples/BloomImageProcessing/shaders/BlurBase-Horizontal.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//============================================================================================================
//
//
// Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
//
//============================================================================================================

#version 450

precision mediump float; precision mediump int;

layout(location = 0) noperspective in vec2 in_TEXCOORD0;

layout(set = 0, binding = 0, std140) uniform WeightInfo
{
vec4 weights[8];
} _Globals;

layout(set = 0, binding = 1) uniform texture2D SourceTexture;
layout(set = 0, binding = 2) uniform sampler SourceSampler;

layout(location = 0) out vec4 FragColor;

void main()
{
const float StepX = 1.0 / 1920.0;
const float StepY = 0;

int WeightSize = int(_Globals.weights[0][0]);
FragColor = vec4(0);
for (int ww = 0; ww < WeightSize; ++ww)
{
float coordIndex = float(ww - WeightSize / 2);
ivec2 weightIndex = ivec2((ww + 1) / 4, (ww + 1) % 4);
FragColor += texture(sampler2D(SourceTexture, SourceSampler), in_TEXCOORD0 + vec2(coordIndex * StepX, coordIndex * StepY)) * _Globals.weights[weightIndex.x][weightIndex.y];
}
}
33 changes: 33 additions & 0 deletions samples/BloomImageProcessing/shaders/BlurBase-Vertical-Ext.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//============================================================================================================
//
//
// Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
//
//============================================================================================================

#version 450

#extension GL_QCOM_image_processing : require

precision mediump float; precision mediump int;

layout(location = 0) noperspective in vec2 in_TEXCOORD0;

layout(set = 0, binding = 0, std140) uniform WeightInfo
{
vec4 weights[8];
} _Globals;


layout(set = 0, binding = 1) uniform texture2D SourceTexture;
layout(set = 0, binding = 2) uniform sampler SourceSampler;
layout(set = 0, binding = 3) uniform texture2DArray BloomWeightTexture;
layout(set = 0, binding = 4) uniform sampler BloomWeightSampler;

layout(location = 0) out vec4 FragColor;

void main()
{
FragColor = textureWeightedQCOM(sampler2D(SourceTexture, SourceSampler), in_TEXCOORD0, sampler2DArray(BloomWeightTexture, BloomWeightSampler));
}
Loading

0 comments on commit 55b1d30

Please sign in to comment.