diff --git a/cmake/bgfx.cmake b/cmake/bgfx.cmake index 51d9402a..e103f68d 100644 --- a/cmake/bgfx.cmake +++ b/cmake/bgfx.cmake @@ -3,7 +3,7 @@ include(ExternalProject) # Download `bx` and extract source path. ExternalProject_Add(bx_EXTERNAL GIT_REPOSITORY "https://github.com/bkaradzic/bx.git" - GIT_TAG "f939b2c3172b1c19f15659613b2f9f9de1f5e820" + GIT_TAG "51f25ba638b9cb35eb2ac078f842a4bed0746d56" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" @@ -21,7 +21,7 @@ set(bx_GENIE "${SOURCE_DIR}/tools/bin/${bx_SYSTEM_NAME}/genie") # Download `bimg` and extract source path. ExternalProject_Add(bimg_EXTERNAL GIT_REPOSITORY "https://github.com/bkaradzic/bimg.git" - GIT_TAG "7b70810f4bfd2cf81c755c413c66e0e82ea8acc5" + GIT_TAG "8355d36befc90c1db82fca8e54f38bfb7eeb3530" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" @@ -75,8 +75,8 @@ endif() # and build it using `bx`. ExternalProject_Add(bgfx_EXTERNAL DEPENDS bx_EXTERNAL bimg_EXTERNAL - GIT_REPOSITORY "https://github.com/pyrym/bgfx.git" - GIT_TAG "e368f78c9562e37c071e56b754e3c712d3601ef1" + GIT_REPOSITORY "https://github.com/bkaradzic/bgfx.git" + GIT_TAG "e0d26507dc1982b53c7f80364637a9a2098f5055" CONFIGURE_COMMAND ${bgfx_CONFIGURE_COMMAND} BUILD_COMMAND ${bgfx_BUILD_COMMAND} INSTALL_COMMAND "" diff --git a/dist/include/bgfx_truss.c99.h b/dist/include/bgfx_truss.c99.h index cf8440d5..525e458b 100644 --- a/dist/include/bgfx_truss.c99.h +++ b/dist/include/bgfx_truss.c99.h @@ -358,6 +358,7 @@ typedef struct bgfx_init_s { bgfx_renderer_type_t type; uint16_t vendorId; uint16_t deviceId; + uint64_t capabilities; bool debug; bool profile; bgfx_platform_data_t platformData; @@ -501,7 +502,7 @@ typedef struct bgfx_encoder_s bgfx_encoder_t; const bgfx_memory_t* bgfx_alloc(uint32_t _size); void bgfx_alloc_instance_data_buffer(bgfx_instance_data_buffer_t* _idb, uint32_t _num, uint16_t _stride); uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num); -bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_layout_t * _layout, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices); +bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_layout_t * _layout, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices, bool _index32); void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num, bool _index32); void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_layout_t * _layout); void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve); @@ -593,7 +594,7 @@ void bgfx_encoder_submit_occlusion_query(bgfx_encoder_t* _this, bgfx_view_id_t _ void bgfx_encoder_touch(bgfx_encoder_t* _this, bgfx_view_id_t _id); uint32_t bgfx_frame(bool _capture); uint32_t bgfx_get_avail_instance_data_buffer(uint32_t _num, uint16_t _stride); -uint32_t bgfx_get_avail_transient_index_buffer(uint32_t _num); +uint32_t bgfx_get_avail_transient_index_buffer(uint32_t _num, bool _index32); uint32_t bgfx_get_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_layout_t * _layout); const bgfx_caps_t* bgfx_get_caps(void); void* bgfx_get_direct_access_ptr(bgfx_texture_handle_t _handle); @@ -609,6 +610,7 @@ bgfx_texture_handle_t bgfx_get_texture(bgfx_frame_buffer_handle_t _handle, uint8 void bgfx_get_uniform_info(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t * _info); bool bgfx_init(const bgfx_init_t * _init); void bgfx_init_ctor(bgfx_init_t* _init); +bool bgfx_is_frame_buffer_valid(uint8_t _num, const bgfx_attachment_t* _attachment); bool bgfx_is_texture_valid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags); const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size); const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData); diff --git a/dist/include/bgfxdefines.h b/dist/include/bgfxdefines.h index 570cf4a4..45a9c61d 100644 --- a/dist/include/bgfxdefines.h +++ b/dist/include/bgfxdefines.h @@ -15,7 +15,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(112) +#define BGFX_API_VERSION UINT32_C(115) /** * Color RGB/alpha/depth write. When it's not specified write will be disabled. @@ -262,7 +262,7 @@ #define BGFX_DISCARD_BINDINGS UINT8_C(0x01) //!< Discard texture sampler and buffer bindings. #define BGFX_DISCARD_INDEX_BUFFER UINT8_C(0x02) //!< Discard index buffer. #define BGFX_DISCARD_INSTANCE_DATA UINT8_C(0x04) //!< Discard instance data. -#define BGFX_DISCARD_STATE UINT8_C(0x08) //!< Discard state. +#define BGFX_DISCARD_STATE UINT8_C(0x08) //!< Discard state and uniform bindings. #define BGFX_DISCARD_TRANSFORM UINT8_C(0x10) //!< Discard transform. #define BGFX_DISCARD_VERTEX_STREAMS UINT8_C(0x20) //!< Discard vertex streams. #define BGFX_DISCARD_ALL UINT8_C(0xff) //!< Discard all states. diff --git a/dist/scripts/dev/bgfxgen.moon b/dist/scripts/dev/bgfxgen.moon index 1829721f..546843a8 100644 --- a/dist/scripts/dev/bgfxgen.moon +++ b/dist/scripts/dev/bgfxgen.moon @@ -64,12 +64,21 @@ remove_comment = (s) -> fix5p1 = (data) -> lines = sutil.split_lines data outlines = {} + cur_enum = nil for linepos = 1, #lines - curline = sutil.strip lines[linepos] + curline = remove_comment sutil.strip lines[linepos] + if (curline\sub 1,4) == "enum" + cur_enum = curline\sub 5,-1 + elseif cur_enum and curline == "" + if (outlines[#outlines]\sub -2,-1) != "()" + print("Enum missing function call: #{cur_enum}") + outlines[#outlines] = outlines[#outlines] .. "()" + cur_enum = nil + if (curline\sub 1,2) == "()" - outlines[#outlines] = (remove_comment outlines[#outlines]) .. curline + outlines[#outlines] = outlines[#outlines] .. curline else - outlines[#outlines+1] = lines[linepos] + outlines[#outlines+1] = curline temp = io.open "bleh.lua", "wt" temp\write table.concat outlines, "\n" temp\close! @@ -96,7 +105,8 @@ key_sorted_concat = (t, sep) -> ordered_concat t, sorted_keys, sep exec_in = (env, fn) -> - chunk, err = loadstring fix5p1 rawload fn + src = fix5p1 rawload fn + chunk, err = loadstring src if not chunk truss.error "Error parsing #{fn}: #{err}" setfenv chunk, env @@ -109,12 +119,18 @@ load_idl = (buildpath) -> idl = exec_in env, "#{path}/scripts/idl.lua" exec_in idl, "#{path}/scripts/bgfx.idl" +BANNED_TYPES = {"va_list"} + is_api_func = (line) -> parts = sutil.split " ", line if parts[1] != "BGFX_C_API" then return nil api_key = (parts[2] != "const" and parts[3]) or parts[4] or line api_key = (sutil.split "%(", api_key)[1] - (table.concat [p for p in *parts[2,]], " "), api_key + signature = table.concat [p for p in *parts[2,]], " " + for bad_type in *BANNED_TYPES + if line\find bad_type + signature = "//" .. signature + signature, api_key get_functions = (buildpath) -> -- generating function signatures from the IDL is too much of a pain @@ -294,8 +310,8 @@ gen_header = (buildpath) -> } export init = -> - bpath = "../build" - print "Copying files" + bpath = truss.args[3] or "../build" + print "Copying files from #{bpath}" copy_files bpath print "Generating include/bgfx_truss.c99.h" truss.save_string "include/bgfx_truss.c99.h", (gen_header bpath) diff --git a/dist/scripts/dev/buildshaders.moon b/dist/scripts/dev/buildshaders.moon index ca8903c8..fc9bb0dc 100644 --- a/dist/scripts/dev/buildshaders.moon +++ b/dist/scripts/dev/buildshaders.moon @@ -38,7 +38,7 @@ WIN_SHADER_TYPES = { } PLATFORMS = { windows: "dx11", - linux: "glsl", + --linux: "glsl", osx: "mtl", vulkan: "spirv" } diff --git a/dist/scripts/examples/logo.t b/dist/scripts/examples/logo.t index 971e1fe3..f98e7285 100644 --- a/dist/scripts/examples/logo.t +++ b/dist/scripts/examples/logo.t @@ -284,7 +284,7 @@ function init() async.await_frames(5) add_2d_drawable(textbox, { x = 390, y = 10, w = 220, h = 120, - font_size = 100, text = '0.1.α' + font_size = 100, text = truss.C.get_version() }) if gif_mode then return end -- spawn caps diff --git a/dist/scripts/gfx/bgfx_constants.t b/dist/scripts/gfx/bgfx_constants.t index 66b86315..eebb5a4f 100644 --- a/dist/scripts/gfx/bgfx_constants.t +++ b/dist/scripts/gfx/bgfx_constants.t @@ -1,6 +1,6 @@ --Autogenerated bgfx constants return { - BGFX_API_VERSION = 0x70ULL, + BGFX_API_VERSION = 0x73ULL, BGFX_STATE_WRITE_R = 0x1ULL, BGFX_STATE_WRITE_G = 0x2ULL, BGFX_STATE_WRITE_B = 0x4ULL, diff --git a/dist/scripts/gfx/geometry.t b/dist/scripts/gfx/geometry.t index f6065099..f7fcde92 100644 --- a/dist/scripts/gfx/geometry.t +++ b/dist/scripts/gfx/geometry.t @@ -54,10 +54,9 @@ function TransientGeometry:allocate(n_verts, n_indices, vertinfo) return end + local index_type = uint16 if n_verts >= 2^16 then - truss.error("TransientGeometry [" .. self.name .. - "] cannot have more then 2^16 vertices.") - return false + index_type = uint32 end local verts_available = bgfx.get_avail_transient_vertex_buffer(n_verts, @@ -66,16 +65,17 @@ function TransientGeometry:allocate(n_verts, n_indices, vertinfo) log.error("Not enough space to allocate " .. n_verts .. " vertices.") return false end - local indices_available = bgfx.get_avail_transient_index_buffer(n_indices) + local indices_available = bgfx.get_avail_transient_index_buffer(n_indices, + index_type == uint32) if indices_available < n_indices then log.error("Not enough space to allocate " .. n_indices .. " indices.") return false end bgfx.alloc_transient_buffers(self._transient_vb, vertinfo.vdecl, n_verts, - self._transient_ib, n_indices) + self._transient_ib, n_indices, index_type == uint32) - self.indices = terralib.cast(&uint16, self._transient_ib.data) + self.indices = terralib.cast(&index_type, self._transient_ib.data) self.verts = terralib.cast(&vertinfo.ttype, self._transient_vb.data) self.allocated = true diff --git a/dist/shaders/raw/basicpbr/vs_shadowpbr.sc b/dist/shaders/raw/basicpbr/vs_shadowpbr.sc index 2dc01129..a89443f3 100644 --- a/dist/shaders/raw/basicpbr/vs_shadowpbr.sc +++ b/dist/shaders/raw/basicpbr/vs_shadowpbr.sc @@ -1,5 +1,8 @@ $input a_position, a_normal -$output v_wpos, v_wnormal, v_viewdir, v_shadowcoord +$output v_wpos, v_wnormal, v_viewdir +//, v_shadowcoord + +// TODO: get this working or delete /* * Copyright 2015 Pyry Matikainen. All rights reserved. @@ -25,5 +28,5 @@ void main() const float shadowMapOffset = 0.001; vec3 posOffset = a_position + normal.xyz * shadowMapOffset; - v_shadowcoord = mul(u_lightMtx, vec4(posOffset, 1.0) ); + //v_shadowcoord = mul(u_lightMtx, vec4(posOffset, 1.0) ); } diff --git a/dist/shaders/raw/common/bgfx_compute.sh b/dist/shaders/raw/common/bgfx_compute.sh index 556972eb..d05b2328 100644 --- a/dist/shaders/raw/common/bgfx_compute.sh +++ b/dist/shaders/raw/common/bgfx_compute.sh @@ -15,9 +15,11 @@ #endif // BGFX_SHADER_LANGUAGE_HLSL #if BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV -# define ANNOTATION(_format) [[spv::format_ ## _format]] +# define FORMAT(_format) [[spv::format_ ## _format]] +# define WRITEONLY [[spv::nonreadable]] #else -# define ANNOTATION(_format) +# define FORMAT(_format) +# define WRITEONLY #endif // BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV #if BGFX_SHADER_LANGUAGE_GLSL @@ -74,66 +76,69 @@ #define SHARED groupshared -#define r32ui uint -#define rg32ui uint2 -#define rgba32ui uint4 -#define r32f float -#define r16f float -#define rg16f float2 -#define rgba16f float4 +#define COMP_r32ui uint +#define COMP_rg32ui uint2 +#define COMP_rgba32ui uint4 +#define COMP_r32f float +#define COMP_r16f float +#define COMP_rg16f float2 +#define COMP_rgba16f float4 #if BGFX_SHADER_LANGUAGE_HLSL -# define rgba8 unorm float4 -# define rg8 unorm float2 -# define r8 unorm float +# define COMP_rgba8 unorm float4 +# define COMP_rg8 unorm float2 +# define COMP_r8 unorm float #else -# define rgba8 float4 -# define rg8 float2 -# define r8 float +# define COMP_rgba8 float4 +# define COMP_rg8 float2 +# define COMP_r8 float #endif // BGFX_SHADER_LANGUAGE_HLSL -#define rgba32f float4 +#define COMP_rgba32f float4 -#define IMAGE2D_RO( _name, _format, _reg) \ - Texture2D<_format> _name ## Texture : REGISTER(t, _reg); \ - static BgfxROImage2D_ ## _format _name = { _name ## Texture } +#define IMAGE2D_RO( _name, _format, _reg) \ + FORMAT(_format) Texture2D _name : REGISTER(t, _reg); \ #define UIMAGE2D_RO(_name, _format, _reg) IMAGE2D_RO(_name, _format, _reg) -#define IMAGE2D_RW( _name, _format, _reg) \ - ANNOTATION(_format) RWTexture2D<_format> _name ## Texture : REGISTER(u, _reg); \ - static BgfxRWImage2D_ ## _format _name = { _name ## Texture } +#define IMAGE2D_WR( _name, _format, _reg) \ + WRITEONLY FORMAT(_format) RWTexture2D _name : REGISTER(u, _reg); \ + +#define UIMAGE2D_WR(_name, _format, _reg) IMAGE2D_WR(_name, _format, _reg) + +#define IMAGE2D_RW( _name, _format, _reg) \ + FORMAT(_format) RWTexture2D _name : REGISTER(u, _reg); \ -#define IMAGE2D_WR( _name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) -#define UIMAGE2D_WR(_name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) #define UIMAGE2D_RW(_name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) -#define IMAGE2D_ARRAY_RO(_name, _format, _reg) \ - Texture2DArray<_format> _name ## Texture : REGISTER(t, _reg); \ - static BgfxROImage2DArray_ ## _format _name = { _name ## Texture } +#define IMAGE2D_ARRAY_RO(_name, _format, _reg) \ + FORMAT(_format) Texture2DArray _name : REGISTER(t, _reg); \ #define UIMAGE2D_ARRAY_RO(_name, _format, _reg) IMAGE2D_ARRAY_RO(_name, _format, _reg) -#define IMAGE2D_ARRAY_RW(_name, _format, _reg) \ - ANNOTATION(_format) RWTexture2DArray<_format> _name ## Texture : REGISTER(u, _reg); \ - static BgfxRWImage2DArray_ ## _format _name = { _name ## Texture } +#define IMAGE2D_ARRAY_WR( _name, _format, _reg) \ + WRITEONLY FORMAT(_format) RWTexture2DArray _name : REGISTER(u, _reg); \ + +#define UIMAGE2D_ARRAY_WR(_name, _format, _reg) IMAGE2D_ARRAY_WR(_name, _format, _reg) + +#define IMAGE2D_ARRAY_RW(_name, _format, _reg) \ + FORMAT(_format) RWTexture2DArray _name : REGISTER(u, _reg); \ #define UIMAGE2D_ARRAY_RW(_name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) -#define IMAGE2D_ARRAY_WR( _name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) -#define UIMAGE2D_ARRAY_WR(_name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) -#define IMAGE3D_RO( _name, _format, _reg) \ - Texture3D<_format> _name ## Texture : REGISTER(t, _reg); \ - static BgfxROImage3D_ ## _format _name = { _name ## Texture } +#define IMAGE3D_RO( _name, _format, _reg) \ + FORMAT(_format) Texture3D _name : REGISTER(t, _reg); #define UIMAGE3D_RO(_name, _format, _reg) IMAGE3D_RO(_name, _format, _reg) -#define IMAGE3D_RW( _name, _format, _reg) \ - ANNOTATION(_format) RWTexture3D<_format> _name ## Texture : REGISTER(u, _reg); \ - static BgfxRWImage3D_ ## _format _name = { _name ## Texture } +#define IMAGE3D_WR( _name, _format, _reg) \ + WRITEONLY FORMAT(_format) RWTexture3D _name : REGISTER(u, _reg); -#define UIMAGE3D_RW(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) -#define IMAGE3D_WR( _name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) #define UIMAGE3D_WR(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) +#define IMAGE3D_RW( _name, _format, _reg) \ + FORMAT(_format) RWTexture3D _name : REGISTER(u, _reg); \ + +#define UIMAGE3D_RW(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) + #if BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV #define BUFFER_RO(_name, _struct, _reg) StructuredBuffer<_struct> _name : REGISTER(t, _reg) #define BUFFER_RW(_name, _struct, _reg) RWStructuredBuffer <_struct> _name : REGISTER(u, _reg) @@ -146,154 +151,118 @@ #define NUM_THREADS(_x, _y, _z) [numthreads(_x, _y, _z)] -#define __IMAGE_IMPL_S(_format, _storeComponents, _type, _loadComponents) \ +#define __IMAGE_IMPL_A(_format, _storeComponents, _type, _loadComponents) \ + _type imageLoad(Texture2D<_format> _image, ivec2 _uv) \ + { \ + return _image[_uv]._loadComponents; \ + } \ \ - struct BgfxROImage2D_ ## _format \ - { \ - Texture2D<_format> m_texture; \ - }; \ + ivec2 imageSize(Texture2D<_format> _image) \ + { \ + uvec2 result; \ + _image.GetDimensions(result.x, result.y); \ + return ivec2(result); \ + } \ \ - struct BgfxRWImage2D_ ## _format \ - { \ - ANNOTATION(_format) RWTexture2D<_format> m_texture; \ - }; \ + _type imageLoad(RWTexture2D<_format> _image, ivec2 _uv) \ + { \ + return _image[_uv]._loadComponents; \ + } \ \ - struct BgfxROImage2DArray_ ## _format \ - { \ - Texture2DArray<_format> m_texture; \ - }; \ + void imageStore(RWTexture2D<_format> _image, ivec2 _uv, _type _value) \ + { \ + _image[_uv] = _value._storeComponents; \ + } \ \ - struct BgfxRWImage2DArray_ ## _format \ - { \ - ANNOTATION(_format) RWTexture2DArray<_format> m_texture; \ - }; \ + ivec2 imageSize(RWTexture2D<_format> _image) \ + { \ + uvec2 result; \ + _image.GetDimensions(result.x, result.y); \ + return ivec2(result); \ + } \ \ - struct BgfxROImage3D_ ## _format \ - { \ - Texture3D<_format> m_texture; \ - }; \ - \ - struct BgfxRWImage3D_ ## _format \ - { \ - ANNOTATION(_format) RWTexture3D<_format> m_texture; \ - }; \ - -#define __IMAGE_IMPL_A(_format, _storeComponents, _type, _loadComponents) \ - __IMAGE_IMPL_S(_format, _storeComponents, _type, _loadComponents) \ + _type imageLoad(Texture2DArray<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - _type imageLoad(BgfxROImage2D_ ## _format _image, ivec2 _uv) \ - { \ - return _image.m_texture[_uv]._loadComponents; \ - } \ + ivec3 imageSize(Texture2DArray<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ + } \ \ - ivec2 imageSize(BgfxROImage2D_ ## _format _image) \ - { \ - uvec2 result; \ - _image.m_texture.GetDimensions(result.x, result.y); \ - return ivec2(result); \ - } \ + _type imageLoad(RWTexture2DArray<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - _type imageLoad(BgfxRWImage2D_ ## _format _image, ivec2 _uv) \ - { \ - return _image.m_texture[_uv]._loadComponents; \ - } \ + void imageStore(RWTexture2DArray<_format> _image, ivec3 _uvw, _type _value) \ + { \ + _image[_uvw] = _value._storeComponents; \ + } \ \ - ivec2 imageSize(BgfxRWImage2D_ ## _format _image) \ - { \ - uvec2 result; \ - _image.m_texture.GetDimensions(result.x, result.y); \ - return ivec2(result); \ - } \ + ivec3 imageSize(RWTexture2DArray<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ + } \ \ - void imageStore(BgfxRWImage2D_ ## _format _image, ivec2 _uv, _type _value) \ - { \ - _image.m_texture[_uv] = _value._storeComponents; \ - } \ + _type imageLoad(Texture3D<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - _type imageLoad(BgfxROImage2DArray_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ + ivec3 imageSize(Texture3D<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ + } \ \ - ivec3 imageSize(BgfxROImage2DArray_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ - } \ + _type imageLoad(RWTexture3D<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - _type imageLoad(BgfxRWImage2DArray_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ + void imageStore(RWTexture3D<_format> _image, ivec3 _uvw, _type _value) \ + { \ + _image[_uvw] = _value._storeComponents; \ + } \ \ - void imageStore(BgfxRWImage2DArray_ ## _format _image, ivec3 _uvw, _type _value) \ - { \ - _image.m_texture[_uvw] = _value._storeComponents; \ - } \ - \ - ivec3 imageSize(BgfxRWImage2DArray_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ - } \ - \ - _type imageLoad(BgfxROImage3D_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ - \ - ivec3 imageSize(BgfxROImage3D_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ - } \ - \ - _type imageLoad(BgfxRWImage3D_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ - \ - ivec3 imageSize(BgfxRWImage3D_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ - } \ - \ - void imageStore(BgfxRWImage3D_ ## _format _image, ivec3 _uvw, _type _value) \ - { \ - _image.m_texture[_uvw] = _value._storeComponents; \ + ivec3 imageSize(RWTexture3D<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ } #define __IMAGE_IMPL_ATOMIC(_format, _storeComponents, _type, _loadComponents) \ \ - void imageAtomicAdd(BgfxRWImage2D_ ## _format _image, ivec2 _uv, _type _value) \ + void imageAtomicAdd(RWTexture2D<_format> _image, ivec2 _uv, _type _value) \ { \ - InterlockedAdd(_image.m_texture[_uv], _value._storeComponents); \ + InterlockedAdd(_image[_uv], _value._storeComponents); \ } \ -__IMAGE_IMPL_A(rgba8, xyzw, vec4, xyzw) -__IMAGE_IMPL_A(rg8, xy, vec4, xyyy) -__IMAGE_IMPL_A(r8, x, vec4, xxxx) -__IMAGE_IMPL_A(rg16f, xy, vec4, xyyy) +__IMAGE_IMPL_A(float, x, vec4, xxxx) +__IMAGE_IMPL_A(float2, xy, vec4, xyyy) +__IMAGE_IMPL_A(float4, xyzw, vec4, xyzw) + +__IMAGE_IMPL_A(uint, x, uvec4, xxxx) +__IMAGE_IMPL_A(uint2, xy, uvec4, xyyy) +__IMAGE_IMPL_A(uint4, xyzw, uvec4, xyzw) + #if BGFX_SHADER_LANGUAGE_HLSL -__IMAGE_IMPL_S(rgba16f, xyzw, vec4, xyzw) -__IMAGE_IMPL_S(r16f, x, vec4, xxxx) -#else -__IMAGE_IMPL_A(rgba16f, xyzw, vec4, xyzw) -__IMAGE_IMPL_A(r16f, x, vec4, xxxx) -#endif // BGFX_SHADER_LANGUAGE_HLSL -__IMAGE_IMPL_A(r32f, x, vec4, xxxx) -__IMAGE_IMPL_A(rgba32f, xyzw, vec4, xyzw) -__IMAGE_IMPL_A(r32ui, x, uvec4, xxxx) -__IMAGE_IMPL_A(rg32ui, xy, uvec4, xyyy) -__IMAGE_IMPL_A(rgba32ui, xyzw, uvec4, xyzw) +__IMAGE_IMPL_A(unorm float, x, vec4, xxxx) +__IMAGE_IMPL_A(unorm float2, xy, vec4, xyyy) +__IMAGE_IMPL_A(unorm float4, xyzw, vec4, xyzw) +#endif + +__IMAGE_IMPL_ATOMIC(uint, x, uvec4, xxxx) -__IMAGE_IMPL_ATOMIC(r32ui, x, uvec4, xxxx) #define atomicAdd(_mem, _data) InterlockedAdd(_mem, _data) #define atomicAnd(_mem, _data) InterlockedAnd(_mem, _data) diff --git a/dist/shaders/raw/common/bgfx_shader.sh b/dist/shaders/raw/common/bgfx_shader.sh index f11bcd25..15cee368 100644 --- a/dist/shaders/raw/common/bgfx_shader.sh +++ b/dist/shaders/raw/common/bgfx_shader.sh @@ -42,7 +42,7 @@ || BGFX_SHADER_LANGUAGE_METAL # define CONST(_x) static const _x # define dFdx(_x) ddx(_x) -# define dFdy(_y) ddy(-_y) +# define dFdy(_y) ddy(-(_y)) # define inversesqrt(_x) rsqrt(_x) # define fract(_x) frac(_x) @@ -62,8 +62,8 @@ # if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL # define dFdxCoarse(_x) ddx_coarse(_x) # define dFdxFine(_x) ddx_fine(_x) -# define dFdyCoarse(_y) ddy_coarse(-_y) -# define dFdyFine(_y) ddy_fine(-_y) +# define dFdyCoarse(_y) ddy_coarse(-(_y)) +# define dFdyFine(_y) ddy_fine(-(_y)) # endif // BGFX_SHADER_LANGUAGE_HLSL > 400 # if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL @@ -301,6 +301,20 @@ vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod) return result; } +vec2 bgfxTextureSize(BgfxISampler2D _sampler, int _lod) +{ + vec2 result; + _sampler.m_texture.GetDimensions(result.x, result.y); + return result; +} + +vec2 bgfxTextureSize(BgfxUSampler2D _sampler, int _lod) +{ + vec2 result; + _sampler.m_texture.GetDimensions(result.x, result.y); + return result; +} + vec4 bgfxTextureGather(BgfxSampler2D _sampler, vec2 _coord) { return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord ); diff --git a/dist/shaders/raw/common/shaderlib.sh b/dist/shaders/raw/common/shaderlib.sh index 91a76432..baa5aed9 100644 --- a/dist/shaders/raw/common/shaderlib.sh +++ b/dist/shaders/raw/common/shaderlib.sh @@ -413,4 +413,19 @@ mat3 cofactor(mat4 _m) ); } +float toClipSpaceDepth(float _depthTextureZ) +{ +#if BGFX_SHADER_LANGUAGE_GLSL + return _depthTextureZ * 2.0 - 1.0; +#else + return _depthTextureZ; +#endif // BGFX_SHADER_LANGUAGE_GLSL +} + +vec3 clipToWorld(mat4 _invViewProj, vec3 _clipPos) +{ + vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) ); + return wpos.xyz / wpos.w; +} + #endif // __SHADERLIB_SH__ diff --git a/dist/shaders/raw/depth/fs_depth.sc b/dist/shaders/raw/depth/fs_depth.sc index 9ae77ea9..06860bd1 100644 --- a/dist/shaders/raw/depth/fs_depth.sc +++ b/dist/shaders/raw/depth/fs_depth.sc @@ -12,8 +12,8 @@ void main() float depthMax = 3.0; float rawDepth = clamp(v_vpos.z / depthMax, 0.0, 1.0); int idepth = rawDepth * 65535.0; - float b0 = (float)(idepth % 256) / 255.0; - float b1 = (float)((idepth >> 8) % 256) / 255.0; + float b0 = float(idepth % 256) / 255.0; + float b1 = float((idepth >> 8) % 256) / 255.0; gl_FragColor = vec4(b1, b0, 1.0, 1.0); } diff --git a/src/trussapi.h b/src/trussapi.h index 6d006aef..870e43e1 100644 --- a/src/trussapi.h +++ b/src/trussapi.h @@ -6,7 +6,7 @@ #ifndef TRUSSAPI_H_HEADER_GUARD #define TRUSSAPI_H_HEADER_GUARD -#define TRUSS_VERSION_STRING "0.1.1" +#define TRUSS_VERSION_STRING "0.1.2" #include // Needed for uint64_t etc. #include // Needed for size_t etc.