From d94d63a542f0e4c7ca6c10e278659a967a9ea576 Mon Sep 17 00:00:00 2001 From: Alex Dunn Date: Fri, 2 Aug 2024 08:59:13 -0700 Subject: [PATCH] GPU perf optimization: Surface data See merge request lightspeedrtx/dxvk-remix-nv!921 --- src/dxvk/rtx_render/rtx_materials.h | 2 +- .../rtx/algorithm/integrator_indirect.slangh | 3 +- .../rtx/algorithm/nee_cache_light.slangh | 6 +- src/dxvk/shaders/rtx/algorithm/resolve.slangh | 6 +- .../shaders/rtx/algorithm/visibility.slangh | 6 +- .../shaders/rtx/concept/surface/surface.h | 496 +++++++++++++++--- .../rtx/concept/surface/surface.slangh | 1 - .../rtx/concept/surface/surface_create.slangh | 156 ------ .../shaders/rtx/pass/common_bindings.slangh | 2 +- .../pass/integrate/integrate_direct.slangh | 1 - .../pass/integrate/integrate_indirect.slangh | 1 - .../nee_cache/update_nee_cache.comp.slang | 1 - .../bake_opacity_micromap.comp.slang | 4 +- ...e_opacity_micromap_rtx_dependencies.slangh | 1 - .../rtxdi/restir_gi_spatial_reuse.comp.slang | 1 - .../rtxdi/restir_gi_temporal_reuse.comp.slang | 1 - .../pass/rtxdi/rtxdi_spatial_reuse.comp.slang | 1 - .../rtxdi/rtxdi_temporal_reuse.comp.slang | 1 - .../shaders/rtx/utility/buffer_helpers.slangh | 29 - 19 files changed, 427 insertions(+), 292 deletions(-) delete mode 100644 src/dxvk/shaders/rtx/concept/surface/surface_create.slangh delete mode 100644 src/dxvk/shaders/rtx/utility/buffer_helpers.slangh diff --git a/src/dxvk/rtx_render/rtx_materials.h b/src/dxvk/rtx_render/rtx_materials.h index 7a0c56e57..a9458e0e3 100644 --- a/src/dxvk/rtx_render/rtx_materials.h +++ b/src/dxvk/rtx_render/rtx_materials.h @@ -107,10 +107,10 @@ struct RtSurface { writeGPUHelper(data, offset, packedHash); writeGPUHelper(data, offset, positionOffset); - writeGPUHelper(data, offset, objectPickingValue); writeGPUHelper(data, offset, normalOffset); writeGPUHelper(data, offset, texcoordOffset); writeGPUHelper(data, offset, color0Offset); + writeGPUHelper(data, offset, objectPickingValue); writeGPUHelperExplicit<1>(data, offset, positionStride); writeGPUHelperExplicit<1>(data, offset, normalStride); diff --git a/src/dxvk/shaders/rtx/algorithm/integrator_indirect.slangh b/src/dxvk/shaders/rtx/algorithm/integrator_indirect.slangh index 3bdc04635..5282a93c3 100644 --- a/src/dxvk/shaders/rtx/algorithm/integrator_indirect.slangh +++ b/src/dxvk/shaders/rtx/algorithm/integrator_indirect.slangh @@ -263,8 +263,9 @@ void integratePathVertex( RayInteraction rayInteraction; Surface surface; SurfaceInteraction surfaceInteraction; - surfaceInteraction.position = pathState.origin; PolymorphicSurfaceMaterialInteraction polymorphicSurfaceMaterialInteraction; + + surfaceInteraction.position = pathState.origin; // Todo: Remove hack thing HackGenericState hackState; diff --git a/src/dxvk/shaders/rtx/algorithm/nee_cache_light.slangh b/src/dxvk/shaders/rtx/algorithm/nee_cache_light.slangh index 9655485da..14275501f 100644 --- a/src/dxvk/shaders/rtx/algorithm/nee_cache_light.slangh +++ b/src/dxvk/shaders/rtx/algorithm/nee_cache_light.slangh @@ -100,8 +100,7 @@ struct NEECacheUtils static Surface getSurface(int surfaceIndex) { - SURFACE_CREATE_READ(surface0, surfaceIndex, surfaces); - Surface surface = surface0; + Surface surface = surfaces[uint(surfaceIndex)]; #if USE_SIMIPLIFIED_MODEL // Don't override following settings because they may affect some emissive objects // surface.isEmissive = false; @@ -296,8 +295,7 @@ struct NEECacheUtils static void calculateTriangleLightIntensity(int surfaceIndex, int primitiveIndex, out vec3 triangleCenter, out f16vec3 triangleNormal, out vec3 lightIntensity) { - SURFACE_CREATE_READ(surface0, surfaceIndex, surfaces); - Surface surface = surface0; + const Surface surface = surfaces[uint(surfaceIndex)]; RayInteraction rayInteracton = {}; rayInteracton.frontHit = true; rayInteracton.barycentricCoordinates = barycentricsToUint(uvToBarycentrics(vec2(1.0 / 3.0))); diff --git a/src/dxvk/shaders/rtx/algorithm/resolve.slangh b/src/dxvk/shaders/rtx/algorithm/resolve.slangh index 034460bda..3c17d395a 100644 --- a/src/dxvk/shaders/rtx/algorithm/resolve.slangh +++ b/src/dxvk/shaders/rtx/algorithm/resolve.slangh @@ -25,7 +25,6 @@ #include "rtx/algorithm/resolve.h" #include "rtx/utility/common.slangh" #include "rtx/utility/math.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/utility/packing.slangh" #include "rtx/utility/froxel.slangh" #include "rtx/concept/ray/ray.slangh" @@ -354,9 +353,8 @@ void resolveVertex( // Create a Surface and Surface Interaction from the hit - SURFACE_CREATE_READ(tempSurface, rayInteraction.surfaceIndex, surfaces); + surface = surfaces[uint(rayInteraction.surfaceIndex)]; - surface = tempSurface; surfaceInteraction = surfaceInteractionCreate(surface, rayInteraction, ray); // Process user clip planes and view distance @@ -942,7 +940,7 @@ void resolveVertexUnordered( surfaceInteraction.vertexColor = vertexColor; } - SURFACE_CREATE_READ(surface, rayInteraction.surfaceIndex, surfaces); + const Surface surface = surfaces[uint(rayInteraction.surfaceIndex)]; if (isTriangle) surfaceInteraction = surfaceInteractionCreate(surface, rayInteraction, ray); diff --git a/src/dxvk/shaders/rtx/algorithm/visibility.slangh b/src/dxvk/shaders/rtx/algorithm/visibility.slangh index 597e0c3c8..fc45820f6 100644 --- a/src/dxvk/shaders/rtx/algorithm/visibility.slangh +++ b/src/dxvk/shaders/rtx/algorithm/visibility.slangh @@ -55,7 +55,7 @@ f16vec3 handleVisibilityVertex(Ray ray, RayHitInfo rayHitInfo, uint8_t visibilit return 1.0; } - SURFACE_CREATE_READ(surface, surfaceIndex, surfaces); + const Surface surface = surfaces[uint(surfaceIndex)]; if (surfaceIsDecal(surface)) // Decals do not cast shadows @@ -189,12 +189,12 @@ float16_t getRayPortalTransparency( // Also note that this does not set up texture gradients properly so this will always likely sample from the lowest mip level // which is also probably not great for performance. - Surface surface; + Surface surface = (Surface)0; surface.spriteSheetRows = portal.spriteSheetRows; surface.spriteSheetCols = portal.spriteSheetCols; surface.spriteSheetFPS = portal.spriteSheetFPS; - SurfaceInteraction surfaceInteraction; + SurfaceInteraction surfaceInteraction = (SurfaceInteraction)0; surfaceInteraction.textureCoordinates = uv * 0.5f + 0.5f; surfaceInteraction.textureGradientX = vec2(0.0f); surfaceInteraction.textureGradientY = vec2(0.0f); diff --git a/src/dxvk/shaders/rtx/concept/surface/surface.h b/src/dxvk/shaders/rtx/concept/surface/surface.h index 4d21cd008..c7f85a32c 100644 --- a/src/dxvk/shaders/rtx/concept/surface/surface.h +++ b/src/dxvk/shaders/rtx/concept/surface/surface.h @@ -22,113 +22,445 @@ #pragma once #include "surface_shared.h" +#include "rtx/utility/packing.slangh" -struct MemorySurface +struct Surface { // Note: Currently aligned nicely to 256 bytes, avoid changing the size of this structure (as it will require // more 128 byte cachelines to be brought in for a single Surface read). + u16vec4 data0a; + u16vec4 data0b; + uint4 data1; + uint4 data2; + uint4 data3; + uint4 data4; + uint4 data5; + uint4 data6; + uint4 data7; + uint4 data8; + uint4 data9; + uint4 data10; + uint4 data11; + uint4 data12; + uint4 data13; + uint4 data14; + uint4 data15; - uvec4 data0; - uvec4 data1; - uvec4 data2; - uvec4 data3; - uvec4 data4; - uvec4 data5; - uvec4 data6; - uvec4 data7; - uvec4 data8; - uvec4 data9; - uvec4 data10; - uvec4 data11; - uvec4 data12; - uvec4 data13; - uvec4 data14; - uvec4 data15; -}; - -struct Surface -{ - uint16_t positionBufferIndex; - uint16_t previousPositionBufferIndex; - uint positionOffset; - // Note: Position stride between current and previous position buffer - uint8_t positionStride; + // flags and properties - uint16_t normalBufferIndex; - uint normalOffset; - uint8_t normalStride; + // Note: Potentially temporary flag for "fullbright" rendered things (e.g. the skybox) which should appear emissive-like. + // This may be able to be determined by some sort of fixed function state in the future, but for now this flag can be used. + property bool isEmissive + { + get { return packedFlagGet(data2.w, 1 << 0); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 0) : packedFlagUnset(data2.w, 1 << 0); } + } - uint16_t texcoordBufferIndex; - uint texcoordOffset; - uint8_t texcoordStride; + // Note: Indicates that there are no opacity-related blend modes (or translucency) on the associated Surface Material. + // This allows for optimizations in hit logic by being able to early out before expensive material decoding is done. + property bool isFullyOpaque + { + get { return packedFlagGet(data2.w, 1 << 1); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 1) : packedFlagUnset(data2.w, 1 << 1); } + } - uint16_t indexBufferIndex; - uint firstIndex; - uint8_t indexStride; + property bool isStatic + { + get { return packedFlagGet(data2.w, 1 << 2); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 2) : packedFlagUnset(data2.w, 1 << 2); } + } - uint16_t color0BufferIndex; - uint color0Offset; - uint8_t color0Stride; + property bool invertedBlend + { + get { return packedFlagGet(data2.w, 1 << 18); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 18) : packedFlagUnset(data2.w, 1 << 18); } + } - uint16_t surfaceMaterialIndex; + property bool isBlendingDisabled + { + get { return packedFlagGet(data2.w, 1 << 19); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 19) : packedFlagUnset(data2.w, 1 << 19); } + } - // Note: Potentially temporary flag for "fullbright" rendered things (e.g. the skybox) which should appear emissive-like. - // This may be able to be determined by some sort of fixed function state in the future, but for now this flag can be used. - bool isEmissive; - // Note: Indicates that there are no opacity-related blend modes (or translucency) on the associated Surface Material. - // This allows for optimizations in hit logic by being able to early out before expensive material decoding is done. - bool isFullyOpaque; - bool isStatic; - uint8_t alphaTestType; - float16_t alphaTestReferenceValue; - uint8_t blendType; - bool invertedBlend; - uint8_t textureColorArg1Source; - uint8_t textureColorArg2Source; - uint8_t textureColorOperation; - uint8_t textureAlphaArg1Source; - uint8_t textureAlphaArg2Source; - uint8_t textureAlphaOperation; - uint8_t texcoordGenerationMode; - uint16_t hashPacked; - uint32_t tFactor; - bool isBlendingDisabled; // Note: Not to be confused with isEmissive, this flag indicates that an emissive blend mode is in use. This can be // calculated on the GPU if needed but since space is currently available in the MemorySurface struct it is fine to precompute. - bool isEmissiveBlend; - bool isParticle; - bool isDecal; - bool isAnimatedWater; - bool isClipPlaneEnabled; - bool isMatte; - bool isTextureFactorBlend; - bool isMotionBlurMaskOut; + property bool isEmissiveBlend + { + get { return packedFlagGet(data2.w, 1 << 20); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 20) : packedFlagUnset(data2.w, 1 << 20); } + } + + property bool isParticle + { + get { return packedFlagGet(data2.w, 1 << 21); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 21) : packedFlagUnset(data2.w, 1 << 21); } + } + + property bool isDecal + { + get { return packedFlagGet(data2.w, 1 << 22); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 22) : packedFlagUnset(data2.w, 1 << 22); } + } + + property bool isAnimatedWater + { + get { return packedFlagGet(data2.w, 1 << 24); } + set { data2.w = newValue ? packedFlagSet(data2.w,1 << 24) : packedFlagUnset(data2.w, 1 << 24); } + } + + property bool isClipPlaneEnabled + { + get { return packedFlagGet(data2.w, 1 << 25); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 25) : packedFlagUnset(data2.w, 1 << 25); } + } + + property bool isMatte + { + get { return packedFlagGet(data2.w, 1 << 26); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 26) : packedFlagUnset(data2.w, 1 << 26); } + } + + property bool isTextureFactorBlend + { + get { return packedFlagGet(data2.w, 1 << 27); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 27) : packedFlagUnset(data2.w, 1 << 27); } + } + + property bool isMotionBlurMaskOut + { + get { return packedFlagGet(data2.w, 1 << 28); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 28) : packedFlagUnset(data2.w, 1 << 28); } + } + // Note: A flag to indicate that spritesheet adjustment shouldn't be done in the Surface Interaction, typically // because it will be done elsewhere for another reason (e.g. for the Ray Portal case where it is done in the Surface // Material Interaction instead). - bool skipSurfaceInteractionSpritesheetAdjustment; - bool isInsideFrustum; + property bool skipSurfaceInteractionSpritesheetAdjustment + { + get { return packedFlagGet(data2.w, 1 << 29); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 29) : packedFlagUnset(data2.w, 1 << 29); } + } + + property bool isInsideFrustum + { + get { return packedFlagGet(data2.w, 1 << 30); } + set { data2.w = newValue ? packedFlagSet(data2.w, 1 << 30) : packedFlagUnset(data2.w, 1 << 30); } + } + + // Matrices + + property mat4x3 prevObjectToWorld + { + get + { + const vec4 m0 = asfloat(data3); + const vec4 m1 = asfloat(data4); + const vec4 m2 = asfloat(data5); + return transpose(mat3x4( + m0.xyz, + vec3(m0.w, m1.xy), + vec3(m1.zw, m2.x), + m2.yzw)); + } + set + { + mat3x4 transposed = transpose(newValue); + data3 = asuint(vec4(transposed[0], transposed[1].x)); + data4 = asuint(vec4(transposed[1].yz, transposed[2].xy)); + data5 = asuint(vec4(transposed[2].z, transposed[3])); + } + } + + property mat3x3 normalObjectToWorld + { + get + { + const vec4 m0 = asfloat(data6); + const vec4 m1 = asfloat(data7); + const float m2 = asfloat(data13.w); + return transpose(mat3x3( + m0.xyz, + vec3(m0.w, m1.xy), + vec3(m1.zw, m2))); + } + set + { + mat3x3 transposed = transpose(newValue); + data6 = asuint(vec4(transposed[0], transposed[1].x)); + data7 = asuint(vec4(transposed[1].yz, transposed[2].xy)); + data13.w = asuint(transposed[2].z); + } + } + + property mat4x3 objectToWorld + { + get + { + const vec4 m0 = asfloat(data8); + const vec4 m1 = asfloat(data9); + const vec4 m2 = asfloat(data10); + return transpose(mat3x4( + m0.xyz, + vec3(m0.w, m1.xy), + vec3(m1.zw, m2.x), + m2.yzw)); + } + set + { + mat3x4 transposed = transpose(newValue); + data8 = asuint(vec4(transposed[0], transposed[1].x)); + data9 = asuint(vec4(transposed[1].yz, transposed[2].xy)); + data10 = asuint(vec4(transposed[2].z, transposed[3])); + } + } - mat4x3 objectToWorld; - mat4x3 prevObjectToWorld; - mat3x3 normalObjectToWorld; // Note: This is only a 4x2 matrix as currently our texture transform implementation only supports <= 2 elements, so the 3rd and 4th // elements this matrix may generate are currently never used (nor is the perspective division when projection is enabled, though this may // justify increasing this to a 4x3 matrix in the future for things projecting 3D coordinates down to 2D coordinates as this should be doable // to support). - mat4x2 textureTransform; + property mat4x2 textureTransform + { + get + { + const vec4 m0 = asfloat(data11); + const vec4 m1 = asfloat(data12); + return mat4x2(m0, m1); + } + set + { + data11 = asuint(newValue[0]); + data12 = asuint(newValue[1]); + } + } + + // Buffers + + property uint16_t positionBufferIndex + { + get { return data0a.x; } + set { data0a.x = newValue; } + } + + property uint16_t previousPositionBufferIndex + { + get { return data0a.y; } + set { data0a.y = newValue; } + } + + property uint16_t normalBufferIndex + { + get { return data0a.z; } + set { data0a.z = newValue; } + } + + property uint16_t texcoordBufferIndex + { + get { return data0a.w; } + set { data0a.w = newValue; } + } + + property uint16_t indexBufferIndex + { + get { return data0b.x; } + set { data0b.x = newValue; } + } + + property uint16_t color0BufferIndex + { + get { return data0b.y; } + set { data0b.y = newValue; } + } + + property uint16_t surfaceMaterialIndex + { + get { return data0b.z; } + set { data0b.z = newValue; } + } + + property uint16_t hashPacked + { + get { return data0b.w; } + set { data0b.w = newValue; } + } + + property uint positionOffset + { + get { return data1.x; } + set { data1.x = newValue; } + } + + property uint normalOffset + { + get { return data1.y; } + set { data1.y = newValue; } + } + + property uint texcoordOffset + { + get { return data1.z; } + set { data1.z = newValue; } + } + + property uint color0Offset + { + get { return data1.w; } + set { data1.w = newValue; } + } + + // Note: Position stride between current and previous position buffer + property uint8_t positionStride + { + get { return (uint8_t)(data2.y & 0xFF); } + set { data2.y = (data2.y & 0xFFFFFF00) | uint32_t(newValue & 0xFF); } + } + + property uint8_t normalStride + { + get { return (uint8_t) (data2.y >> 8) & 0xFF; } + set { data2.y = (data2.y & 0xFFFF00FF) | (uint32_t(newValue & 0xFF) << 8); } + } + + property uint8_t texcoordStride + { + get { return (uint8_t) (data2.y >> 16) & 0xFF; } + set { data2.y = (data2.y & 0xFF00FFFF) | (uint32_t(newValue & 0xFF) << 16); } + } + + property uint8_t color0Stride + { + get { return (uint8_t) (data2.y >> 24) & 0xFF; } + set { data2.y = (data2.y & 0x00FFFFFF) | (uint32_t(newValue & 0xFF) << 24); } + } + + property uint firstIndex + { + get { return (data2.z & 0xFFFFFF); } + set { data2.z = (data2.z & 0xFF000000) | (newValue & 0xFFFFFF); } + } + + property uint8_t indexStride + { + get { return (uint8_t) (data2.z >> 24) & 0xFF; } + set { data2.z = (data2.z & 0x00FFFFFF) | (uint32_t(newValue & 0xFF) << 24); } + } + + // Sprite sheets + + property uint8_t spriteSheetRows + { + get { return uint8_t(data13.x & 0xFF); } + set { data13.x = (data13.x & ~(0xFF << 0)) | uint32_t(newValue & 0xFF) << 0; } + } + + property uint8_t spriteSheetCols + { + get { return uint8_t((data13.x >> 8) & 0xFF); } + set { data13.x = (data13.x & ~(0xFF << 8)) | uint32_t(newValue & 0xFF) << 8; } + } + + property uint8_t spriteSheetFPS + { + get { return uint8_t((data13.x >> 16) & 0xFF); } + set { data13.x = (data13.x & ~(0xFF << 16)) | uint32_t(newValue & 0xFF) << 16; } + } + + // Fixed function + + property uint8_t alphaTestType + { + get { return uint8_t((data2.w >> 3) & alphaTestTypeMask); } + set { data2.w = (data2.w & ~(alphaTestTypeMask << 3)) | ((newValue & alphaTestTypeMask) << 3); } + } + + property float16_t alphaTestReferenceValue + { + get { return float16_t((uint8_t) ((data2.w >> 6) & 0xFFu)) / float16_t(0xFFu); } + set + { + uint8_t v = uint8_t(float(newValue) * 0xFF); + data2.w = (data2.w & ~(0xFF << 6)) | (v << 6); + } + } + + property uint8_t blendType + { + get { return uint8_t((data2.w >> 14) & surfaceBlendTypeMask); } + set { data2.w = (data2.w & ~(surfaceBlendTypeMask << 14)) | (uint32_t(newValue & surfaceBlendTypeMask) << 14); } + } + + property uint8_t textureColorArg1Source + { + get { return uint8_t(data13.z & 0x3); } + set { data13.z = (data13.z & ~0x3) | uint32_t(newValue & 0x3); } + } + + property uint8_t textureColorArg2Source + { + get { return uint8_t((data13.z >> 2) & 0x3); } + set { data13.z = (data13.z & ~(0x3 << 2)) | (uint32_t(newValue & 0x3) << 2); } + } + + property uint8_t textureColorOperation + { + get { return uint8_t((data13.z >> 4) & 0x7); } + set { data13.z = (data13.z & ~(0x7 << 4)) | (uint32_t(newValue & 0x7) << 4); } + } + + property uint8_t textureAlphaArg1Source + { + get { return uint8_t((data13.z >> 7) & 0x3); } + set { data13.z = (data13.z & ~(0x3 << 7)) | (uint32_t(newValue & 0x3) << 7); } + } + + property uint8_t textureAlphaArg2Source + { + get { return uint8_t((data13.z >> 9) & 0x3); } + set { data13.z = (data13.z & ~(0x3 << 9)) | (uint32_t(newValue & 0x3) << 9); } + } + + property uint8_t textureAlphaOperation + { + get { return uint8_t((data13.z >> 11) & 0x7); } + set { data13.z = (data13.z & ~(0x7 << 11)) | (uint32_t(newValue & 0x7) << 11); } + } + + property uint8_t texcoordGenerationMode + { + get { return uint8_t((data13.z >> 17) & 0x3); } + set { data13.z = (data13.z & ~(0x3 << 17)) | (uint32_t(newValue & 0x3) << 17); } + } + + property uint tFactor + { + get { return data13.y; } + set { data13.y = newValue; } + } + + // Misc - vec4 clipPlane; + property vec4 clipPlane + { + get { return asfloat(data14); } + set { data14 = asuint(newValue); } + } - uint8_t spriteSheetRows; - uint8_t spriteSheetCols; - uint8_t spriteSheetFPS; + property uint8_t decalSortOrder + { + get { return uint8_t((data13.x >> 24) & 0xFF); } + set { data13.x = (data13.x & 0x00FFFFFF) | (uint32_t(newValue & 0xFF) << 24); } + } - uint32_t objectPickingValue; + property uint objectPickingValue + { + get { return data2.x; } + set { data2.x = newValue; } + } - uint8_t decalSortOrder; - - float displaceIn; + property float displaceIn + { + get { return uint16BitsToHalf(data15.x & 0xFFFF); } + set { data15.x = (data15.x & 0xFFFF0000) | (float16BitsToUint16(newValue) & 0xFFFF); } + } }; // Note: Minimal version of typical Surface Interaction for transmission across passes. diff --git a/src/dxvk/shaders/rtx/concept/surface/surface.slangh b/src/dxvk/shaders/rtx/concept/surface/surface.slangh index 1b0d79821..c1bcc3b3a 100644 --- a/src/dxvk/shaders/rtx/concept/surface/surface.slangh +++ b/src/dxvk/shaders/rtx/concept/surface/surface.slangh @@ -29,7 +29,6 @@ #include "rtx/concept/surface/surface_interaction.slangh" #include "rtx/concept/surface/gbuffer_memory_minimal_surface_interaction.slangh" #include "rtx/concept/surface/minimal_surface_interaction.slangh" -#include "rtx/concept/surface/surface_create.slangh" bool surfaceIsDecal(Surface surface) { diff --git a/src/dxvk/shaders/rtx/concept/surface/surface_create.slangh b/src/dxvk/shaders/rtx/concept/surface/surface_create.slangh deleted file mode 100644 index 1d34e3027..000000000 --- a/src/dxvk/shaders/rtx/concept/surface/surface_create.slangh +++ /dev/null @@ -1,156 +0,0 @@ -/* -* Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -// Note: surface.h must be first include to define required structures -#include "rtx/concept/surface/surface.h" -#include "rtx/utility/common.slangh" -#include "rtx/utility/packing.slangh" - -Surface surfaceCreate(MemorySurface memorySurface) -{ - // Decode the Surface from the packed memory representation - - Surface surface; - - const u16vec2 indexData0 = unpack16(memorySurface.data0.x); - const u16vec2 indexData1 = unpack16(memorySurface.data0.y); - const u16vec2 indexData2 = unpack16(memorySurface.data0.z); - const u16vec2 indexData3 = unpack16(memorySurface.data0.w); - - surface.positionBufferIndex = indexData0.x; - surface.previousPositionBufferIndex = indexData0.y; - surface.normalBufferIndex = indexData1.x; - surface.texcoordBufferIndex = indexData1.y; - surface.indexBufferIndex = indexData2.x; - surface.color0BufferIndex = indexData2.y; - surface.surfaceMaterialIndex = indexData3.x; - - surface.hashPacked = indexData3.y; - - // Offsets are 4 bytes, so no unpacking - surface.positionOffset = memorySurface.data1.x; - surface.normalOffset = memorySurface.data1.z; - surface.texcoordOffset = memorySurface.data1.w; - surface.color0Offset = memorySurface.data2.x; - - surface.positionStride = uint8_t(memorySurface.data2.y); - surface.normalStride = uint8_t(memorySurface.data2.y >> 8u); - surface.texcoordStride = uint8_t(memorySurface.data2.y >> 16u); - surface.color0Stride = uint8_t(memorySurface.data2.y >> 24u); - - surface.firstIndex = memorySurface.data2.z & 0xFFFFFFu; - surface.indexStride = uint8_t(memorySurface.data2.z >> 24u); - - const uint32_t flagData = memorySurface.data2.w; - - surface.isEmissive = (flagData & (1u << 0)) != 0u; - surface.isFullyOpaque = (flagData & (1u << 1)) != 0u; - surface.isStatic = (flagData & (1u << 2)) != 0u; - surface.alphaTestType = uint8_t((flagData >> 3) & alphaTestTypeMask); - // Note: Explicit calculation done rather than using usual unorm decoding function to be exact with the - // way alpha is meant to be interpreted as a floating point value. - surface.alphaTestReferenceValue = float16_t(uint8_t((flagData >> 6) & 0xFFu)) / float16_t(0xFFu); - surface.blendType = uint8_t((flagData >> 14) & surfaceBlendTypeMask); - surface.invertedBlend = (flagData & (1u << 18)) != 0u; - surface.isBlendingDisabled = (flagData & (1u << 19)) != 0u; - surface.isEmissiveBlend = (flagData & (1u << 20)) != 0u; - surface.isParticle = (flagData & (1u << 21)) != 0u; - surface.isDecal = (flagData & (1u << 22)) != 0u; - // 23rd bit is available - surface.isAnimatedWater = (flagData & (1u << 24)) != 0u; - surface.isClipPlaneEnabled = (flagData & (1u << 25)) != 0u; - surface.isMatte = (flagData & (1u << 26)) != 0u; - surface.isTextureFactorBlend = (flagData & (1u << 27)) != 0u; - surface.isMotionBlurMaskOut = (flagData & (1u << 28)) != 0u; - surface.skipSurfaceInteractionSpritesheetAdjustment = (flagData & (1u << 29)) != 0u; - surface.isInsideFrustum = (flagData & (1u << 30)) != 0u; - // Note: Still a few bits empty here in the flag data reserved mostly for future flags. - - const vec4 prevObjectToWorldData0 = uintBitsToFloat(memorySurface.data3); - const vec4 prevObjectToWorldData1 = uintBitsToFloat(memorySurface.data4); - const vec4 prevObjectToWorldData2 = uintBitsToFloat(memorySurface.data5); - - surface.prevObjectToWorld = transpose(mat3x4( - prevObjectToWorldData0.xyz, - vec3(prevObjectToWorldData0.w, prevObjectToWorldData1.xy), - vec3(prevObjectToWorldData1.zw, prevObjectToWorldData2.x), - prevObjectToWorldData2.yzw)); - - const vec4 normalObjectToWorldData0 = uintBitsToFloat(memorySurface.data6); - const vec4 normalObjectToWorldData1 = uintBitsToFloat(memorySurface.data7); - const float normalObjectToWorldData2 = uintBitsToFloat(memorySurface.data13.w); - - surface.normalObjectToWorld = transpose(mat3x3( - normalObjectToWorldData0.xyz, - vec3(normalObjectToWorldData0.w, normalObjectToWorldData1.xy), - vec3(normalObjectToWorldData1.zw, normalObjectToWorldData2))); - - const vec4 objectToWorldData0 = uintBitsToFloat(memorySurface.data8); - const vec4 objectToWorldData1 = uintBitsToFloat(memorySurface.data9); - const vec4 objectToWorldData2 = uintBitsToFloat(memorySurface.data10); - - surface.objectToWorld = transpose(mat3x4( - objectToWorldData0.xyz, - vec3(objectToWorldData0.w, objectToWorldData1.xy), - vec3(objectToWorldData1.zw, objectToWorldData2.x), - objectToWorldData2.yzw)); - - const vec4 textureTransformData0 = uintBitsToFloat(memorySurface.data11); - const vec4 textureTransformData1 = uintBitsToFloat(memorySurface.data12); - - // Note: 4 columns and 2 rows, initialized row by row though because this is really an alias for a Slang - // row-major matrix... - surface.textureTransform = mat4x2( - textureTransformData0, - textureTransformData1); - - const uint32_t textureSpritesheetData = memorySurface.data13.x; - - surface.spriteSheetRows = uint8_t((textureSpritesheetData >> 0) & 0xFF); - surface.spriteSheetCols = uint8_t((textureSpritesheetData >> 8) & 0xFF); - surface.spriteSheetFPS = uint8_t((textureSpritesheetData >> 16) & 0xFF); - surface.decalSortOrder = uint8_t((textureSpritesheetData >> 24) & 0xFF); - - surface.tFactor = memorySurface.data13.y; - - const uint32_t textureFlagData = memorySurface.data13.z; - - surface.textureColorArg1Source = uint8_t((textureFlagData ) & 0x3); - surface.textureColorArg2Source = uint8_t((textureFlagData >> 2) & 0x3); - surface.textureColorOperation = uint8_t((textureFlagData >> 4) & 0x7); - surface.textureAlphaArg1Source = uint8_t((textureFlagData >> 7) & 0x3); - surface.textureAlphaArg2Source = uint8_t((textureFlagData >> 9) & 0x3); - surface.textureAlphaOperation = uint8_t((textureFlagData >> 11) & 0x7); - surface.texcoordGenerationMode = uint8_t((textureFlagData >> 17) & 0x3); - // Note: Still a few bits empty here in the texture flag data. - - surface.clipPlane = uintBitsToFloat(memorySurface.data14); - - surface.displaceIn = uint16BitsToHalf(memorySurface.data15.x); - // Note: second half of data15.x are free here. - // Note: data15 y, z, and w are free here. - - surface.objectPickingValue = memorySurface.data1.y; - - return surface; -} diff --git a/src/dxvk/shaders/rtx/pass/common_bindings.slangh b/src/dxvk/shaders/rtx/pass/common_bindings.slangh index 93bc4efc9..93805254f 100644 --- a/src/dxvk/shaders/rtx/pass/common_bindings.slangh +++ b/src/dxvk/shaders/rtx/pass/common_bindings.slangh @@ -65,7 +65,7 @@ layout(binding = BINDING_ACCELERATION_STRUCTURE_UNORDERED) RaytracingAccelerationStructure unorderedTLAS; layout(binding = BINDING_SURFACE_DATA_BUFFER) -StructuredBuffer surfaces; +StructuredBuffer surfaces; layout(binding = BINDING_SURFACE_MAPPING_BUFFER) StructuredBuffer surfaceMapping; diff --git a/src/dxvk/shaders/rtx/pass/integrate/integrate_direct.slangh b/src/dxvk/shaders/rtx/pass/integrate/integrate_direct.slangh index 956ab205f..0095ac352 100644 --- a/src/dxvk/shaders/rtx/pass/integrate/integrate_direct.slangh +++ b/src/dxvk/shaders/rtx/pass/integrate/integrate_direct.slangh @@ -24,7 +24,6 @@ #include "rtx/utility/common.slangh" #include "rtx/utility/noise.slangh" #include "rtx/utility/math.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/utility/gbuffer_helpers.slangh" #include "rtx/concept/ray/ray.slangh" #include "rtx/concept/surface/surface.slangh" diff --git a/src/dxvk/shaders/rtx/pass/integrate/integrate_indirect.slangh b/src/dxvk/shaders/rtx/pass/integrate/integrate_indirect.slangh index fd0ad05ec..f00ecfc2f 100644 --- a/src/dxvk/shaders/rtx/pass/integrate/integrate_indirect.slangh +++ b/src/dxvk/shaders/rtx/pass/integrate/integrate_indirect.slangh @@ -24,7 +24,6 @@ #include "rtx/utility/common.slangh" #include "rtx/utility/noise.slangh" #include "rtx/utility/math.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/utility/gbuffer_helpers.slangh" #include "rtx/concept/ray/ray.slangh" #include "rtx/concept/surface/surface.slangh" diff --git a/src/dxvk/shaders/rtx/pass/nee_cache/update_nee_cache.comp.slang b/src/dxvk/shaders/rtx/pass/nee_cache/update_nee_cache.comp.slang index 033c66eff..1fc9cd55e 100644 --- a/src/dxvk/shaders/rtx/pass/nee_cache/update_nee_cache.comp.slang +++ b/src/dxvk/shaders/rtx/pass/nee_cache/update_nee_cache.comp.slang @@ -32,7 +32,6 @@ #include "rtx/utility/geometry_flags.slangh" #include "rtx/utility/demodulate_helpers.slangh" #include "rtx/utility/debug_view_helpers.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/concept/camera/camera.slangh" #include "rtx/concept/ray/ray.slangh" #include "rtx/concept/ray/ray_helper.slangh" diff --git a/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap.comp.slang b/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap.comp.slang index 6ef70e385..23ecb59c7 100644 --- a/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap.comp.slang +++ b/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap.comp.slang @@ -50,7 +50,7 @@ layout(binding = BINDING_BAKE_OPACITY_MICROMAP_SECONDARY_OPACITY_INPUT) Sampler2D SecondaryOpacity; layout(binding = BINDING_BAKE_OPACITY_MICROMAP_BINDING_SURFACE_DATA_INPUT) -StructuredBuffer Surfaces; +StructuredBuffer Surfaces; layout(binding = BINDING_BAKE_OPACITY_MICROMAP_ARRAY_OUTPUT) RWStructuredBuffer OpacityMicromapArray; @@ -327,7 +327,7 @@ void main(uint globalId: SV_DispatchThreadID, uint groupId : SV_GroupID, uint th if (globalId < cb.numActiveThreads) { - SURFACE_CREATE_READ(surface, cb.surfaceIndex, Surfaces); + const Surface surface = Surfaces[uint(cb.surfaceIndex)]; float2 vertexTexcoords[3]; float16_t vertexOpacities[3]; diff --git a/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap_rtx_dependencies.slangh b/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap_rtx_dependencies.slangh index 1d23f39ae..47b30705b 100644 --- a/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap_rtx_dependencies.slangh +++ b/src/dxvk/shaders/rtx/pass/opacity_micromap/bake_opacity_micromap_rtx_dependencies.slangh @@ -30,5 +30,4 @@ #include "rtx\concept\surface\surface.h" #include "rtx\utility\packing.slangh" #include "rtx\concept\surface_material\opaque_surface_material_blending.slangh" -#include "rtx\utility\buffer_helpers.slangh" #include "rtx\concept\surface_material\surface_material.h" diff --git a/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_spatial_reuse.comp.slang b/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_spatial_reuse.comp.slang index c2027d442..fd2b548b9 100644 --- a/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_spatial_reuse.comp.slang +++ b/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_spatial_reuse.comp.slang @@ -31,7 +31,6 @@ #include "rtx/utility/texture.slangh" #include "rtx/utility/sampling.slangh" #include "rtx/utility/packing.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/utility/debug_view_helpers.slangh" #include "rtx/concept/ray/ray.slangh" #include "rtx/concept/surface/surface.slangh" diff --git a/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_temporal_reuse.comp.slang b/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_temporal_reuse.comp.slang index 4d4c513a4..9a7f69364 100644 --- a/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_temporal_reuse.comp.slang +++ b/src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_temporal_reuse.comp.slang @@ -32,7 +32,6 @@ #include "rtx/utility/texture.slangh" #include "rtx/utility/sampling.slangh" #include "rtx/utility/packing.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/concept/ray/ray.slangh" #include "rtx/concept/surface/surface.slangh" #include "rtx/concept/surface_material/surface_material.slangh" diff --git a/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_spatial_reuse.comp.slang b/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_spatial_reuse.comp.slang index c22969514..e3a1dc43c 100644 --- a/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_spatial_reuse.comp.slang +++ b/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_spatial_reuse.comp.slang @@ -32,7 +32,6 @@ #include "rtx/utility/texture.slangh" #include "rtx/utility/sampling.slangh" #include "rtx/utility/packing.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/concept/ray/ray.slangh" #include "rtx/concept/surface/surface.slangh" #include "rtx/concept/surface_material/surface_material.slangh" diff --git a/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_temporal_reuse.comp.slang b/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_temporal_reuse.comp.slang index 0b69c796c..4181f896a 100644 --- a/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_temporal_reuse.comp.slang +++ b/src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_temporal_reuse.comp.slang @@ -33,7 +33,6 @@ #include "rtx/utility/texture.slangh" #include "rtx/utility/sampling.slangh" #include "rtx/utility/packing.slangh" -#include "rtx/utility/buffer_helpers.slangh" #include "rtx/concept/ray/ray.slangh" #include "rtx/concept/surface/surface.slangh" #include "rtx/concept/surface_material/surface_material.slangh" diff --git a/src/dxvk/shaders/rtx/utility/buffer_helpers.slangh b/src/dxvk/shaders/rtx/utility/buffer_helpers.slangh deleted file mode 100644 index 223fe9e8b..000000000 --- a/src/dxvk/shaders/rtx/utility/buffer_helpers.slangh +++ /dev/null @@ -1,29 +0,0 @@ -/* -* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -#include "rtx/concept/surface/surface_create.slangh" -#include "rtx/concept/surface_material/surface_material.h" - -#define SURFACE_CREATE_READ(variable, surfaceIndex, surfaceBuffer) \ -const MemorySurface variable ## MemorySurface = surfaceBuffer[uint(surfaceIndex)]; \ -const Surface variable = surfaceCreate(variable ## MemorySurface);