On Mon, 16 Nov 2026 12:29:13 GMT, Lukasz Kostyra <[email protected]> wrote:
>> ## Description >> >> This PR is for review and integration of Direct3D 12 Rendering Pipeline into >> JavaFX mainline. We released three Early Access (EA) versions of this >> implementation while keeping the development ongoing on [JavaFX >> Sandbox](https://github.com/openjdk/jfx-sandbox/tree/direct3d12) and reached >> a stage where it is ready to be integrated into mainline. Any further work >> and potential fixes will be done on mainline. >> >> At the time of writing, this PR is identical to the [JavaFX Sandbox D3D12 >> branch](https://github.com/openjdk/jfx-sandbox/tree/direct3d12) with only >> one difference - the Sandbox defaults to D3D12 backend. This PR, however, >> does *NOT* change the default rendering pipeline on Windows. D3D9 remains >> the default rendering pipeline and D3D12 is optional - it can be selected by >> providing `-Dprism.order=d3d12`. To verify which pipeline is actually in use >> `-Dprism.verbose=true` is recommended. >> >> ## Details >> >> Below are general changes introduced by the backend: >> >> ### JSL changes >> >> - Introduced `HLSL6Backend` class which translates JSL shader code into >> HLSL6 code. D3D12 introduced HLSL Shader Level 6 support and won't support >> existing HLSL shaders used with D3D9, as those are compiled for unsupported >> Shader Level 3. >> - D3D12-specific shaders are kept in >> `modules/javafx.graphics/src/main/native-prism-d3d12/hlsl6` >> - Shader compilation is done with DXC instead of FXC (FXC does not support >> SL6). DXC is bundled in Windows SDK which JavaFX already integrates with. >> - Backend also generates C++ headers with Shader resource binding >> information, used by the native-side >> >> ### Build changes >> >> - Added new build tasks for generation and compilation of HLSL6 shaders for >> D3D12 >> - Added tasks to compile D3D12 native backend code >> >> ### Prism changes >> >> - Added D3D12-specific Java classes (package `com.sun.prism.d3d12`) and a >> Java-to-JNI layer (package `com.sun.prism.d3d12.ni`) >> - Java implementation is mostly similar to D3D9 implementation, with only >> some minor changes needed to accommodate slightly different presentation >> behavior of the new runtime >> - JNI interface is relatively high level to reduce the amount of JNI calls >> for performance >> - Added a native Prism backend implementation using D3D12 runtime (stored in >> `modules/javafx.graphics/src/main/native-prism-d3d12`) >> - Written in C++ 20 >> - Uses only interfaces available via Windows API with no third-party >> libraries - WinAPI, Windows COM interface system and "bare... > > Lukasz Kostyra has updated the pull request incrementally with one additional > commit since the last revision: > > Review fixes from @kevinrushforth A few JNI and static analysis findings. modules/javafx.graphics/src/main/native-prism-d3d12/D3D12NativeDevice.cpp line 991: > 989: D3D12::Internal::JNIBuffer<jfloatArray> vertsArray(env, nullptr, > vertices); > 990: D3D12::Internal::JNIBuffer<jbyteArray> colorsArray(env, nullptr, > colors); > 991: if (!vertsArray || !colorsArray) return; To avoid possible pending JNI exception: Suggestion: D3D12::Internal::JNIBuffer<jfloatArray> vertsArray(env, nullptr, vertices); if (!vertsArray) return; D3D12::Internal::JNIBuffer<jbyteArray> colorsArray(env, nullptr, colors); if (!colorsArray) return; modules/javafx.graphics/src/main/native-prism-d3d12/D3D12NativeDevice.cpp line 1084: > 1082: if (!shader) return false; > 1083: > 1084: D3D12::Internal::JNIString nameJStr(env, name); Check for NULL and return. modules/javafx.graphics/src/main/native-prism-d3d12/D3D12NativeDevice.cpp line 1111: > 1109: if (!shader) return false; > 1110: > 1111: D3D12::Internal::JNIString nameJStr(env, name); Check for NULL and return. modules/javafx.graphics/src/main/native-prism-d3d12/D3D12NativeMesh.cpp line 122: > 120: D3D12::Internal::JNIBuffer<jfloatArray> vertsBuffer(env, nullptr, > verts); > 121: D3D12::Internal::JNIBuffer<jintArray> indicesBuffer(env, nullptr, > indices); > 122: if (!vertsBuffer || !indicesBuffer) return false; Suggestion: D3D12::Internal::JNIBuffer<jfloatArray> vertsBuffer(env, nullptr, verts); if (!vertsBuffer) return false; D3D12::Internal::JNIBuffer<jintArray> indicesBuffer(env, nullptr, indices); if (!indicesBuffer) return false; modules/javafx.graphics/src/main/native-prism-d3d12/D3D12NativeMesh.cpp line 145: > 143: D3D12::Internal::JNIBuffer<jfloatArray> vertsBuffer(env, nullptr, > verts); > 144: D3D12::Internal::JNIBuffer<jshortArray> indicesBuffer(env, nullptr, > indices); > 145: if (!vertsBuffer || !indicesBuffer) return false; Suggestion: D3D12::Internal::JNIBuffer<jfloatArray> vertsBuffer(env, nullptr, verts); if (!vertsBuffer) return false; D3D12::Internal::JNIBuffer<jshortArray> indicesBuffer(env, nullptr, indices); if (!indicesBuffer) return false; modules/javafx.graphics/src/main/native-prism-d3d12/internal/D3D12Config.cpp line 56: > 54: std::string Config::GetPropertyInternal(const char* propertyName) > 55: { > 56: jstring propStr = mJNIEnv->NewStringUTF(propertyName); Check this call for pending JNI exceptions or NULL before calling `CallStaticObjectMethod`. For example: if (mJNIEnv->ExceptionCheck() || propStr == NULL) { mJNIEnv->ExceptionClear(); return std::string(); } modules/javafx.graphics/src/main/native-prism-d3d12/internal/D3D12Config.cpp line 67: > 65: > 66: jboolean isCopy = false; > 67: const char* propValue = mJNIEnv->GetStringUTFChars(propValueStr, > &isCopy); This should also be checked for pending JNI exceptions or NULL before using it to create a string. modules/javafx.graphics/src/main/native-prism-d3d12/internal/D3D12Logger.cpp line 124: > 122: if (Config::IsColorLogsEnabled()) > 123: { > 124: GetConsoleScreenBufferInfo(stdOutHandle, &consoleInfo); `GetConsoleScreenBufferInfo` doesn't guarantee to initialize `consoleInfo`. If there is an error, it might be uninitialized in which case later on in this function, it will read an uninitialized `consoleInfo.wAttributes`. modules/javafx.graphics/src/main/native-prism-d3d12/internal/JNIBuffer.hpp line 87: > 85: if (mData == nullptr) return; > 86: > 87: mElementCount = > static_cast<size_t>(mJNIEnv->GetArrayLength(array)); Other JNI calls such as `GetArrayLength` should not be called inside a critical region (that is, between `GetPrimitiveArrayCritical` and `ReleasePrimitiveArrayCritical`). This might be tricky to solve if two such buffers are created and used at the same time, since the second buffer will query the length while the first is pinned. ------------- PR Review: https://git.openjdk.org/jfx/pull/2346#pullrequestreview-5967416032 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4623023242 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4622991703 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4623008980 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4623043404 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4623051593 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4622743479 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4622753812 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4623107657 PR Review Comment: https://git.openjdk.org/jfx/pull/2346#discussion_r4622857667
