Fix compile time with MSVC (Release) #117534

Merged
Brecht Van Lommel merged 2 commits from pbo/blender:fix_compile_time into main 2024-01-28 12:13:06 +01:00
Contributor

While investigating blender compilation time for windows-arm64, we identified two compilation units that were taking a long time to compile (~1h each).
This affects windows-x64 builds as well (not related to a specific architecture, but to MSVC itself).

While investigating blender compilation time for windows-arm64, we identified two compilation units that were taking a long time to compile (~1h each). This affects windows-x64 builds as well (not related to a specific architecture, but to MSVC itself).
Iliya Katushenock added this to the Platforms, Builds Tests & Devices project 2024-01-26 10:17:28 +01:00
Iliya Katushenock added the
Module
Render & Cycles
Platform
Windows
labels 2024-01-26 10:17:37 +01:00
Author
Contributor

@LazyDodo This will probably interests you, since it drastically speeds up (some) incremental rebuilds when using MSVC.

@LazyDodo This will probably interests you, since it drastically speeds up (some) incremental rebuilds when using MSVC.
pbo requested review from Ray molenkamp 2024-01-26 11:35:52 +01:00
Aras Pranckevicius reviewed 2024-01-26 11:40:32 +01:00
@ -413,6 +413,14 @@ void ShaderCreateInfo::validate_vertex_attributes(const ShaderCreateInfo *other_
using namespace blender::gpu::shader;
#ifdef _MSC_VER

Would probably be good to restore previous flag after this function though, as right now this affects the whole rest of the file, right?

Would probably be good to restore previous flag after this function though, as right now this affects the whole rest of the file, right?
Author
Contributor

You're right, I was misleaded by MSDN documentation mentioning "function-by-function basis".

You're right, I was misleaded by MSDN documentation mentioning "function-by-function basis".
pbo marked this conversation as resolved
pbo force-pushed fix_compile_time from 4d933888cd to 2384598481 2024-01-26 11:51:11 +01:00 Compare
Author
Contributor

Added "pragma optimize on" after function having a problem.

Added "pragma optimize on" after function having a problem.
Aras Pranckevicius reviewed 2024-01-26 11:55:30 +01:00
@ -554,2 +563,4 @@
// gpu_shader_create_info_compile(nullptr);
}
#ifdef _MSC_VER
#pragma optimize( "", on )

...now this will turn on optimization even for Debug builds though :/

...now this will turn on optimization even for Debug builds though :/
Author
Contributor

From: https://learn.microsoft.com/en-us/cpp/preprocessor/optimize?view=msvc-170

When you use the on parameter, it resets the optimizations to the ones that you specified using the /O compiler option.

So that would suggest in Debug, we don't enable any specific optimization. Does that sounds right?

From: https://learn.microsoft.com/en-us/cpp/preprocessor/optimize?view=msvc-170 > When you use the on parameter, it resets the optimizations to the ones that you specified using the /O compiler option. So that would suggest in Debug, we don't enable any specific optimization. Does that sounds right?

Ah sorry, ignore me, I read the MSDN docs wrong. Looks indeed like #pragma optimize("", on) means "use defaults / command line".

Ah sorry, ignore me, I read the MSDN docs wrong. Looks indeed like `#pragma optimize("", on)` means "use defaults / command line".
aras_p marked this conversation as resolved
Member

The one in gpu_shader_create_info.cc i have no issues landing, msvc just tends to struggle with very long functions we've done this exact setup in the past for i think glew.

The one in cycles i'm gonna need the cycles team to sign off on this, as it very likely could cause a performance regression

The one in `gpu_shader_create_info.cc` i have no issues landing, msvc just tends to struggle with very long functions we've done this exact setup in the past for i think glew. The one in cycles i'm gonna need the cycles team to sign off on this, as it very likely could cause a performance regression
Brecht Van Lommel requested changes 2024-01-26 16:13:14 +01:00
@ -245,0 +241,4 @@
#ifndef _MSC_VER
/* MSVC has very long compilation time (x20) if we inline this function */
ccl_device_forceinline
#endif

Can it be changed to this?

#if defined(__KERNEL_GPU__)
ccl_device_forceinline 
#else
/* MSVC has very long compilation time (x20) if we force inline this function */ 
ccl_device
#endif

The main reason for force inline this kind of thing is the GPU, not doing that doesn't have to be MSVC specific.

ccl_device is static inline, which makes it a private function without warnings if unused. It should not force any inlining to happen.

Can it be changed to this? ``` #if defined(__KERNEL_GPU__) ccl_device_forceinline #else /* MSVC has very long compilation time (x20) if we force inline this function */ ccl_device #endif ``` The main reason for force inline this kind of thing is the GPU, not doing that doesn't have to be MSVC specific. `ccl_device` is `static inline`, which makes it a private function without warnings if unused. It should not force any inlining to happen.
Author
Contributor

Implemented your version,

Implemented your version,
pbo marked this conversation as resolved
pbo force-pushed fix_compile_time from 2384598481 to 502db13495 2024-01-27 18:28:52 +01:00 Compare
Brecht Van Lommel approved these changes 2024-01-27 18:31:55 +01:00
Author
Contributor

Switched kernel inline to version suggested in comment.

Switched kernel inline to version suggested in comment.

@blender-bot build

@blender-bot build
pbo force-pushed fix_compile_time from 502db13495 to bf2e18784a 2024-01-27 18:33:29 +01:00 Compare
Author
Contributor

Rebased on top of main.

Rebased on top of main.
Author
Contributor

(sorry, I think it conflicted with the build command you required)

(sorry, I think it conflicted with the build command you required)

No problem, will just do it again.

@blender-bot build

No problem, will just do it again. @blender-bot build
pbo force-pushed fix_compile_time from bf2e18784a to 481ccf3cfd 2024-01-27 19:03:50 +01:00 Compare
Author
Contributor

Fixed formatting (lint fail).

Fixed formatting (lint fail).
Author
Contributor

Another CI pass, and we should be good to go. In CI job, blender compile on windows-x64 went from 15min to 9min.

Another CI pass, and we should be good to go. In CI job, blender compile on windows-x64 went from 15min to 9min.

@blender-bot build

@blender-bot build
Author
Contributor

@brecht The fail remaining in lint job is not a file I modified. Are we supposed to fix format too as part of this PR?

@brecht The fail remaining in lint job is not a file I modified. Are we supposed to fix format too as part of this PR?
Brecht Van Lommel approved these changes 2024-01-28 11:58:57 +01:00
Brecht Van Lommel left a comment
Owner

That can just be ignored. Thanks for the contribution.

That can just be ignored. Thanks for the contribution.
Brecht Van Lommel merged commit a3d915310b into main 2024-01-28 12:13:06 +01:00
Brecht Van Lommel deleted branch fix_compile_time 2024-01-28 12:13:09 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#117534
No description provided.