Esempio n. 1
0
        public void SetupBuild(int deviceIndex, uint triangleCnt, GpuBuffer vertices, ulong vertices_off, GpuBuffer indices, ulong indices_off, bool shortIndices)
        {
            devID             = deviceIndex;
            TrianglePrimitive = new RRTriangleMeshPrimitive()
            {
                index_type       = shortIndices ? RRIndexType.RrIndexTypeUint16 : RRIndexType.RrIndexTypeUint32,
                triangle_count   = triangleCnt,
                triangle_indices = indices.GetRayDevicePointer(indices_off),
                vertex_count     = VertexCount,
                vertex_stride    = VertexSize,
                vertices         = vertices.GetRayDevicePointer(vertices_off)
            };
            TrianglePrimitive_ptr = TrianglePrimitive.Pointer();

            GeometryBuildInput = new RRGeometryBuildInput()
            {
                primitive_type  = RRPrimitiveType.RrPrimitiveTypeTriangleMesh,
                primitive_count = 1,
                primitives      = TrianglePrimitive_ptr,
            };
            GeometryBuildInput_ptr = GeometryBuildInput.Pointer();

            RRBuildOptions opts = new RRBuildOptions()
            {
                build_flags           = 0,
                backend_specific_info = IntPtr.Zero,
            };
            var opts_ptr = opts.Pointer();

            //Allocate the necessary memory
            ManagedPtr <RRMemoryRequirements> geomMemReqs = new ManagedPtr <RRMemoryRequirements>();

            if (rrGetGeometryBuildMemoryRequirements(GraphicsDevice.DeviceInformation[deviceIndex].RaysContext, GeometryBuildInput_ptr, opts_ptr, geomMemReqs) != RRError.RrSuccess)
            {
                throw new Exception("Failed to determine geometry memory requirements.");
            }

            ScratchBuffer = new GpuBuffer(Name + "_scratch")
            {
                MemoryUsage = MemoryUsage.GpuOnly,
                Size        = geomMemReqs.Value.temporary_build_buffer_size,
                Usage       = BufferUsage.Storage | BufferUsage.TransferDst
            };
            ScratchBuffer.Build(deviceIndex);
            scratchBufferPtr = ScratchBuffer.GetRayDevicePointer(0);

            BuiltGeometryBuffer = new GpuBuffer(Name + "_geom")
            {
                MemoryUsage = MemoryUsage.GpuOnly,
                Size        = geomMemReqs.Value.result_buffer_size,
                Usage       = BufferUsage.Storage | BufferUsage.TransferDst
            };
            BuiltGeometryBuffer.Build(deviceIndex);
            geomBufferPtr = BuiltGeometryBuffer.GetRayDevicePointer(0);
        }
Esempio n. 2
0
        public void BuildGeometry(RayGeometry geom)
        {
            if (locked)
            {
                if (!IsRadRayStream)
                {
                    throw new Exception("Not a raytracing enabled command buffer.");
                }

                var geom_build_input = geom.GeometryBuildInput_ptr;
                var build_options    = new RRBuildOptions()
                {
                    build_flags = 0,
                };
                var build_options_ptr = build_options.Pointer();

                rrCmdBuildGeometry(GraphicsDevice.DeviceInformation[devID].RaysContext, RRBuildOperation.RrBuildOperationBuild, geom_build_input, build_options_ptr, geom.scratchBufferPtr, geom.geomBufferPtr, radRayStream);
                IsEmpty = false;
            }
            else
            {
                throw new Exception("Command buffer not built.");
            }
        }