summaryrefslogtreecommitdiffstats
path: root/tools/gfx/vulkan/vk-device.cpp
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-03-26 16:07:32 -0400
committerGitHub <noreply@github.com>2024-03-26 13:07:32 -0700
commit0877d1a3e9d69fdbf4087581df96954e56e4dd97 (patch)
tree3f7135d119908573013770ce0fbbee09701f6f26 /tools/gfx/vulkan/vk-device.cpp
parent57f514d09d3b879e238f37980456634e8286691c (diff)
Implement GLSL gimageDim & memory qualifiers with optional extension(s); resolves #3587 for GLSL & SPIR-V targets #3631 (#3810)
* [early push of code since memory qualifiers may be made into a seperate branch & pr and I rather make it simple to split the implementation if required] all type & functions impl. for GLSL image type added all memory qualifiers & tests for direct read/write [GLSL syntax] (DID NOT test or implement parameter qualifiers, that is next commit) * this inlcudes emit-glsl & emit-spirv for qualifier decorations * this also includes error handling * this includes parsing * full implementation other than Rect; all errors and basic tests are done & working what is left: 1. need to now add Rect type support (additional TextureImpl flag) 2. tests 3. testing infrastructure to support variety of types * testing framework now works with images of all types and imageBuffers -- next steps are actual tests * push code for mostly working image atomics; missing int64/uint64 tests and slightly broken feature likley due to missing code from master which I pushed for regular atomics * fix all remaining shader image atomic issues and tests to work with float & i64/u64 fully will now clean up code and squash the commits (since they are quite all over the place) * refactor code to work & look correct, fix all regressions Turned off tests for texture format R64 due to the shader use limitation of currently being only for storage buffers on most hardware (test fail cause, this is not allowed) Changed raygen.slang & nv-ray-tracing-motion-blur.slang since both cross-compiled with glslang, which does not respect layout(rgba8) for RWBuffer's, in this scenario making the type into a SPIR-V rgba32f, which is incorrect and a known problem, this causes different code to be outputted from Slang & HLSL+GLSL->Slang paths Clean up all code and better explain the "why" for the gimageDim definition we use various strings of Slang code, the gist is: 1. Parameters are structured as per IMAGE_PARAM keyword in spec, and we respect this in order to match specification (to allow easy code iteration) 2. sample parameters are required for functions 3. types are inconsistently named fixed regression of breaking l-value lowering when r-value should be lowered (lower-to-ir) fix compiler warnings remove unneeded lambdas `expr->type.isLeftValue = isMutableGLSLBufferBlockVarExpr(baseExpr) && (expr->type.hasReadOnlyOnTarget == false);` is an adjustment made such that a buffer block is mutable only if the block is mutable and the base expression is mutable (to handle case of readonly buffer block, immutable) * remove rectangle parameter * use proper const syntax and struct naming * adjust syntax * adjust modifier capabilitites: HLSL+GLSL --> GLSL. Notice most specifically, if the parent is a global struct we can put a memory qualifier, this does not include, struct inside a struct, with a member variable with a memory qualifier (since then you could use the struct in invalid ways). Added test for struct inside struct with member variable with memory qualifier. adjust syntax and remove code which will rot * adjust formatting for consistency * addressing review feedback addressing review feedback: change testing code to handle int and float/half correctly in all cases adjust testing code syntax as requested change vkdevice code to fit a different form as requested * adjust code as per requested for review: 1. adjusted testing code logic to handle non 0-1 values appropriately, notice int8_t will likley be the range and set order of {[0,127],[-1,-128]}, this is intentional 2. syntax adjustments for correctness * trying to fix falcor regressions * add back removed code for regression testing * test removing changes which may break falcor * Revert "test removing changes which may break falcor" This reverts commit 240da97f06c23e98a26ac23cf1d385995c67b251. * disable R64 support in attempt to fix falcor tests * Revert "disable R64 support in attempt to fix falcor tests" This reverts commit 317cb632eb2f47e980fc4aeafe418f8060f4c473. * disable major device changes (still trying to figure out falcor fails -- locally working different than CI) * test removing d3d changes * remove all format changes * add back removed code for regression testing * try something to get code to work with falcor * address review * Add way to handle constref/ref/encapsulated texture objects with memory qualifiers as a parameter. Fixed an issue (and improved codegen) for when we have a store(dst,load(src)) pattern, where dst is supposed to be equal to src for when resolving globalParam's (no need for work-arounds anymore) * move recent-fix/change to textureType loading into a proper optimization pass which now runs after SPIR-V legalization to catch odd SPIR-V emitting after legalizing types for SPIR-V * Revert most recent optimization pass change, add work around getting a unmangled global parameter address through a intrinsic op instead of spir-v intrinsic (works same as `__imagePointer()`) * remove unneeded changes * remove unneeded `__constref` in glsl.meta * move memory qualifier checks to visitInvoke of check-expr.cpp move GetLegalizedSPIRVGlobalParamAddr resolving to spirv-legalization pass move error for "if using non texture type with memory qualifer in param" earlier such that we error with this first. No point in telling user "you are not putting correct memory qualifiers" when memory qualifiers should not have been used. * add memory qualifier folding modifier 'MemoryQualifierCollectionModifier' to reduce searching and processing (later will be adapted to whole system) as suggested/asked. The utility is a method to track memory qualifiers without doing a expensive linked-list traversal (image's have 4 modifiers normally). * properly pass multiple qualifiers from checkModifier down to the `modifier`s list * addressing review comments: * change implementation to properly handle restrict modifier * add comments about implementation for clarity
Diffstat (limited to 'tools/gfx/vulkan/vk-device.cpp')
-rw-r--r--tools/gfx/vulkan/vk-device.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/tools/gfx/vulkan/vk-device.cpp b/tools/gfx/vulkan/vk-device.cpp
index b2cbb03c1..dd8a674cb 100644
--- a/tools/gfx/vulkan/vk-device.cpp
+++ b/tools/gfx/vulkan/vk-device.cpp
@@ -487,6 +487,11 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
extendedFeatures.atomicFloat2Features.pNext = deviceFeatures2.pNext;
deviceFeatures2.pNext = &extendedFeatures.atomicFloat2Features;
+ // Image Int64 Atomic
+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT.html
+ extendedFeatures.imageInt64AtomicFeatures.pNext = deviceFeatures2.pNext;
+ deviceFeatures2.pNext = &extendedFeatures.imageInt64AtomicFeatures;
+
// mesh shader features
extendedFeatures.meshShaderFeatures.pNext = deviceFeatures2.pNext;
deviceFeatures2.pNext = &extendedFeatures.meshShaderFeatures;
@@ -580,6 +585,13 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
);
SIMPLE_EXTENSION_FEATURE(
+ extendedFeatures.imageInt64AtomicFeatures,
+ shaderImageInt64Atomics,
+ VK_EXT_SHADER_IMAGE_ATOMIC_INT64_EXTENSION_NAME,
+ "image-atomic-int64"
+ );
+
+ SIMPLE_EXTENSION_FEATURE(
extendedFeatures.extendedDynamicStateFeatures,
extendedDynamicState,
VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME,
@@ -1638,6 +1650,97 @@ Result DeviceImpl::createTextureResource(
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
+ if(desc.sampleDesc.numSamples != 1)
+ {
+ // Handle senario where texture is sampled. We cannot use
+ // a simple buffer copy for sampled textures. ClearColorImage
+ // is not data accurate but it is fine for testing & works.
+ FormatInfo formatInfo;
+ gfxGetFormatInfo(desc.format, &formatInfo);
+ uint32_t data = 0;
+ VkClearColorValue clearColor;
+ switch(formatInfo.channelType)
+ {
+ case SLANG_SCALAR_TYPE_INT32:
+ for(int i = 0; i < 4; i++)
+ clearColor.int32[i] = *reinterpret_cast<int32_t*>(const_cast<void*>(initData->data));
+ break;
+ case SLANG_SCALAR_TYPE_UINT32:
+ for(int i = 0; i < 4; i++)
+ clearColor.uint32[i] = *reinterpret_cast<uint32_t*>(const_cast<void*>(initData->data)); break;
+ break;
+ case SLANG_SCALAR_TYPE_INT64:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.int32[i] = int32_t(*reinterpret_cast<int64_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_UINT64:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.uint32[i] = uint32_t(*reinterpret_cast<uint64_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_FLOAT16:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.float32[i] = HalfToFloat(*reinterpret_cast<uint16_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_FLOAT32:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.float32[i] = (*reinterpret_cast<float*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_FLOAT64:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.float32[i] = float(*reinterpret_cast<double*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_INT8:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.int32[i] = int32_t(*reinterpret_cast<int8_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_UINT8:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.uint32[i] = uint32_t(*reinterpret_cast<uint8_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_INT16:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.int32[i] = int32_t(*reinterpret_cast<int16_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ case SLANG_SCALAR_TYPE_UINT16:
+ {
+ for(int i = 0; i < 4; i++)
+ clearColor.uint32[i] = uint32_t(*reinterpret_cast<uint16_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
+ };
+
+ VkImageSubresourceRange range{};
+ range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ range.baseMipLevel = 0;
+ range.levelCount = VK_REMAINING_MIP_LEVELS;
+ range.baseArrayLayer = 0;
+ range.layerCount = VK_REMAINING_ARRAY_LAYERS;
+
+ m_api.vkCmdClearColorImage(
+ commandBuffer,
+ texture->m_image,
+ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ &clearColor,
+ 1,
+ &range);
+ }
+ else
{
Offset srcOffset = 0;
for (int i = 0; i < arraySize; ++i)
@@ -2154,6 +2257,23 @@ Result DeviceImpl::createBufferView(
info.buffer = resourceImpl->m_buffer.m_buffer;
info.offset = offset;
info.range = size;
+ VkBufferUsageFlags2CreateInfoKHR bufferViewUsage{};
+ bufferViewUsage.sType = VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR;
+
+ if (desc.type == IResourceView::Type::UnorderedAccess)
+ {
+ info.pNext = &bufferViewUsage;
+ bufferViewUsage.usage = VK_BUFFER_USAGE_2_STORAGE_TEXEL_BUFFER_BIT_KHR;
+ }
+ else if (desc.type == IResourceView::Type::ShaderResource)
+ {
+ info.pNext = &bufferViewUsage;
+ bufferViewUsage.usage = VK_BUFFER_USAGE_2_UNIFORM_TEXEL_BUFFER_BIT_KHR;
+ }
+ else
+ {
+ assert(!"unhandled");
+ }
SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateBufferView(m_device, &info, nullptr, &view));
}