Skip to content

Commit 98c701a

Browse files
Fixed Example 5 even under Vulkan!
(still gives validation error about fences) Plus a small vulkan fix.
1 parent 300078b commit 98c701a

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

examples_tests/05.NablaTutorialExample/main.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class NablaTutorialExampleApp : public ApplicationBase
167167
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
168168
const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
169169

170-
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "NablaTutorialExample", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
170+
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_VULKAN, "NablaTutorialExample", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
171171
window = std::move(initOutput.window);
172172
windowCb = std::move(initOutput.windowCb);
173173
apiConnection = std::move(initOutput.apiConnection);
@@ -202,13 +202,19 @@ class NablaTutorialExampleApp : public ApplicationBase
202202
Loading an asset bundle. You can specify some flags
203203
and parameters to have an impact on extraordinary
204204
tasks while loading for example.
205-
*/
205+
*/
206206

207207
asset::IAssetLoader::SAssetLoadParams loadingParams;
208208
auto images_bundle = assetManager->getAsset("../../media/color_space_test/R8G8B8A8_1.png", loadingParams);
209209
assert(!images_bundle.getContents().empty());
210210
auto image = images_bundle.getContents().begin()[0];
211+
212+
/*
213+
By default an image that comes out of an image loader will only have the TRANSFER_DST usage flag.
214+
We need to add more usages, as only we know what we'll do with the image farther along in the pipeline.
215+
*/
211216
auto image_raw = static_cast<asset::ICPUImage*>(image.get());
217+
image_raw->addImageUsageFlags(asset::IImage::EUF_SAMPLED_BIT);
212218

213219
/*
214220
Specifing gpu image view parameters to create a gpu
@@ -220,7 +226,16 @@ class NablaTutorialExampleApp : public ApplicationBase
220226
cpu2gpuParams.waitForCreationToComplete();
221227
auto& gpuParams = gpuImage->getCreationParameters();
222228

223-
IImageView<IGPUImage>::SCreationParams gpuImageViewParams = { static_cast<IGPUImageView::E_CREATE_FLAGS>(0), gpuImage, IImageView<IGPUImage>::ET_2D, gpuParams.format, {}, {static_cast<IImage::E_ASPECT_FLAGS>(0u), 0, gpuParams.mipLevels, 0, gpuParams.arrayLayers} };
229+
IImageView<IGPUImage>::SCreationParams gpuImageViewParams = {
230+
IGPUImageView::ECF_NONE,
231+
gpuImage,
232+
IImageView<IGPUImage>::ET_2D,
233+
gpuParams.format,
234+
{},
235+
{
236+
IImage::EAF_COLOR_BIT, 0, gpuParams.mipLevels, 0, gpuParams.arrayLayers
237+
}
238+
};
224239
auto gpuImageView = logicalDevice->createGPUImageView(std::move(gpuImageViewParams));
225240

226241
/*
@@ -279,15 +294,18 @@ class NablaTutorialExampleApp : public ApplicationBase
279294
We know ahead of time that `SBasicViewParameters` struct is the expected structure of the only UBO block in the descriptor set nr. 1 of the shader.
280295
*/
281296

282-
IGPUBuffer::SCreationParams creationParams;
297+
IGPUBuffer::SCreationParams creationParams = {};
283298
creationParams.canUpdateSubRange = true;
284299
creationParams.usage = asset::IBuffer::EUF_UNIFORM_BUFFER_BIT;
285-
creationParams.sharingMode = asset::E_SHARING_MODE::ESM_CONCURRENT;
286-
creationParams.queueFamilyIndexCount = 0u;
287-
creationParams.queueFamilyIndices = nullptr;
288300
IDriverMemoryBacked::SDriverMemoryRequirements memReq;
289301
memReq.vulkanReqs.size = sizeof(SBasicViewParameters);
290-
gpuubo = logicalDevice->createGPUBufferOnDedMem(creationParams, memReq);
302+
memReq.vulkanReqs.alignment = physicalDevice->getLimits().UBOAlignment;
303+
memReq.vulkanReqs.memoryTypeBits = 0xffffffffu;
304+
memReq.memoryHeapLocation = IDriverMemoryAllocation::ESMT_DEVICE_LOCAL;
305+
memReq.mappingCapability = IDriverMemoryAllocation::EMAF_NONE;
306+
memReq.prefersDedicatedAllocation = true;
307+
memReq.requiresDedicatedAllocation = true;
308+
gpuubo = logicalDevice->createGPUBufferOnDedMem(creationParams,memReq);
291309

292310
/*
293311
Creating descriptor sets - texture (sampler) and basic view parameters (UBO).
@@ -380,6 +398,7 @@ class NablaTutorialExampleApp : public ApplicationBase
380398
if (cpuindexbuffer)
381399
cpubuffers.push_back(cpuindexbuffer);
382400

401+
cpu2gpuParams.beginCommandBuffers();
383402
auto gpubuffers = cpu2gpu.getGPUObjectsFromAssets(cpubuffers.data(), cpubuffers.data() + cpubuffers.size(), cpu2gpuParams);
384403
cpu2gpuParams.waitForCreationToComplete();
385404

include/nbl/asset/IImageView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class IImageView : public IDescriptor
2222
// no flags for now, yet
2323
enum E_CREATE_FLAGS
2424
{
25+
ECF_NONE = 0
2526
};
2627
enum E_TYPE
2728
{

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ class CVulkanLogicalDevice final : public ILogicalDevice
12761276
vkDescSetLayoutBinding.stageFlags = static_cast<VkShaderStageFlags>(binding->stageFlags);
12771277
vkDescSetLayoutBinding.pImmutableSamplers = nullptr;
12781278

1279-
if (binding->samplers && binding->count > 0u)
1279+
if (binding->type==asset::ESRT_SAMPLED_IMAGE && binding->samplers && binding->count > 0u)
12801280
{
12811281
// If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount is not 0 and pImmutableSamplers is not NULL:
12821282
// pImmutableSamplers must be a valid pointer to an array of descriptorCount valid VkSampler handles.

0 commit comments

Comments
 (0)