From 024a42e6910b31ececf58b452716f274bec9bc9d Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 8 Apr 2026 14:15:14 -0500 Subject: [PATCH] remove bufferdeviceaddress --- shader/triangle.hlsl | 13 +++++++------ src/main.cpp | 14 ++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/shader/triangle.hlsl b/shader/triangle.hlsl index a9b7139..36c04b4 100644 --- a/shader/triangle.hlsl +++ b/shader/triangle.hlsl @@ -27,7 +27,8 @@ struct PushConstant { }; [[vk::push_constant]] -struct PushConstant constants; +ShaderData data; +//struct PushConstant constants; [[vk::binding(0)]] SamplerState samplers[]; [[vk::binding(0)]] Texture2D textures[]; @@ -36,12 +37,12 @@ struct PushConstant constants; VSOutput VSMain(VSInput input) { VSOutput output = (VSOutput)0; - output.Position = mul(constants.data.Get().Transform, float4(input.Position.xyz, 1.0)); - output.Normal = mul((float3x3)constants.data.Get().ModelView, input.Normal); + output.Position = mul(data.Transform, float4(input.Position.xyz, 1.0)); + output.Normal = mul((float3x3)data.ModelView, input.Normal); output.Texture = input.Texture.xy; - float4 viewPosition = mul(constants.data.Get().ModelView, float4(input.Position.xyz, 1.0)); - output.LightDirection = (constants.data.Get().LightPosition - viewPosition).xyz; + float4 viewPosition = mul(data.ModelView, float4(input.Position.xyz, 1.0)); + output.LightDirection = (data.LightPosition - viewPosition).xyz; output.ViewDirection = -viewPosition.xyz; return output; @@ -75,7 +76,7 @@ VSOutlineOutput VSOutlineMain(VSInput input) { VSOutlineOutput output = (VSOutlineOutput)0; float3 position = input.Position.xyz + input.Normal.xyz * 0.01; - output.Position = mul(constants.data.Get().Transform, float4(position, 1.0)); + output.Position = mul(data.Transform, float4(position, 1.0)); return output; } diff --git a/src/main.cpp b/src/main.cpp index dad2b8b..5e69c3d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -509,7 +509,7 @@ int main() .shaderSampledImageArrayNonUniformIndexing = true, .descriptorBindingVariableDescriptorCount = true, .runtimeDescriptorArray = true, - .bufferDeviceAddress = true + //.bufferDeviceAddress = true }; VkPhysicalDeviceVulkan13Features enabledVulkan13Features{ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, @@ -649,7 +649,7 @@ int main() vkGetBufferMemoryRequirements(device, shaderDataDevice.frame[0].buffer, &memoryRequirements); VkMemoryPropertyFlags memoryPropertyFlags{ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT }; - VkMemoryAllocateFlags memoryAllocateFlags{ VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT }; + VkMemoryAllocateFlags memoryAllocateFlags{ /*VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT*/ }; shaderDataDevice.stride = allocateFromMemoryRequirements(physicalDeviceMemoryProperties, memoryRequirements, memoryPropertyFlags, @@ -667,11 +667,13 @@ int main() VK_CHECK(vkBindBufferMemory(device, shaderDataDevice.frame[i].buffer, shaderDataDevice.memory, offset)); + /* VkBufferDeviceAddressInfo bufferDeviceAddressInfo{ .sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO, .buffer = shaderDataDevice.frame[i].buffer }; shaderDataDevice.frame[i].deviceAddress = vkGetBufferDeviceAddress(device, &bufferDeviceAddressInfo); + */ } } @@ -979,7 +981,8 @@ int main() VkPushConstantRange pushConstantRange{ .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, - .size = (sizeof (VkDeviceAddress)) + //.size = (sizeof (VkDeviceAddress)) + .size = (sizeof (ShaderData)) }; VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo{ .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, @@ -1201,6 +1204,7 @@ int main() size_t frameOffset = shaderDataDevice.stride * frameIndex; void * frameData = (void *)(((VkDeviceSize)shaderDataDevice.mappedData) + frameOffset); VkDeviceSize frameSize{ (sizeof (ShaderData)) }; + /* memcpy(frameData, &shaderData, frameSize); VkDeviceSize flushSize{ roundAlignment(frameSize, physicalDeviceProperties.limits.nonCoherentAtomSize) }; VkMappedMemoryRange shaderDataMemoryRange{ @@ -1210,6 +1214,7 @@ int main() .size = flushSize, }; vkFlushMappedMemoryRanges(device, 1, &shaderDataMemoryRange); + */ // command buffer VkCommandBuffer& commandBuffer = commandBuffers[frameIndex]; @@ -1302,7 +1307,8 @@ int main() vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexIndexBuffer, &vertexOffset); VkDeviceSize indexOffset{ vertexBufferSize }; vkCmdBindIndexBuffer(commandBuffer, vertexIndexBuffer, indexOffset, VK_INDEX_TYPE_UINT32); - vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, (sizeof (VkDeviceAddress)), &shaderDataDevice.frame[frameIndex].deviceAddress); + //vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, (sizeof (VkDeviceAddress)), &shaderDataDevice.frame[frameIndex].deviceAddress); + vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, (sizeof (ShaderData)), &shaderData); VkDeviceSize indexCount{ 9216 }; vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines[MAIN_PIPELINE]);