Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vulkan failed to render gltf with primitive.mode=line #8310

Open
tankeco opened this issue Dec 12, 2024 · 0 comments
Open

vulkan failed to render gltf with primitive.mode=line #8310

tankeco opened this issue Dec 12, 2024 · 0 comments
Assignees
Labels
vulkan Issues with the Vulkan backend

Comments

@tankeco
Copy link

tankeco commented Dec 12, 2024

Describe the bug
I have a GLB file that contains a mesh with a primitive.mode of 1 ({"name":"Object_54","primitives":[{"attributes":{"POSITION":266},"indices":267,"material":0,"mode":1}]}). When trying to render this GLB using Vulkan, it encounters errors. I've tried different versions of NVIDIA drivers and Mesa LLVMPIPE - while the error messages differ, the rendering still fails (though not 100% of the time, but very likely). When I remove this mesh from the scene, the rendering works successfully. I'm not sure if this is an issue with my implementation, with Filament, or with the Vulkan driver?

I also tried model in https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/PrimitiveModeNormalsTest , it also crashed

using filament 1.56.3

To Reproduce

Steps to reproduce the behavior:

  1. test glb: 004bef020bb34445b2b31e97552cd421.glb.zip
  2. compile code in Additional context
  3. run ./a.out 004bef020bb34445b2b31e97552cd421.glb 0 -> not remove Object_54, crash
  4. run ./a.out 004bef020bb34445b2b31e97552cd421.glb 1 -> remove Object_54, success

Expected behavior
program run always success

Screenshots
N/A

Logs
on L40s:

./a.out 004bef020bb34445b2b31e97552cd421.glb 0
remove_line: 0
FEngine (64 bits) created at 0x562399481160 (threading is enabled)
FEngine resolved backend: Vulkan
Vulkan device driver: NVIDIA 535.129.03
Selected physical device 'NVIDIA L40S' from 1 physical devices. (vendor 0x10de, device 0x26b9, driver 0x85e040c0, api 1.3)
Backend feature level: 3
FEngine feature level: 1
**Failed to wait for readPixels fence**
callback called
write_png_file: test3.png

on P100

$./a.out 004bef020bb34445b2b31e97552cd421.glb 0
remove_line: 0
FEngine (64 bits) created at 0x55d035f401a0 (threading is enabled)
FEngine resolved backend: Vulkan
Vulkan device driver: NVIDIA 525.105.17
Selected physical device 'Tesla P100-PCIE-16GB' from 3 physical devices. (vendor 0x10de, device 0x15f8, driver 0x835a4440, api 1.3)
Backend feature level: 3
FEngine feature level: 1
Segmentation fault (core dumped)

use llvmpipe:

$VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json ./a.out 004bef020bb34445b2b31e97552cd421.glb 0
remove_line: 0
FEngine (64 bits) created at 0x55c69e2391a0 (threading is enabled)
FEngine resolved backend: Vulkan
Vulkan device driver: llvmpipe Mesa 24.3.0 (LLVM 15.0.6)
Selected physical device 'llvmpipe (LLVM 15.0.6, 256 bits)' from 1 physical devices. (vendor 0x10005, device 0x0, driver 0x1, api 1.3)
Backend feature level: 3
FEngine feature level: 1
Segmentation fault (core dumped)

Desktop (please complete the following information):

  • OS: Linux (centos7)
  • GPU: P100, L40s
  • Backend: Vulkan

Smartphone (please complete the following information):
N/A

Additional context
my test code:

#include <filament/Engine.h>
#include <filament/SwapChain.h>
#include <filament/Renderer.h>
#include <filament/RenderTarget.h>
#include <filament/Scene.h>
#include <filament/View.h>
#include <filament/Viewport.h>
#include <filament/Camera.h>
#include <filament/ColorSpace.h>
#include <filament/ColorGrading.h>
#include <filament/Skybox.h>
#include <filament/Material.h>
#include <filament/MaterialInstance.h>
#include <filament/RenderableManager.h>
#include <filament/LightManager.h>
#include <filament/IndirectLight.h>
#include <filament/TransformManager.h>
#include <filament/Texture.h>
#include <utils/EntityManager.h>
#include <utils/NameComponentManager.h>
#include <utils/Entity.h>
#include <utils/compiler.h>
#include <utils/Path.h>
#include <backend/PixelBufferDescriptor.h>
#include <gltfio/AssetLoader.h>
#include <gltfio/FilamentAsset.h>
#include <gltfio/ResourceLoader.h>
#include <gltfio/TextureProvider.h>
#include <gltfio/math.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <math/mat3.h>
#include <math/norm.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <memory>

using namespace std;
using namespace filament;

void callback(void* buffer, size_t size, void* user) {
    std::cout << "callback called" << std::endl;

}

int main(int argc, char** argv) {
    if (argc < 3) {
        std::cout << "Usage: " << argv[0] << " <model_path> <remove_line>" << std::endl;
        return 1;
    }
    std::string model_path = argv[1];
    bool remove_line = false;
    if (std::string(argv[2]) == "true" || std::string(argv[2]) == "1" || std::string(argv[2]) == "True") {
        remove_line = true;
    }
    else {
        remove_line = false;
    }
    std::cout << "remove_line: " << remove_line << std::endl;

    Engine* engine = Engine::create(Engine::Backend::VULKAN);
    Renderer* renderer = engine->createRenderer();
    Scene* scene = engine->createScene();
    View* view = engine->createView();
    auto swap_chain = engine->createSwapChain(1024, 1024);
    view->setScene(scene);
    utils::EntityManager& em = engine->getEntityManager();
    utils::Entity cameraEntity = em.create();
    Camera* camera = engine->createCamera(cameraEntity);
    camera->setExposure(1.0f, 1.2f, 100.f);
    camera->lookAt(math::float3(0, 0, 1), math::float3(0, 0, 0));
    view->setCamera(camera);
    view->setViewport({0, 0, 1024, 1024});

    ifstream file(model_path);
    vector<uint8_t> file_buffer((istreambuf_iterator<char>(file)), istreambuf_iterator<char>());

    auto materialProvider = gltfio::createJitShaderProvider(engine);
    auto asset_loader = gltfio::AssetLoader::create(
        {engine, materialProvider, new utils::NameComponentManager(engine->getEntityManager())});
    gltfio::FilamentAsset* asset = asset_loader->createAsset(file_buffer.data(), file_buffer.size());

    auto resource_loader = gltfio::ResourceLoader({.engine = engine});
    resource_loader.addTextureProvider("image/jpeg", gltfio::createStbProvider(engine));
    resource_loader.addTextureProvider("image/png", gltfio::createStbProvider(engine));
    resource_loader.addTextureProvider("image/ktx2", gltfio::createKtx2Provider(engine));

    resource_loader.loadResources(asset);

    utils::Entity sun = em.get().create();

    filament::LightManager::Builder(filament::LightManager::Type::SUN)
               .color({1.0f, 1.0f, 1.0f})
               .intensity(30000.0f)
               .build(*engine, sun);
    scene->addEntity(sun);

    size_t size = 1024 * 1024 * 4;
    void* buffer = malloc(size);
    memset(buffer, 0, size);
    backend::PixelBufferDescriptor pd(buffer, size,
        backend::PixelDataFormat::RGBA, backend::PixelDataType::UBYTE,
        callback, nullptr);

    if (!remove_line) {
        scene->addEntities(asset->getEntities(), asset->getEntityCount());
    }
    else {
        for (size_t j = 0; j < asset->getEntityCount(); j++) {
            if (j == 16) {
                // app.scene->addEntity(asset->getEntities()[j]);
            }
            else {
                scene->addEntity(asset->getEntities()[j]);
            }
        }
    }

    renderer->beginFrame(swap_chain);
    renderer->render(view);
    renderer->readPixels(0, 0, 1024, 1024, std::move(pd));
    renderer->endFrame();
    engine->flushAndWait();
}
@poweifeng poweifeng self-assigned this Dec 12, 2024
@poweifeng poweifeng added the vulkan Issues with the Vulkan backend label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vulkan Issues with the Vulkan backend
Projects
None yet
Development

No branches or pull requests

2 participants