-
Notifications
You must be signed in to change notification settings - Fork 173
Allow printf in shaders #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
koubaa
wants to merge
4
commits into
KomputeProject:master
Choose a base branch
from
koubaa:printf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,34 @@ | |
#include <string> | ||
#include <unordered_map> | ||
|
||
template <> struct fmt::formatter<vk::ValidationFeatureEnableEXT>: public fmt::formatter<std::string> { | ||
|
||
// parse is inherited from formatter<string>. | ||
|
||
template <typename Context> | ||
fmt::format_context::iterator format (vk::ValidationFeatureEnableEXT const& flag, Context& ctx) const { | ||
std::string name {"unknown"}; | ||
switch(flag) { | ||
case vk::ValidationFeatureEnableEXT::eDebugPrintf: | ||
name = "debugPrintF"; | ||
break; | ||
case vk::ValidationFeatureEnableEXT::eGpuAssisted: | ||
name = "gpuAssisted"; | ||
break; | ||
case vk::ValidationFeatureEnableEXT::eGpuAssistedReserveBindingSlot: | ||
name = "gpuAssistedReserveBindingSlot"; | ||
break; | ||
case vk::ValidationFeatureEnableEXT::eBestPractices: | ||
name = "bestPractices"; | ||
break; | ||
case vk::ValidationFeatureEnableEXT::eSynchronizationValidation: | ||
name = "synchronizationValidation"; | ||
break; | ||
} | ||
return fmt::formatter<std::string>::format(name, ctx); | ||
} | ||
}; | ||
|
||
namespace kp { | ||
|
||
#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS | ||
|
@@ -185,10 +213,11 @@ Manager::createInstance() | |
#endif | ||
|
||
if (!applicationExtensions.empty()) { | ||
computeInstanceCreateInfo.enabledExtensionCount = | ||
(uint32_t)applicationExtensions.size(); | ||
computeInstanceCreateInfo.ppEnabledExtensionNames = | ||
applicationExtensions.data(); | ||
computeInstanceCreateInfo.setEnabledExtensionCount( | ||
(uint32_t)applicationExtensions.size()); | ||
computeInstanceCreateInfo.setPpEnabledExtensionNames( | ||
applicationExtensions.data()); | ||
KP_LOG_DEBUG("Desired extensions: {}", fmt::join(applicationExtensions, ", ")); | ||
} | ||
|
||
#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS | ||
|
@@ -212,7 +241,21 @@ Manager::createInstance() | |
for (const std::string& layerName : envLayerNames) { | ||
desiredLayerNames.push_back(layerName.c_str()); | ||
} | ||
KP_LOG_DEBUG("Desired layers: {}", fmt::join(desiredLayerNames, ", ")); | ||
} | ||
KP_LOG_DEBUG("Desired layers: {}", fmt::join(desiredLayerNames, ", ")); | ||
|
||
vk::ValidationFeaturesEXT validationFeatures; | ||
std::vector<vk::ValidationFeatureEnableEXT> validationFeatureEnablesExt; | ||
const char* envPrintfVal = std::getenv("KOMPUTE_ENV_PRINTF"); | ||
if (envPrintfVal != nullptr && *envPrintfVal != '\0') { | ||
KP_LOG_DEBUG("Kompute Manager adding debug printf"); | ||
validationFeatureEnablesExt.push_back(vk::ValidationFeatureEnableEXT::eDebugPrintf); | ||
} | ||
|
||
if (!validationFeatureEnablesExt.empty()) { | ||
validationFeatures.setEnabledValidationFeatures(validationFeatureEnablesExt); | ||
computeInstanceCreateInfo.setPNext(&validationFeatures); | ||
KP_LOG_DEBUG("Validation features: {}", fmt::join(validationFeatureEnablesExt, ", ")); | ||
} | ||
|
||
// Identify the valid layer names based on the desiredLayerNames | ||
|
@@ -236,9 +279,9 @@ Manager::createInstance() | |
KP_LOG_DEBUG( | ||
"Kompute Manager Initializing instance with valid layers: {}", | ||
fmt::join(validLayerNames, ", ")); | ||
computeInstanceCreateInfo.enabledLayerCount = | ||
static_cast<uint32_t>(validLayerNames.size()); | ||
computeInstanceCreateInfo.ppEnabledLayerNames = validLayerNames.data(); | ||
computeInstanceCreateInfo.setEnabledLayerCount( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for next ones but I like the usage of the VKCPP capabilities |
||
static_cast<uint32_t>(validLayerNames.size())); | ||
computeInstanceCreateInfo.setPpEnabledLayerNames(validLayerNames.data()); | ||
} else { | ||
KP_LOG_WARN("Kompute Manager no valid layer names found from desired " | ||
"layer names"); | ||
|
@@ -268,15 +311,14 @@ Manager::createInstance() | |
KP_LOG_DEBUG("Kompute Manager Instance Created"); | ||
|
||
#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS | ||
KP_LOG_DEBUG("Kompute Manager adding debug callbacks"); | ||
if (validLayerNames.size() > 0) { | ||
KP_LOG_DEBUG("Kompute Manager adding debug callbacks"); | ||
vk::DebugReportFlagsEXT debugFlags = | ||
vk::DebugReportFlagBitsEXT::eError | | ||
vk::DebugReportFlagBitsEXT::eWarning; | ||
vk::DebugReportCallbackCreateInfoEXT debugCreateInfo = {}; | ||
debugCreateInfo.pfnCallback = | ||
(PFN_vkDebugReportCallbackEXT)debugMessageCallback; | ||
debugCreateInfo.flags = debugFlags; | ||
auto debugCreateInfo = vk::DebugReportCallbackCreateInfoEXT() | ||
.setFlags(debugFlags) | ||
.setPfnCallback((PFN_vkDebugReportCallbackEXT)debugMessageCallback); | ||
|
||
this->mDebugDispatcher.init(*this->mInstance, &vkGetInstanceProcAddr); | ||
this->mDebugReportCallback = | ||
|
@@ -384,6 +426,7 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices, | |
} else { | ||
this->mComputeQueueFamilyIndices = familyQueueIndices; | ||
} | ||
KP_LOG_DEBUG("compute queue family indices: {}", fmt::join(this->mComputeQueueFamilyIndices, ", ")); | ||
|
||
std::unordered_map<uint32_t, uint32_t> familyQueueCounts; | ||
std::unordered_map<uint32_t, std::vector<float>> familyQueuePriorities; | ||
|
@@ -425,11 +468,15 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices, | |
validExtensions.push_back(ext.c_str()); | ||
} | ||
} | ||
|
||
if (desiredExtensions.size() != validExtensions.size()) { | ||
KP_LOG_ERROR("Kompute Manager not all extensions were added: {}", | ||
fmt::join(validExtensions, ", ")); | ||
} | ||
|
||
KP_LOG_DEBUG("Kompute Manager used extensions {}", | ||
fmt::join(validExtensions, ", ")); | ||
|
||
vk::DeviceCreateInfo deviceCreateInfo(vk::DeviceCreateFlags(), | ||
deviceQueueCreateInfos.size(), | ||
deviceQueueCreateInfos.data(), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it is already understandable, I would put an enum for the level (just to have a meaningful level name from "trace" to "error")