Skip to content

Commit

Permalink
Fix warnings regarding #pragma clang
Browse files Browse the repository at this point in the history
'#pragma clang' is unavailable in MSVC. Wrap them with the proper
preprocessor to avoid warnings in MSVC.

BUGS=[390207431]
  • Loading branch information
z3moon committed Feb 2, 2025
1 parent 793f2b4 commit 57b631a
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions filament/backend/include/private/backend/DriverAPI.inc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@
* Driver API below...
*/

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif

DECL_DRIVER_API_0(tick)

Expand Down Expand Up @@ -533,7 +535,9 @@ DECL_DRIVER_API_N(scissor,
Viewport, scissor)


#if defined(__clang__)
#pragma clang diagnostic pop
#endif

#undef EXPAND

Expand Down
4 changes: 4 additions & 0 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@
#include <emscripten.h>
#endif

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#endif

// We can only support this feature on OpenGL ES 3.1+
// Support is currently disabled as we don't need it
Expand Down Expand Up @@ -4094,4 +4096,6 @@ template class ConcreteDispatcher<OpenGLDriver>;

} // namespace filament::backend

#if defined(__clang__)
#pragma clang diagnostic pop
#endif
4 changes: 4 additions & 0 deletions filament/backend/src/vulkan/VulkanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ using namespace bluevk;

using utils::FixedCapacityVector;

#if defined(__clang__)
// Vulkan functions often immediately dereference pointers, so it's fine to pass in a pointer
// to a stack-allocated variable.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-stack-address"
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif

namespace filament::backend {

Expand Down Expand Up @@ -1882,4 +1884,6 @@ template class ConcreteDispatcher<VulkanDriver>;

} // namespace filament::backend

#if defined(__clang__)
#pragma clang diagnostic pop
#endif
5 changes: 5 additions & 0 deletions filament/backend/src/vulkan/VulkanMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <bluevk/BlueVK.h> // must be included before vk_mem_alloc

#if defined(__clang__)
#pragma clang diagnostic push

// Needed because not all clang versions have the warning -Wdeprecated-copy.
Expand All @@ -32,11 +33,15 @@
#pragma clang diagnostic ignored "-Wextra-semi"
#pragma clang diagnostic ignored "-Wc++98-compat-extra-semi"
#pragma clang diagnostic ignored "-Wthread-safety-analysis"
#endif

static const PFN_vkGetInstanceProcAddr& vkGetInstanceProcAddr = bluevk::vkGetInstanceProcAddr;
static const PFN_vkGetDeviceProcAddr& vkGetDeviceProcAddr = bluevk::vkGetDeviceProcAddr;

#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"

#if defined(__clang__)
#pragma clang diagnostic pop
#endif
2 changes: 2 additions & 0 deletions filament/backend/src/vulkan/VulkanMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
#endif

#if defined(__clang__)
#pragma clang diagnostic ignored "-Wc++98-compat-extra-semi"
#endif

#include "vk_mem_alloc.h"

Expand Down
4 changes: 4 additions & 0 deletions filament/backend/src/vulkan/VulkanPipelineCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
#include "VulkanTexture.h"
#include "VulkanUtility.h"

#if defined(__clang__)
// Vulkan functions often immediately dereference pointers, so it's fine to pass in a pointer
// to a stack-allocated variable.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-stack-address"
#endif

using namespace bluevk;

Expand Down Expand Up @@ -323,4 +325,6 @@ bool VulkanPipelineCache::PipelineEqual::operator()(const PipelineKey& k1,

} // namespace filament::backend

#if defined(__clang__)
#pragma clang diagnostic pop
#endif
4 changes: 4 additions & 0 deletions filament/backend/src/vulkan/VulkanPipelineCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class VulkanPipelineCache {
VkSpecializationInfo* specializationInfos = nullptr;
};

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
#endif

// The RasterState POD contains standard graphics-related state like blending, culling, etc.
// The following states are omitted because Filament never changes them:
Expand Down Expand Up @@ -212,7 +214,9 @@ class VulkanPipelineCache {
bool operator()(const PipelineKey& k1, const PipelineKey& k2) const;
};

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

// CACHE ENTRY STRUCTS
// -------------------
Expand Down
8 changes: 8 additions & 0 deletions filament/src/Culler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ void Culler::intersects(
float4 const * const UTILS_RESTRICT planes = frustum.mPlanes;

count = round(count);
#if defined(__clang__)
#pragma clang loop vectorize_width(FILAMENT_CULLER_VECTORIZE_HINT)
#endif
for (size_t i = 0; i < count; i++) {
int visible = ~0;
float4 const sphere(b[i]);

#if defined(__clang__)
#pragma clang loop unroll(full)
#endif
for (size_t j = 0; j < 6; j++) {
// clang doesn't seem to generate vector * scalar instructions, which leads
// to increased register pressure and stack spills
Expand All @@ -69,11 +73,15 @@ void Culler::intersects(
float4 const * UTILS_RESTRICT const planes = frustum.mPlanes;

count = round(count);
#if defined(__clang__)
#pragma clang loop vectorize_width(FILAMENT_CULLER_VECTORIZE_HINT)
#endif
for (size_t i = 0; i < count; i++) {
int visible = ~0;

#if defined(__clang__)
#pragma clang loop unroll(full)
#endif
for (size_t j = 0; j < 6; j++) {
// clang doesn't seem to generate vector * scalar instructions, which leads
// to increased register pressure and stack spills
Expand Down
2 changes: 2 additions & 0 deletions filament/src/Froxelizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ bool Froxelizer::update() noexcept {
const float linearizer = std::log2(zLightFar / zLightNear) / float(std::max(1u, mFroxelCountZ - 1u));
// for a strange reason when, vectorizing this loop, clang does some math in double
// and generates conversions to float. not worth it for so little iterations.
#if defined(__clang__)
#pragma clang loop vectorize(disable) unroll(disable)
#endif
for (ssize_t i = 1, n = mFroxelCountZ; i <= n; i++) {
mDistancesZ[i] = zLightFar * std::exp2(float(i - n) * linearizer);
}
Expand Down
4 changes: 4 additions & 0 deletions filament/src/ToneMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ float3 DisplayRangeToneMapper::operator()(float3 const c) const noexcept {
//------------------------------------------------------------------------------

struct GenericToneMapper::Options {
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#endif
void setParameters(
float contrast,
float midGrayIn,
Expand All @@ -424,7 +426,9 @@ struct GenericToneMapper::Options {
inputScale = (a * b * (midGrayOut - 1.0f)) / c;
outputScale = midGrayOut * (a - b) / c;
}
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

float contrast;
float midGrayIn;
Expand Down
14 changes: 14 additions & 0 deletions filament/src/details/ColorGrading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ using namespace backend;
struct ColorGrading::BuilderDetails {
const ToneMapper* toneMapper = nullptr;

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
ToneMapping toneMapping = ToneMapping::ACES_LEGACY;
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

bool hasAdjustments = false;

Expand Down Expand Up @@ -268,8 +272,10 @@ ColorGrading::Builder& ColorGrading::Builder::outputColorSpace(
return *this;
}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
ColorGrading* ColorGrading::Builder::build(Engine& engine) {
// We want to see if any of the default adjustment values have been modified
// We skip the tonemapping operator on purpose since we always want to apply it
Expand Down Expand Up @@ -309,7 +315,9 @@ ColorGrading* ColorGrading::Builder::build(Engine& engine) {
return colorGrading;
}

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

//------------------------------------------------------------------------------
// Exposure
Expand Down Expand Up @@ -585,8 +593,10 @@ static std::tuple<TextureFormat, PixelDataFormat, PixelDataType>
}
}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
// The following functions exist to preserve backward compatibility with the
// `FILMIC` set via the deprecated `ToneMapping` API. Selecting `ToneMapping::FILMIC`
// forces post-processing to be performed in sRGB to guarantee that the inverse tone
Expand All @@ -612,7 +622,9 @@ static float3 selectColorGradingLuminance(ColorGrading::ToneMapping const toneMa
}
return LUMINANCE_Rec2020;
}
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

using ColorTransform = float3(*)(float3);

Expand Down Expand Up @@ -792,7 +804,9 @@ FColorGrading::FColorGrading(FEngine& engine, const Builder& builder) {
// we use a vectorize width of 8 because, on ARMv8 it allows the compiler to write eight
// 32-bits results in one go.
const size_t count = (config.lutDimension * config.lutDimension) & ~0x7u; // tell the compiler that we're a multiple of 8
#if defined(__clang__)
#pragma clang loop vectorize_width(8)
#endif
for (size_t i = 0; i < count; ++i) {
float4 v{src[i]};
uint32_t pr = uint32_t(std::floor(v.x * 1023.0f + 0.5f));
Expand Down
4 changes: 4 additions & 0 deletions filament/src/fsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ namespace filament {

using namespace math;

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wignored-qualifiers"
#endif

#define A_CPU 1
#include "materials/fsr/ffx_a.h"
#define FSR_EASU_F 1
#define FSR_RCAS_F 1
#include "materials/fsr/ffx_fsr1.h"

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

void FSR_ScalingSetup(FSRUniforms* outUniforms, FSRScalingConfig config) noexcept {
// FsrEasu API claims it needs the left-top offset, however that's not true with OpenGL,
Expand Down

0 comments on commit 57b631a

Please sign in to comment.