mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2025-04-12 20:38:31 +08:00
Capture base address
Set in Push Constant Use in Shader
This commit is contained in:
parent
4c13a82d0c
commit
47de764ba9
|
@ -290,7 +290,7 @@ void MonteCarloPiSimulation::setupSimulationAllocations() {
|
|||
cuMemSetAccess(d_ptr, m_totalAllocationSize, &accessDescriptor, 1));
|
||||
|
||||
// fill the BDA buffer with something
|
||||
const float bdaValues[2] = { 42.0f, 17.0f };
|
||||
const float bdaValues[2] = { 0.2f, 0.2f };
|
||||
cuMemcpyHtoD(va_BDA, &bdaValues[0], sizeof(float) * 2);
|
||||
}
|
||||
|
||||
|
|
|
@ -1083,8 +1083,14 @@ void VulkanBaseApp::createGraphicsPipeline() {
|
|||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||
pipelineLayoutInfo.setLayoutCount = 1; // Optional
|
||||
pipelineLayoutInfo.pSetLayouts = &m_descriptorSetLayout; // Optional
|
||||
pipelineLayoutInfo.pushConstantRangeCount = 0; // Optional
|
||||
pipelineLayoutInfo.pPushConstantRanges = nullptr; // Optional
|
||||
|
||||
VkPushConstantRange pcr{};
|
||||
pcr.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
pcr.offset = 0;
|
||||
pcr.size = sizeof(uint64_t);
|
||||
|
||||
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||
pipelineLayoutInfo.pPushConstantRanges = &pcr;
|
||||
|
||||
if (vkCreatePipelineLayout(m_device, &pipelineLayoutInfo, nullptr,
|
||||
&m_pipelineLayout) != VK_SUCCESS) {
|
||||
|
|
|
@ -71,6 +71,7 @@ class VulkanCudaPi : public VulkanBaseApp {
|
|||
using chrono_tp = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
||||
chrono_tp m_lastTime;
|
||||
size_t m_lastFrame;
|
||||
uint64_t m_bdaBufferBaseAddress;
|
||||
|
||||
public:
|
||||
VulkanCudaPi(size_t num_points)
|
||||
|
@ -88,7 +89,8 @@ class VulkanCudaPi : public VulkanBaseApp {
|
|||
m_vkSignalSemaphore(VK_NULL_HANDLE),
|
||||
m_cudaWaitSemaphore(),
|
||||
m_cudaSignalSemaphore(),
|
||||
m_lastFrame(0) {
|
||||
m_lastFrame(0),
|
||||
m_bdaBufferBaseAddress(0) {
|
||||
// Add our compiled vulkan shader files
|
||||
char* vertex_shader_path =
|
||||
sdkFindFilePath("vert.spv", execution_path.c_str());
|
||||
|
@ -141,6 +143,12 @@ class VulkanCudaPi : public VulkanBaseApp {
|
|||
vkCmdBindVertexBuffers(commandBuffer, 0,
|
||||
sizeof(vertexBuffers) / sizeof(vertexBuffers[0]),
|
||||
vertexBuffers, offsets);
|
||||
vkCmdPushConstants(commandBuffer,
|
||||
m_pipelineLayout,
|
||||
VK_SHADER_STAGE_VERTEX_BIT,
|
||||
0,
|
||||
sizeof(uint64_t),
|
||||
&m_bdaBufferBaseAddress);
|
||||
vkCmdDraw(commandBuffer, (uint32_t)(m_sim.getNumPoints()), 1, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -252,9 +260,9 @@ class VulkanCudaPi : public VulkanBaseApp {
|
|||
VkBufferDeviceAddressInfoKHR bda_info{VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_KHR,
|
||||
nullptr,
|
||||
m_bdaBuffer};
|
||||
auto bda = vkGetBufferDeviceAddressKHR(m_device, &bda_info);
|
||||
assert(bda);
|
||||
std::cout << "DEBUG: BDA = " << (void*)bda << std::endl;
|
||||
m_bdaBufferBaseAddress = vkGetBufferDeviceAddressKHR(m_device, &bda_info);
|
||||
assert(m_bdaBufferBaseAddress);
|
||||
std::cout << "DEBUG: BDA = " << (void*)m_bdaBufferBaseAddress << std::endl;
|
||||
|
||||
// Create the semaphore vulkan will signal when it's done with the vertex
|
||||
// buffer
|
||||
|
|
|
@ -56,22 +56,12 @@ layout(push_constant, std430) uniform Registers
|
|||
uint64_t base_address;
|
||||
} registers;
|
||||
|
||||
layout(std430, binding = 0) buffer CUDA_SSBO {
|
||||
float coords[2];
|
||||
} cuda_ssbo;
|
||||
|
||||
void main() {
|
||||
gl_PointSize = 1.0;
|
||||
gl_Position = vec4(xyPos.xy, 0.0f, 1.0f);
|
||||
|
||||
#if 0
|
||||
gl_Position.x += cuda_ssbo.coords[0];
|
||||
gl_Position.y += cuda_ssbo.coords[1];
|
||||
#endif
|
||||
#if 0
|
||||
gl_Position.x += BufferFloat(registers.base_address).f[0];
|
||||
gl_Position.y += BufferFloat(registers.base_address).f[1];
|
||||
#endif
|
||||
|
||||
float color_r = 1.0f + 0.5f * sin(ubo.frame / 100.0f);
|
||||
float color_g = 1.0f + 0.5f * sin((ubo.frame / 100.0f) + (2.0f*PI/3.0f));
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user