Skip to content

feat: add shader resource file for Qt6 build#574

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Feb 28, 2026
Merged

feat: add shader resource file for Qt6 build#574
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71
Copy link
Copy Markdown
Contributor

@wyu71 wyu71 commented Feb 27, 2026

  • Add dtkdeclarative_shaders_ng.qrc to reference shader files from src/shaders
  • Use alias to map shader paths for Qt6 compatibility
  • Remove Qt version checks in DOpenGLBlurEffectNode shader loading
  • Unify shader resource paths across Qt5 and Qt6

Log: add shader resource file for Qt6 build

Summary by Sourcery

Build:

  • Include dtkdeclarative_shaders_ng.qrc in the Qt6 CMake resources so shader files are packaged with the library.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Feb 27, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new Qt resource collection for shaders to the Qt6 build and wires it into the CMake resource setup so shader files can be loaded uniformly across Qt5/Qt6 without version checks.

Sequence diagram for unified shader loading without Qt version checks

sequenceDiagram
    participant DOpenGLBlurEffectNode
    participant QtResourceSystem
    participant ShaderFiles

    DOpenGLBlurEffectNode->>QtResourceSystem: request shader(:/shaders/blur.vert)
    QtResourceSystem->>ShaderFiles: resolve alias to src/shaders/blur.vert
    ShaderFiles-->>QtResourceSystem: shader source
    QtResourceSystem-->>DOpenGLBlurEffectNode: shader source
    DOpenGLBlurEffectNode->>DOpenGLBlurEffectNode: compile and link shader (no Qt version checks)
Loading

File-Level Changes

Change Details Files
Hook new shader resource collection into the Qt6 CMake build so shaders are packaged as resources.
  • Extend qt_add_resources call in qt6/src/CMakeLists.txt to include the new dtkdeclarative_shaders_ng.qrc file
  • Ensure the new resource collection is linked into the main library via target_sources
qt6/src/CMakeLists.txt
Introduce a Qt6 shader resource collection file to reference shader assets under a unified path.
  • Add dtkdeclarative_shaders_ng.qrc to define resource aliases for shaders (expected to point at src/shaders for Qt6 builds)
  • Prepare ground for removing Qt version-specific shader path handling by centralizing paths in the resource file
qt6/src/dtkdeclarative_shaders_ng.qrc

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Feb 27, 2026

TAG Bot

New tag: 6.7.34
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #576

- Add dtkdeclarative_shaders_ng.qrc to reference shader files from src/shaders
- Use alias to map shader paths for Qt6 compatibility
- Remove Qt version checks in DOpenGLBlurEffectNode shader loading
- Unify shader resource paths across Qt5 and Qt6

Log: add shader resource file for Qt6 build
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

deepin pr auto review

这份代码变更主要是通过Qt资源系统(Qt Resource System, QRC)引入了一组新的着色器文件。以下是对该变更的审查意见,涵盖语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • CMakeLists.txt:

    • 语法正确。qt_add_resources 是 Qt6 中标准的添加资源文件的方法,将新的 dtkdeclarative_shaders_ng.qrc 文件追加到 RESOURCES 变量中是符合逻辑的。
    • 路径引用正确,因为 dtkdeclarative_shaders_ng.qrcCMakeLists.txt 位于同一目录(qt6/src/),所以直接使用文件名是可行的。
  • dtkdeclarative_shaders_ng.qrc:

    • XML 格式正确,符合 Qt 资源文件的标准格式。
    • 路径逻辑问题:QRC 文件中使用了相对路径 ../../src/shaders/。这意味着着色器源文件位于 qt6/src/ 的上级目录的 src 目录中(即项目根目录下的 src/shaders/)。这种跨目录引用虽然合法,但增加了项目的脆弱性。如果项目结构调整(例如移动了 qt6 文件夹),构建将会失败。

2. 代码质量

  • 资源管理:

    • 将着色器文件作为资源嵌入是 Qt 应用的常见做法,有利于分发和部署,确保着色器文件随二进制文件一起发布。
    • 命名规范:文件名 dtkdeclarative_shaders_ng.qrc 中的 ng (next generation?) 暗示这可能是一组新的或替换旧的着色器。建议确认是否存在旧的着色器资源文件,以避免资源冗余或混淆。
  • 路径清晰度:

    • .qrc 文件中使用 ../../ 这种相对路径会降低代码的可读性和可维护性。维护者需要时刻清楚当前文件相对于源码的位置。

3. 代码性能

  • 构建性能:
    • 增加资源文件会增加编译时间和最终二进制文件的大小。由于着色器文件通常较小,对构建时间影响不大。
    • 运行时性能:资源被编译进二进制文件中,运行时从内存读取,比从磁盘文件读取速度快,且没有 I/O 阻塞,这对渲染性能是有利的。

4. 代码安全

  • 路径遍历风险:

    • 虽然在构建阶段使用相对路径通常不会直接导致安全漏洞,但在复杂的构建系统中,不一致的路径解析有时会导致意外包含文件。建议确保 ../../src/shaders/ 目录下的文件确实是受控的源代码,而非临时生成的或用户可写的文件。
  • 资源别名:

    • 使用了 alias 属性(如 alias="shaders/dualkawasedown.frag")是很好的做法。它将物理文件路径与逻辑路径分离,隐藏了实际的源码目录结构(../../src/),防止外部通过逻辑路径推测服务器或文件系统的物理结构。

改进建议

  1. 统一源码位置或使用 CMake 变量

    • 建议避免在 .qrc 文件中使用 ../../ 这种跳出当前目录的相对路径。
    • 方案 A:如果可能,将着色器源文件移动到 qt6/src/shaders/ 目录下,这样 QRC 中的路径可以直接写 shaders/xxx.frag,更加直观。
    • 方案 B:在 CMakeLists.txt 中定义一个指向着色器根目录的变量(例如 DTK_SHADER_SOURCE_DIR),然后在 QRC 文件中虽然不能直接使用 CMake 变量,但可以通过 configure_file 在构建时生成 QRC 文件,或者调整项目结构以减少路径跳转。
  2. 资源前缀一致性

    • 确认 /dtk/declarative 前缀是否与项目中其他资源的前缀保持一致,以保持命名空间的整洁。
  3. 文件完整性检查

    • 在 CMake 中添加检查逻辑,确保引用的着色器文件(../../src/shaders/...)在构建前确实存在,防止因文件缺失导致的构建中断或运行时错误。

修改后的 CMakeLists 片段建议(增加存在性检查):

# 定义着色器源文件目录,假设相对于 qt6/src
set(SHADER_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../src/shaders")

# 检查目录是否存在
if(NOT EXISTS "${SHADER_SOURCE_DIR}")
    message(FATAL_ERROR "Shader source directory not found: ${SHADER_SOURCE_DIR}")
endif()

# 检查具体的文件是否存在(可选)
set(REQUIRED_SHADERS
    dualkawasedown.frag dualkawasedown.vert
    dualkawaseup.frag dualkawaseup.vert
    noise.vert noise.frag
)
foreach(shader ${REQUIRED_SHADERS})
    if(NOT EXISTS "${SHADER_SOURCE_DIR}/${shader}")
        message(WARNING "Required shader file missing: ${shader}")
    endif()
endforeach()

file(GLOB QML_RCS dtkdeclarative_qml.qrc dtkdeclarative_overridable_qml.qrc)
qt_add_resources(RESOURCES
    ${QML_RCS}
    ${ASSETS_RCS}
    dtkdeclarative_shaders_ng.qrc
)
target_sources(${LIB_NAME} PRIVATE ${RESOURCES})

总结:该变更在语法和功能上是正确的,能够有效地将着色器资源集成到构建系统中。主要的改进点在于优化文件路径的依赖关系,增加构建时的健壮性检查,以及确保项目结构的清晰度。

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wyu71

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wyu71
Copy link
Copy Markdown
Contributor Author

wyu71 commented Feb 28, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Feb 28, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 37f492e into linuxdeepin:master Feb 28, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants