Skip to content

Commit

Permalink
Merge pull request #2334 from billhollings/disable-log-glsl
Browse files Browse the repository at this point in the history
Support disabling logging GLSL shader code during shader conversion logging.
  • Loading branch information
billhollings authored Sep 12, 2024
2 parents cf3a02d + 76cdec4 commit 2f7ae76
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
62 changes: 36 additions & 26 deletions Docs/MoltenVK_Configuration_Parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,28 @@ An alternate way to reverse the Y-axis is to employ a negative Y-axis value on
the viewport, in which case this parameter can be disabled.


---------------------------------------
#### MVK_CONFIG_SHADER_DUMP_DIR

##### Type: String
##### Default: `""`

_(The default value is an empty string)._

If not empty, **MoltenVK** will dump all SPIR-V shaders, compiled MSL shaders, and pipeline shader lists to the given directory.
The directory will be non-recursively created if it doesn't already exist.


---------------------------------------
#### MVK_CONFIG_SHADER_LOG_ESTIMATED_GLSL

##### Type: Boolean
##### Default: `0`

If the `MVK_CONFIG_DEBUG` parameter is enabled, and this parameter is enabled, when
SPIR-V code is converted to MSL, an estimate of the equivalent GLSL shader will be logged.


---------------------------------------
#### MVK_CONFIG_SHOULD_MAXIMIZE_CONCURRENT_COMPILATION

Expand Down Expand Up @@ -612,6 +634,20 @@ increases the number of buffers, textures and samplers that can be bound to a pi
cases improves performance.


---------------------------------------
#### MVK_CONFIG_USE_METAL_PRIVATE_API

##### Type: Boolean
##### Default: Value of `MVK_USE_METAL_PRIVATE_API`

If enabled, **MoltenVK** will _use_ private interfaces exposed by _Metal_ to implement _Vulkan_
features that are difficult to support otherwise.

Unlike `MVK_USE_METAL_PRIVATE_API`, this setting may be overridden at run time.

This option is not available unless **MoltenVK** was built with `MVK_USE_METAL_PRIVATE_API` set to `1`.


---------------------------------------
#### MVK_CONFIG_USE_MTLHEAP

Expand Down Expand Up @@ -648,29 +684,3 @@ Determines the style used to implement _Vulkan_ semaphore (`VkSemaphore`) functi

In the special case of `VK_SEMAPHORE_TYPE_TIMELINE` semaphores, **MoltenVK** will always use
`MTLSharedEvent` if it is available on the platform, regardless of the value of this parameter.


---------------------------------------
#### MVK_CONFIG_USE_METAL_PRIVATE_API

##### Type: Boolean
##### Default: Value of `MVK_USE_METAL_PRIVATE_API`

If enabled, **MoltenVK** will _use_ private interfaces exposed by _Metal_ to implement _Vulkan_
features that are difficult to support otherwise.

Unlike `MVK_USE_METAL_PRIVATE_API`, this setting may be overridden at run time.

This option is not available unless **MoltenVK** was built with `MVK_USE_METAL_PRIVATE_API` set to `1`.


---------------------------------------
#### MVK_CONFIG_SHADER_DUMP_DIR

##### Type: String
##### Default: `""`

_(The default value is an empty string)._

If not empty, **MoltenVK** will dump all SPIR-V shaders, compiled MSL shaders, and pipeline shader lists to the given directory.
The directory will be non-recursively created if it doesn't already exist.
3 changes: 3 additions & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ Released 2024-09-24
- Only add present handler if `VK_GOOGLE_display_timing` info is available during presentation.
- Move primitive-restart-disabled warning from renderpass to pipeline creation, to reduce voluminous log noise.
- iOS: Support storage images in _Metal_ argument buffers.
- Add `MVKConfiguration::shaderLogEstimatedGLSL`, and environment variable `MVK_CONFIG_SHADER_LOG_ESTIMATED_GLSL`,
to enable or disable the logging of estimated _GLSL_ code, and disable it by default
- Update dependency libraries to match _Vulkan SDK 1.3.295_.
- Update `MVK_PRIVATE_API_VERSION` to version `43`.



Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/API/mvk_private_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef unsigned long MTLArgumentBuffersTier;
*/


#define MVK_PRIVATE_API_VERSION 42
#define MVK_PRIVATE_API_VERSION 43


#pragma mark -
Expand Down Expand Up @@ -238,6 +238,7 @@ typedef struct {
float timestampPeriodLowPassAlpha; /**< MVK_CONFIG_TIMESTAMP_PERIOD_LOWPASS_ALPHA */
VkBool32 useMetalPrivateAPI; /**< MVK_CONFIG_USE_METAL_PRIVATE_API */
const char* shaderDumpDir; /**< MVK_CONFIG_SHADER_DUMP_DIR */
VkBool32 shaderLogEstimatedGLSL; /**< MVK_CONFIG_SHADER_LOG_ESTIMATED_GLSL */
} MVKConfiguration;

// Legacy support for renamed struct elements.
Expand Down
5 changes: 3 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKShaderModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ static uint32_t getWorkgroupDimensionSize(const SPIRVWorkgroupSizeDimension& wgD

bool MVKShaderModule::convert(SPIRVToMSLConversionConfiguration* pShaderConfig,
SPIRVToMSLConversionResult& conversionResult) {
bool shouldLogCode = getMVKConfig().debugMode;
bool shouldLogEstimatedGLSL = shouldLogCode;
const auto& mvkCfg = getMVKConfig();
bool shouldLogCode = mvkCfg.debugMode;
bool shouldLogEstimatedGLSL = shouldLogCode && mvkCfg.shaderLogEstimatedGLSL;

// If the SPIR-V converter does not have any code, but the GLSL converter does,
// convert the GLSL code to SPIR-V and set it into the SPIR-V conveter.
Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/Utility/MVKConfigMembers.def
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ MVK_CONFIG_MEMBER(shouldMaximizeConcurrentCompilation, VkBool32,
MVK_CONFIG_MEMBER(timestampPeriodLowPassAlpha, float, TIMESTAMP_PERIOD_LOWPASS_ALPHA)
MVK_CONFIG_MEMBER(useMetalPrivateAPI, VkBool32, USE_METAL_PRIVATE_API)
MVK_CONFIG_MEMBER_STRING(shaderDumpDir, char*, SHADER_DUMP_DIR)
MVK_CONFIG_MEMBER(shaderLogEstimatedGLSL, VkBool32, SHADER_LOG_ESTIMATED_GLSL)

#undef MVK_CONFIG_MEMBER
#undef MVK_CONFIG_MEMBER_STRING
Expand All @@ -99,5 +100,5 @@ MVK_CONFIG_MEMBER_STRING(shaderDumpDir, char*,
* Once MVKConfiguration and the list above are in agreement, it may be necessary to modify
* this value if the internal padding has changed as a result of new MVKConfiguration members.
*/
#define kMVKConfigurationInternalPaddingByteCount 4
#define kMVKConfigurationInternalPaddingByteCount 8

8 changes: 8 additions & 0 deletions MoltenVK/MoltenVK/Utility/MVKEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,11 @@ void mvkSetConfig(MVKConfiguration& dstMVKConfig, const MVKConfiguration& srcMVK
# define MVK_CONFIG_SHADER_DUMP_DIR ""
#endif

/**
* Enable logging estimated GLSL code during shader conversion.
* Disabled by default.
*/
#ifndef MVK_CONFIG_SHADER_LOG_ESTIMATED_GLSL
# define MVK_CONFIG_SHADER_LOG_ESTIMATED_GLSL 0
#endif

0 comments on commit 2f7ae76

Please sign in to comment.