MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / Buffer

Method Buffer

Source/Falcor/Core/API/Buffer.cpp:106–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106Buffer::Buffer(
107 ref<Device> pDevice,
108 size_t size,
109 size_t structSize,
110 ResourceFormat format,
111 ResourceBindFlags bindFlags,
112 MemoryType memoryType,
113 const void* pInitData
114)
115 : Resource(pDevice, Type::Buffer, bindFlags, size), mMemoryType(memoryType)
116{
117 FALCOR_CHECK(size > 0, "Can't create GPU buffer of size zero");
118
119 // Check that buffer size is within 4GB limit. Larger buffers are currently not well supported in D3D12.
120 // TODO: Revisit this check in the future.
121 FALCOR_CHECK(size <= (1ull << 32), "Creating GPU buffer of size {} bytes. Buffers above 4GB are not currently well supported.", size);
122
123 if (mMemoryType != MemoryType::DeviceLocal && is_set(mBindFlags, ResourceBindFlags::Shared))
124 {
125 FALCOR_THROW("Can't create shared resource with CPU access other than 'None'.");
126 }
127
128 mSize = align_to(mpDevice->getBufferDataAlignment(bindFlags), mSize);
129 mStructSize = structSize;
130 mFormat = format;
131
132 if (mMemoryType == MemoryType::DeviceLocal)
133 {
134 mState.global = Resource::State::Common;
135 if (is_set(mBindFlags, ResourceBindFlags::AccelerationStructure))
136 mState.global = Resource::State::AccelerationStructure;
137 }
138 else if (mMemoryType == MemoryType::Upload)
139 {
140 mState.global = Resource::State::GenericRead;
141 }
142 else if (mMemoryType == MemoryType::ReadBack)
143 {
144 mState.global = Resource::State::CopyDest;
145 }
146
147 mGfxBufferResource = createBufferResource(mpDevice, mState.global, mSize, mStructSize, mFormat, mBindFlags, mMemoryType);
148
149 if (pInitData)
150 setBlob(pInitData, 0, size);
151
152 mElementCount = uint32_t(size);
153}
154
155Buffer::Buffer(ref<Device> pDevice, size_t size, ResourceBindFlags bindFlags, MemoryType memoryType, const void* pInitData)
156 : Buffer(pDevice, size, 0, ResourceFormat::Unknown, bindFlags, memoryType, pInitData)

Callers

nothing calls this directly

Calls 7

align_toFunction · 0.85
createBufferResourceFunction · 0.85
getFormatBytesPerBlockFunction · 0.85
setBlobFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected