Skip to content

Commit

Permalink
Merge branch 'next' into dev-xir
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGengYF committed Dec 17, 2024
2 parents e8afe30 + 9542f6b commit 2ef8938
Show file tree
Hide file tree
Showing 35 changed files with 531 additions and 230 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-xmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ jobs:
fi
brew install molten-vk ninja cmake xmake
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
sudo xcode-select -switch /Applications/Xcode_16.1.app
echo "Check the relevant software versions"
brew --version
xcodebuild -version
clang++ --version
echo "Check End"
- name: "Configure and Build"
run: |
xmake lua setup.lua
Expand Down
9 changes: 9 additions & 0 deletions include/luisa/backends/ext/dx_hdr_ext.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <luisa/backends/ext/dx_hdr_ext_interface.h>
#include <luisa/runtime/swapchain.h>
#include <luisa/runtime/stream.h>
namespace luisa::compute {
Swapchain DXHDRExt::create_swapchain(const Stream &stream, const DXSwapchainOption &option) noexcept {
return Swapchain{stream.device(), create_swapchain(option, stream.handle())};
}
}// namespace luisa::compute
87 changes: 87 additions & 0 deletions include/luisa/backends/ext/dx_hdr_ext_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once
#include <luisa/runtime/rhi/device_interface.h>

namespace luisa::compute {
class Swapchain;
class Stream;
class DXHDRExt : public DeviceExtension {
public:
enum class DisplayCurve {
sRGB = 0,// The display expects an sRGB signal.
ST2084, // The display expects an HDR10 signal.
None // The display expects a linear signal.
};
enum class SwapChainBitDepth {
_8 = 0,
_10,
_16,
};
struct DisplayChromaticities {
float RedX{0.f};
float RedY{0.f};
float GreenX{0.f};
float GreenY{0.f};
float BlueX{0.f};
float BlueY{0.f};
float WhiteX{0.f};
float WhiteY{0.f};
};
struct DXSwapchainOption {
uint64_t window;
uint2 size;
PixelStorage storage = PixelStorage::HALF4;
bool wants_vsync = true;
uint back_buffer_count = 2;
};

enum class ColorSpace : uint {
RGB_FULL_G22_NONE_P709 = 0,
RGB_FULL_G10_NONE_P709 = 1,
RGB_STUDIO_G22_NONE_P709 = 2,
RGB_STUDIO_G22_NONE_P2020 = 3,
RESERVED = 4,
YCBCR_FULL_G22_NONE_P709_X601 = 5,
YCBCR_STUDIO_G22_LEFT_P601 = 6,
YCBCR_FULL_G22_LEFT_P601 = 7,
YCBCR_STUDIO_G22_LEFT_P709 = 8,
YCBCR_FULL_G22_LEFT_P709 = 9,
YCBCR_STUDIO_G22_LEFT_P2020 = 10,
YCBCR_FULL_G22_LEFT_P2020 = 11,
RGB_FULL_G2084_NONE_P2020 = 12,
YCBCR_STUDIO_G2084_LEFT_P2020 = 13,
RGB_STUDIO_G2084_NONE_P2020 = 14,
YCBCR_STUDIO_G22_TOPLEFT_P2020 = 15,
YCBCR_STUDIO_G2084_TOPLEFT_P2020 = 16,
RGB_FULL_G22_NONE_P2020 = 17,
YCBCR_STUDIO_GHLG_TOPLEFT_P2020 = 18,
YCBCR_FULL_GHLG_TOPLEFT_P2020 = 19,
RGB_STUDIO_G24_NONE_P709 = 20,
RGB_STUDIO_G24_NONE_P2020 = 21,
YCBCR_STUDIO_G24_LEFT_P709 = 22,
YCBCR_STUDIO_G24_LEFT_P2020 = 23,
YCBCR_STUDIO_G24_TOPLEFT_P2020 = 24,
CUSTOM = 0xFFFFFFFF
};

struct Meta {
ColorSpace color_space;
DisplayChromaticities chromaticities;
};

[[nodiscard]] virtual SwapchainCreationInfo create_swapchain(
const DXSwapchainOption &option,
uint64_t stream_handle) noexcept = 0;
virtual Meta set_hdr_meta_data(
uint64_t swapchain_handle,
float max_output_nits = 1000.0f,
float min_output_nits = 0.001f,
float max_cll = 2000.0f,
float max_fall = 500.0f,
const DisplayChromaticities *custom_chroma = nullptr) noexcept = 0;
static constexpr luisa::string_view name = "DXHDRExt";
[[nodiscard]] Swapchain create_swapchain(const Stream &stream, const DXSwapchainOption &option) noexcept;

protected:
~DXHDRExt() = default;
};
}// namespace luisa::compute
53 changes: 38 additions & 15 deletions include/luisa/core/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ template<typename T, size_t N>
static constexpr size_t vector_alignment_v = vector_alignment<T, N>::value;

/// Vector storage only allows size of 2, 3, 4
template<typename T, size_t N>
template<typename T, std::size_t N>
struct VectorStorage {
static_assert(always_false_v<T>, "Invalid vector storage");
};

/// Vector storage of size 2
template<typename T>
struct alignas(vector_alignment_v<T, 2>) VectorStorage<T, 2> {
T x, y;
T x {};
T y {};
explicit constexpr VectorStorage(T s = {}) noexcept : x{s}, y{s} {}
constexpr VectorStorage(T x, T y) noexcept : x{x}, y{y} {}
#include <luisa/core/swizzle_2.inl.h>
Expand All @@ -37,7 +38,9 @@ struct alignas(vector_alignment_v<T, 2>) VectorStorage<T, 2> {
/// Vector storage of size 3
template<typename T>
struct alignas(vector_alignment_v<T, 3>) VectorStorage<T, 3> {
T x, y, z;
T x {};
T y {};
T z {};
explicit constexpr VectorStorage(T s = {}) noexcept : x{s}, y{s}, z{s} {}
constexpr VectorStorage(T x, T y, T z) noexcept : x{x}, y{y}, z{z} {}
#include <luisa/core/swizzle_3.inl.h>
Expand All @@ -46,7 +49,10 @@ struct alignas(vector_alignment_v<T, 3>) VectorStorage<T, 3> {
/// Vector storage of size 4
template<typename T>
struct alignas(vector_alignment_v<T, 4>) VectorStorage<T, 4> {
T x, y, z, w;
T x {};
T y {};
T z {};
T w {};
explicit constexpr VectorStorage(T s = {}) noexcept : x{s}, y{s}, z{s}, w{s} {}
constexpr VectorStorage(T x, T y, T z, T w) noexcept : x{x}, y{y}, z{z}, w{w} {}
#include <luisa/core/swizzle_4.inl.h>
Expand All @@ -63,18 +69,37 @@ struct alignas(vector_alignment_v<T, 4>) VectorStorage<T, 4> {
* @tparam T bool/float/int/uint
* @tparam N 2/3/4
*/
template<typename T, size_t N>
template<typename T, std::size_t N>
struct Vector : public detail::VectorStorage<T, N> {
static constexpr auto dimension = N;
static Vector<T, N> zero() noexcept { return Vector<T, N>(static_cast<T>(0)); }
static Vector<T, N> one() noexcept { return Vector<T, N>(static_cast<T>(1)); }
using value_type = T;
using Storage = detail::VectorStorage<T, N>;
static_assert(is_scalar_v<T>, "Invalid vector type");
using size_type = std::size_t;
using reference = value_type &;
using const_reference = const value_type &;
using Storage = detail::VectorStorage<value_type, N>;
using Storage::VectorStorage; // introduce base class constructor function

static_assert(is_scalar_v<value_type>, "Invalid vector type");
static_assert(N == 2 || N == 3 || N == 4, "Invalid vector dimension");
using Storage::VectorStorage;
[[nodiscard]] constexpr T &operator[](size_t index) noexcept { return (&(this->x))[index]; }
[[nodiscard]] constexpr const T &operator[](size_t index) const noexcept { return (&(this->x))[index]; }

static constexpr size_type dimension { N };

static Vector<value_type, N> zero() noexcept {
return Vector<value_type, N>(static_cast<value_type>(0));
}

static Vector<value_type, N> one() noexcept {
return Vector<value_type, N>(static_cast<value_type>(1));
}

[[nodiscard]]
constexpr reference operator[](size_type index) noexcept {
return (&(this->x))[index];
}

[[nodiscard]]
constexpr const_reference operator[](size_type index) const noexcept {
return (&(this->x))[index];
}
};

template<typename T, size_t N>
Expand Down Expand Up @@ -571,8 +596,6 @@ LUISA_MAKE_TYPE_N(bool)
LUISA_MAKE_TYPE_N(float)
LUISA_MAKE_TYPE_N(int)
LUISA_MAKE_TYPE_N(uint)
LUISA_MAKE_TYPE_N(byte)
LUISA_MAKE_TYPE_N(ubyte)
LUISA_MAKE_TYPE_N(short)
LUISA_MAKE_TYPE_N(ushort)
LUISA_MAKE_TYPE_N(slong)
Expand Down
26 changes: 14 additions & 12 deletions include/luisa/core/dynamic_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace luisa {

/**
* @brief Dynamic module loader
*
*
*/
class LC_CORE_API DynamicModule : concepts::Noncopyable {

Expand All @@ -29,7 +29,7 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {
void dispose() noexcept;
/**
* @brief Return function pointer of given name
*
*
* @tparam F function type
* @param name name of function
* @return pointer to function
Expand All @@ -42,17 +42,17 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {

/**
* @brief Return address of given name
*
*
* @param name
* @return void*
* @return void*
*/
[[nodiscard]] void *address(std::string_view name) const noexcept {
return dynamic_module_find_symbol(_handle, name);
}

/**
* @brief Invoke function
*
*
* @tparam F function type
* @tparam Args function args
* @param name name of function
Expand All @@ -67,12 +67,12 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {

/**
* @brief Apply function to each element
*
*
* @tparam F function type
* @tparam Tuple tuple type
* @param name name of function
* @param t tuple to be applied
* @return decltype(auto)
* @return decltype(auto)
*/
template<concepts::function F, typename Tuple>
decltype(auto) apply(std::string_view name, Tuple &&t) const noexcept {
Expand All @@ -81,15 +81,15 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {

/**
* @brief Add dynamic module search path
*
* @param path
*
* @param path
*/
static void add_search_path(const std::filesystem::path &path) noexcept;

/**
* @brief Remove dynamic module search path
*
* @param path
*
* @param path
*/
static void remove_search_path(const std::filesystem::path &path) noexcept;

Expand All @@ -108,7 +108,9 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {
* @return The module if successfully loaded, otherwise a nullopt
*/
[[nodiscard]] static DynamicModule load(
const std::filesystem::path &folder, std::string_view name) noexcept;
const luisa::filesystem::path &folder,
std::string_view name
) noexcept;
};

}// namespace luisa
2 changes: 1 addition & 1 deletion include/luisa/runtime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LC_RUNTIME_API Context {
luisa::shared_ptr<detail::ContextImpl> _impl;

public:
explicit Context(luisa::shared_ptr<luisa::compute::detail::ContextImpl> impl) noexcept;
explicit Context(luisa::shared_ptr<detail::ContextImpl> impl) noexcept;
// program_path can be first arg from main entry
explicit Context(luisa::string_view program_path) noexcept;
explicit Context(const char *program_path) noexcept
Expand Down
1 change: 1 addition & 0 deletions include/luisa/runtime/swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LC_RUNTIME_API Swapchain final : public Resource {
private:
friend class Device;
friend class ResourceGenerator;
friend class DXHDRExt;
PixelStorage _storage{};
Swapchain(DeviceInterface *device, const SwapchainCreationInfo &create_info) noexcept;
Swapchain(DeviceInterface *device, const SwapchainOption &option, uint64_t stream_handle) noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/backends/common/hlsl/builtin/hlsl_builtin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static HLSLCompressedHeader get_hlsl_builtin(luisa::string_view ss) {
dict.try_emplace("bc7_trymode_137cs", HLSLCompressedHeader{bc7_trymode_137cs, 1814, 7852});
dict.try_emplace("bc7_trymode_456cs", HLSLCompressedHeader{bc7_trymode_456cs, 2391, 11171});
dict.try_emplace("hlsl_header", HLSLCompressedHeader{hlsl_header, 1411, 5596});
dict.try_emplace("raytracing_header", HLSLCompressedHeader{raytracing_header, 868, 3614});
dict.try_emplace("raytracing_header", HLSLCompressedHeader{raytracing_header, 881, 3650});
dict.try_emplace("tex2d_bindless", HLSLCompressedHeader{tex2d_bindless, 551, 4136});
dict.try_emplace("tex3d_bindless", HLSLCompressedHeader{tex3d_bindless, 507, 3535});
dict.try_emplace("compute_quad", HLSLCompressedHeader{compute_quad, 87, 138});
Expand Down
8 changes: 4 additions & 4 deletions src/backends/common/hlsl/builtin/raytracing_header
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ray.TMin=rayDesc.v1;
ray.TMax=rayDesc.v3;
RayQuery<_CLOSEST_HIT_RAY_FLAG> q;
q.TraceRayInline(accel,_CLOSEST_HIT_RAY_FLAG,mask,ray);
_Hit1 pl;
_Hit1 pl=(_Hit1)0;
q.Proceed();
if(q.CommittedStatus()==COMMITTED_TRIANGLE_HIT){
pl.v0=q.CommittedInstanceIndex();
Expand Down Expand Up @@ -62,7 +62,7 @@ return ray;
}
template<typename Q>
_Hit0 _GetCommitedHit(Q q){
_Hit0 pl;
_Hit0 pl=(_Hit0)0;
switch(q.CommittedStatus()){
case COMMITTED_TRIANGLE_HIT:
pl.v0=q.CommittedInstanceIndex();
Expand All @@ -86,7 +86,7 @@ return pl;
}
template<typename Q>
_Hit1 _GetTriangleCandidateHit(Q q){
_Hit1 pl;
_Hit1 pl=(_Hit1)0;
pl.v0=q.CandidateInstanceIndex();
pl.v1=q.CandidatePrimitiveIndex();
pl.v2=q.CandidateTriangleBarycentrics();
Expand All @@ -95,7 +95,7 @@ return pl;
}
template<typename Q>
_Hit2 _GetProceduralCandidateHit(Q q){
_Hit2 pl;
_Hit2 pl=(_Hit2)0;
pl.v0=q.CandidateInstanceIndex();
pl.v1=q.CandidatePrimitiveIndex();
return pl;
Expand Down
2 changes: 1 addition & 1 deletion src/backends/common/hlsl/builtin/raytracing_header.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace lc_hlsl{
unsigned char raytracing_header[868]={120,218,237,87,223,111,218,48,16,126,175,212,255,193,83,95,64,66,8,210,110,83,75,169,148,133,20,162,1,129,36,221,84,77,85,228,38,110,103,53,56,224,24,214,172,237,255,62,59,191,72,66,10,76,219,180,151,62,180,114,238,206,231,239,190,59,159,143,35,23,221,97,130,128,173,12,117,83,53,45,123,160,89,182,33,95,219,151,67,185,15,106,233,202,190,212,13,69,181,245,137,60,189,82,159,51,169,249,89,155,216,19,67,87,212,222,149,33,15,249,82,27,105,150,246,69,53,235,135,7,71,169,107,121,124,253,154,91,89,81,212,137,101,95,106,70,114,180,60,238,217,42,255,51,85,217,80,6,165,147,242,24,205,129,220,83,141,231,63,1,200,194,57,226,24,129,1,195,233,18,209,240,60,219,54,214,199,234,5,176,135,138,157,234,100,207,235,108,219,177,35,144,146,51,18,10,103,104,54,247,32,67,231,194,43,129,51,4,172,139,195,3,123,128,89,27,216,22,133,14,82,60,63,64,1,171,241,125,140,127,99,114,47,59,14,242,16,133,12,251,196,100,116,233,176,37,69,0,10,105,195,2,20,134,61,20,56,141,37,38,12,204,96,240,80,127,58,60,48,98,161,80,242,67,249,255,166,78,241,61,38,221,59,207,135,236,184,150,108,106,174,90,205,213,183,214,77,163,240,221,46,125,75,55,245,196,73,15,83,228,8,24,27,126,164,146,31,169,228,71,42,248,177,70,28,74,166,107,103,82,248,184,150,30,119,162,48,98,202,43,43,245,2,44,184,205,162,25,209,198,77,53,226,241,210,171,197,196,84,238,104,8,126,4,40,1,36,38,125,238,69,62,38,212,119,16,114,107,66,129,239,106,139,166,226,207,102,152,49,228,154,12,178,101,80,171,119,187,138,62,226,117,100,169,61,219,50,52,121,220,31,170,194,185,160,123,238,113,166,186,185,77,26,9,24,36,14,210,136,139,30,35,167,194,164,157,55,153,80,204,23,120,85,178,145,242,54,22,197,144,220,123,232,19,164,161,131,8,163,216,9,50,203,227,188,37,15,223,138,52,47,200,11,80,6,233,68,58,61,57,253,240,81,58,125,47,84,156,102,196,107,135,196,65,191,188,90,141,197,43,0,236,116,245,86,147,157,77,118,182,212,96,161,181,20,106,47,201,195,98,239,52,144,48,77,3,9,223,210,208,217,100,103,159,52,236,232,215,191,151,161,6,200,214,83,158,45,11,100,112,250,136,125,245,169,39,238,100,109,10,22,117,192,89,143,73,1,62,191,179,169,46,166,61,186,180,137,214,205,105,51,62,35,3,43,151,174,36,49,93,191,249,152,151,180,133,164,96,35,9,201,207,84,34,154,143,232,18,163,228,204,72,24,231,166,235,174,93,197,217,225,146,48,47,145,132,36,115,85,221,121,18,198,98,160,149,156,77,147,167,174,5,108,206,81,236,1,185,92,16,209,244,148,42,163,238,20,252,192,204,249,94,213,136,133,161,3,3,4,170,251,241,217,127,107,199,237,100,117,82,73,207,45,69,240,161,179,1,189,106,78,249,23,97,180,50,152,210,94,48,249,196,3,151,30,59,75,119,181,114,186,125,30,146,233,122,172,225,185,78,153,83,32,113,177,203,13,75,73,79,222,225,44,226,212,108,75,196,169,201,182,196,165,54,187,223,209,178,101,185,170,119,7,42,69,129,70,115,132,187,164,208,123,45,84,233,175,134,186,23,188,149,143,93,62,236,71,185,94,3,20,160,26,81,231,1,46,14,152,192,199,39,31,177,60,223,40,140,186,104,174,101,7,25,28,17,97,228,98,219,115,118,235,251,94,50,226,190,189,97,229,241,182,252,107,105,251,104,91,182,46,60,92,197,89,54,125,198,54,219,232,187,220,60,59,214,173,129,54,238,199,233,251,5,64,150,165,243};
unsigned char raytracing_header[881]={120,218,237,87,223,111,218,48,16,126,175,212,255,193,83,95,130,132,16,164,221,166,150,82,41,11,105,137,6,4,146,116,83,53,85,145,155,184,157,181,224,64,98,88,179,118,255,251,108,231,7,73,72,129,105,155,246,210,7,144,115,119,62,127,247,221,229,124,57,242,208,61,38,8,56,234,208,176,52,203,118,6,186,237,152,202,141,115,57,84,174,128,148,173,156,75,195,84,53,199,152,40,211,107,237,57,151,90,31,245,137,51,49,13,85,235,95,155,202,144,45,245,145,110,235,159,52,171,113,120,112,148,185,86,198,55,47,185,85,84,85,155,216,206,165,110,166,71,43,227,190,163,177,159,165,41,166,58,168,156,84,196,104,13,148,190,102,62,255,9,64,26,207,17,195,8,76,24,79,151,40,140,207,243,109,99,99,172,93,0,103,168,58,153,78,241,253,238,182,29,59,2,169,56,35,49,119,134,102,115,31,82,116,206,189,18,56,67,192,190,56,60,112,6,152,118,128,99,135,208,69,170,31,68,40,162,18,219,71,217,51,38,15,138,235,34,31,133,144,226,128,88,52,92,186,116,25,34,0,185,180,105,131,16,198,125,20,185,205,37,38,20,204,96,244,173,241,116,120,96,38,66,174,100,135,178,255,150,17,226,7,76,122,247,126,0,233,177,148,110,106,173,218,173,213,151,246,109,179,244,220,169,60,203,183,141,212,73,31,135,200,229,48,54,252,200,21,63,114,197,143,92,242,99,143,24,148,92,215,201,165,240,113,45,61,238,138,48,18,202,107,43,245,2,44,152,205,162,37,104,99,166,58,241,89,233,73,9,49,181,59,154,156,31,14,138,3,73,72,159,251,61,73,172,26,109,225,108,18,6,46,66,158,196,45,240,189,180,104,169,193,108,134,41,69,158,69,33,93,70,82,163,215,83,141,17,43,40,91,235,59,182,169,43,227,171,161,198,79,225,188,207,125,70,89,175,176,73,39,17,133,196,69,58,241,208,163,112,202,77,58,69,147,73,136,217,2,175,42,54,114,209,198,14,49,36,15,62,250,0,195,216,69,132,134,216,141,114,203,227,162,37,227,193,22,154,159,200,143,80,14,233,68,62,61,57,125,247,94,62,125,203,85,140,111,196,138,136,176,232,147,199,23,202,178,252,46,0,39,91,189,22,103,119,147,157,45,197,88,234,49,165,34,76,243,176,216,59,13,36,206,210,64,226,215,52,116,55,217,217,39,13,59,26,247,239,101,168,9,242,245,148,101,203,6,57,156,43,68,63,7,161,207,223,73,105,10,22,13,192,88,79,72,1,1,123,103,51,93,66,187,120,105,83,173,87,208,230,124,10,3,187,144,174,52,49,189,160,245,88,148,116,184,164,100,35,115,201,143,76,194,155,15,239,18,163,244,76,33,76,114,211,243,214,174,146,236,48,73,92,148,200,92,146,187,170,239,60,41,99,9,208,90,206,166,233,157,215,6,14,227,40,241,128,60,38,16,52,61,101,202,172,55,183,69,111,142,190,99,234,126,173,235,200,124,135,11,35,4,234,27,243,217,127,235,203,157,116,117,82,203,211,93,136,224,183,238,6,244,186,201,229,95,132,209,206,97,202,123,193,100,51,16,92,250,244,44,219,213,46,232,246,185,81,166,235,65,135,37,61,99,78,133,196,195,30,51,172,100,191,122,51,231,161,103,246,91,66,207,76,182,101,48,179,217,125,179,86,45,171,117,190,59,98,89,68,44,38,11,111,25,66,255,165,152,229,60,102,249,111,198,188,23,206,85,128,61,246,65,32,178,191,70,202,209,53,69,83,2,30,142,40,7,202,134,34,190,60,223,40,149,6,239,187,85,7,57,28,30,170,112,177,237,166,187,11,2,63,29,131,95,175,183,234,8,92,253,162,218,62,254,86,173,75,119,90,121,204,205,110,184,205,198,250,166,48,234,142,13,123,160,143,175,146,244,253,2,8,227,175,191};
}
Loading

0 comments on commit 2ef8938

Please sign in to comment.