mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-17 19:23:51 +02:00
IES profile support and fixed numerous editor crashes.
This commit is contained in:
@@ -2469,9 +2469,12 @@ struct glRaytracingMeshMetadata_t
|
||||
float averageColor[4];
|
||||
};
|
||||
|
||||
static const uint32_t GL_RAYTRACING_MAX_IES_TEXTURES = 8;
|
||||
|
||||
struct glRaytracingLightingState_t
|
||||
{
|
||||
std::vector<glRaytracingLight_t> cpuLights;
|
||||
std::vector<glRaytracingLight_t> uploadLights;
|
||||
glRaytracingLightingConstants_t constants;
|
||||
|
||||
ComPtr<ID3D12DescriptorHeap> descriptorHeap;
|
||||
@@ -2522,6 +2525,9 @@ struct glRaytracingLightingState_t
|
||||
DXGI_FORMAT emissiveFormat;
|
||||
ID3D12Resource* specularTexture;
|
||||
DXGI_FORMAT specularFormat;
|
||||
uint32_t iesTextureIds[GL_RAYTRACING_MAX_IES_TEXTURES];
|
||||
ID3D12Resource* iesTextures[GL_RAYTRACING_MAX_IES_TEXTURES];
|
||||
DXGI_FORMAT iesFormats[GL_RAYTRACING_MAX_IES_TEXTURES];
|
||||
bool uploadToCurrentFrameResource;
|
||||
bool initialized;
|
||||
|
||||
@@ -2553,6 +2559,12 @@ struct glRaytracingLightingState_t
|
||||
emissiveFormat = DXGI_FORMAT_R16G16B16A16_FLOAT;
|
||||
specularTexture = nullptr;
|
||||
specularFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
for (uint32_t i = 0; i < GL_RAYTRACING_MAX_IES_TEXTURES; ++i)
|
||||
{
|
||||
iesTextureIds[i] = 0;
|
||||
iesTextures[i] = nullptr;
|
||||
iesFormats[i] = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
uploadToCurrentFrameResource = false;
|
||||
initialized = false;
|
||||
}
|
||||
@@ -2577,14 +2589,15 @@ enum glRaytracingLightingDescriptorIndex_t
|
||||
GLR_DESC_EMISSIVE_SRV = 11,
|
||||
GLR_DESC_SPECULAR_SRV = 12,
|
||||
GLR_DESC_MESH_METADATA_SRV = 13,
|
||||
GLR_DESC_PATHTRACE_UAV = 14,
|
||||
GLR_DESC_DENOISE_A_UAV = 15,
|
||||
GLR_DESC_DENOISE_B_UAV = 16,
|
||||
GLR_DESC_OUTPUT_UAV = 17,
|
||||
GLR_DESC_TEMPORAL_UAV = 18,
|
||||
GLR_DESC_HISTORY_UAV = 19,
|
||||
GLR_DESC_COUNT = 20,
|
||||
GLR_DESC_SRV_COUNT = 14,
|
||||
GLR_DESC_IES_TEXTURES_SRV = 14,
|
||||
GLR_DESC_PATHTRACE_UAV = GLR_DESC_IES_TEXTURES_SRV + GL_RAYTRACING_MAX_IES_TEXTURES,
|
||||
GLR_DESC_DENOISE_A_UAV = GLR_DESC_PATHTRACE_UAV + 1,
|
||||
GLR_DESC_DENOISE_B_UAV = GLR_DESC_PATHTRACE_UAV + 2,
|
||||
GLR_DESC_OUTPUT_UAV = GLR_DESC_PATHTRACE_UAV + 3,
|
||||
GLR_DESC_TEMPORAL_UAV = GLR_DESC_PATHTRACE_UAV + 4,
|
||||
GLR_DESC_HISTORY_UAV = GLR_DESC_PATHTRACE_UAV + 5,
|
||||
GLR_DESC_COUNT = GLR_DESC_PATHTRACE_UAV + 6,
|
||||
GLR_DESC_SRV_COUNT = 14 + GL_RAYTRACING_MAX_IES_TEXTURES,
|
||||
GLR_DESC_UAV_COUNT = 6
|
||||
};
|
||||
|
||||
@@ -2631,6 +2644,10 @@ struct Light
|
||||
// as the influence range for rect lights, and as the far clip distance for spot lights.
|
||||
float3 pointRadius;
|
||||
float pointRadiusPad; // non-zero disables specular for this light
|
||||
|
||||
uint iesTextureIndex; // 0 = none, 1..8 = gIesTextures index + 1
|
||||
float iesStrength;
|
||||
float2 iesPad;
|
||||
};
|
||||
|
||||
struct MeshMetadata
|
||||
@@ -2686,6 +2703,7 @@ RaytracingAccelerationStructure gSceneBVH : register(t5);
|
||||
Texture2D<float4> gEmissiveTex : register(t11);
|
||||
Texture2D<float4> gSpecularTex : register(t12);
|
||||
StructuredBuffer<MeshMetadata> gMeshMetadata : register(t13);
|
||||
Texture2D<float4> gIesTextures[8] : register(t14);
|
||||
RWTexture2D<float4> gOutputTex : register(u0);
|
||||
|
||||
static const uint GL_RAYTRACING_LIGHT_TYPE_POINT = 0;
|
||||
@@ -3143,6 +3161,60 @@ float Doom3ProjectionTexture2D(float2 centeredCoord)
|
||||
|
||||
return Doom3QuadraticCentered(centeredCoord.x) * Doom3QuadraticCentered(centeredCoord.y);
|
||||
}
|
||||
|
||||
int WrapIESHorizontalCoord(int x)
|
||||
{
|
||||
x = x % 512;
|
||||
return (x < 0) ? (x + 512) : x;
|
||||
}
|
||||
|
||||
float SampleIESTexture(Light Lgt, float3 lightToSurface)
|
||||
{
|
||||
if (Lgt.iesTextureIndex == 0u || Lgt.iesStrength <= 0.0)
|
||||
return 1.0;
|
||||
|
||||
float3 dir = Doom3SafeNormalizeOr(lightToSurface, Doom3SafeNormalizeOr(Lgt.normal, float3(0.0, 0.0, 1.0)));
|
||||
float3 axisW = Doom3SafeNormalizeOr(Lgt.normal, float3(0.0, 0.0, 1.0));
|
||||
float3 axisU = Doom3SafeNormalizeOr(Lgt.axisU, float3(1.0, 0.0, 0.0));
|
||||
float3 axisV = Doom3SafeNormalizeOr(Lgt.axisV, float3(0.0, 1.0, 0.0));
|
||||
|
||||
float localX = dot(dir, axisU);
|
||||
float localY = dot(dir, axisV);
|
||||
float localZ = dot(dir, axisW);
|
||||
|
||||
float horizontal = atan2(localY, localX) * (0.15915494309189535) + 0.5;
|
||||
float vertical = acos(clamp(localZ, -1.0, 1.0)) * (0.3183098861837907);
|
||||
|
||||
uint texIndex = min(Lgt.iesTextureIndex - 1u, 7u);
|
||||
float u = frac(horizontal) * 512.0 - 0.5;
|
||||
float v = saturate(vertical) * 256.0 - 0.5;
|
||||
int x0 = (int)floor(u);
|
||||
int y0 = (int)floor(v);
|
||||
float tx = frac(u);
|
||||
float ty = frac(v);
|
||||
int x1 = x0 + 1;
|
||||
int y1 = y0 + 1;
|
||||
|
||||
x0 = WrapIESHorizontalCoord(x0);
|
||||
x1 = WrapIESHorizontalCoord(x1);
|
||||
y0 = clamp(y0, 0, 255);
|
||||
y1 = clamp(y1, 0, 255);
|
||||
|
||||
float p00 = gIesTextures[texIndex].Load(int3(x0, y0, 0)).r;
|
||||
float p10 = gIesTextures[texIndex].Load(int3(x1, y0, 0)).r;
|
||||
float p01 = gIesTextures[texIndex].Load(int3(x0, y1, 0)).r;
|
||||
float p11 = gIesTextures[texIndex].Load(int3(x1, y1, 0)).r;
|
||||
float profile = lerp(lerp(p00, p10, tx), lerp(p01, p11, tx), ty);
|
||||
return lerp(1.0, profile, saturate(Lgt.iesStrength));
|
||||
}
|
||||
|
||||
float ApplyIESProfile(float attenuation, Light Lgt, float3 lightToSurface)
|
||||
{
|
||||
if (attenuation <= 0.0 || Lgt.iesTextureIndex == 0u || Lgt.iesStrength <= 0.0)
|
||||
return attenuation;
|
||||
|
||||
return attenuation * SampleIESTexture(Lgt, lightToSurface);
|
||||
}
|
||||
)"
|
||||
R"(
|
||||
float Doom3ProjectedDepthFalloff(float depth, float nearClip, float farClip)
|
||||
@@ -3192,6 +3264,15 @@ float ComputeSpotLightAttenuation(float3 worldPos, Light Lgt)
|
||||
|
||||
float depth = dot(lightToSurface, spotDir);
|
||||
|
||||
if (Lgt.iesTextureIndex != 0u && Lgt.iesStrength > 0.0)
|
||||
{
|
||||
if (depth <= 1e-4 || depth >= farClip)
|
||||
return 0.0;
|
||||
|
||||
float t = saturate(depth / max(farClip, 1e-4));
|
||||
return 1.0 - smoothstep(0.985, 1.0, t);
|
||||
}
|
||||
|
||||
if (depth <= nearClip || depth >= farClip)
|
||||
return 0.0;
|
||||
|
||||
@@ -4023,7 +4104,7 @@ float3 PathTraceDirectPointLight(uint2 pixel, float3 worldPos, float3 N, float3
|
||||
float3 tangent, bitangent;
|
||||
BuildOrthonormalBasis(centerDir, tangent, bitangent);
|
||||
|
||||
float atten = ComputePointLightAttenuation(worldPos, Lgt);
|
||||
float atten = ApplyIESProfile(ComputePointLightAttenuation(worldPos, Lgt), Lgt, worldPos - Lgt.position);
|
||||
if (atten <= 0.0)
|
||||
return 0.0;
|
||||
|
||||
@@ -4081,7 +4162,7 @@ float3 PathTraceDirectSpotLight(float3 worldPos, float3 N, float3 V, float3 base
|
||||
return 0.0;
|
||||
|
||||
float3 L = toLight / dist;
|
||||
float atten = ComputeSpotLightAttenuation(worldPos, Lgt);
|
||||
float atten = ApplyIESProfile(ComputeSpotLightAttenuation(worldPos, Lgt), Lgt, worldPos - Lgt.position);
|
||||
|
||||
float diffuseNoL = ComputeDiffuseLightingTerm(N, L);
|
||||
|
||||
@@ -5264,7 +5345,7 @@ void RayGen()
|
||||
reflectionRng);
|
||||
|
||||
float3 albedo = baseAlbedo * cavity;
|
||||
float3 finalColor = (albedo * (lightingAccum + float3(0.08, 0.08, 0.08))) + specularAccum + reflectedSpecular;
|
||||
float3 finalColor = (albedo * (lightingAccum)) + specularAccum + reflectedSpecular;
|
||||
|
||||
if (gMaxBounces > 1u)
|
||||
{
|
||||
@@ -6073,16 +6154,72 @@ static void glRaytracingLightingUpdateLights(void)
|
||||
if (g_glRaytracingLighting.cpuLights.empty())
|
||||
return;
|
||||
|
||||
const size_t bytes = g_glRaytracingLighting.cpuLights.size() * sizeof(glRaytracingLight_t);
|
||||
std::vector<glRaytracingLight_t>& uploadLights = g_glRaytracingLighting.uploadLights;
|
||||
uploadLights = g_glRaytracingLighting.cpuLights;
|
||||
|
||||
for (size_t i = 0; i < uploadLights.size(); ++i)
|
||||
{
|
||||
glRaytracingLight_t& light = uploadLights[i];
|
||||
const uint32_t textureId = light.iesTextureId;
|
||||
if (textureId == 0 || light.iesStrength <= 0.0f)
|
||||
{
|
||||
light.iesTextureId = 0;
|
||||
light.iesStrength = 0.0f;
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t slot = GL_RAYTRACING_MAX_IES_TEXTURES;
|
||||
for (uint32_t j = 0; j < GL_RAYTRACING_MAX_IES_TEXTURES; ++j)
|
||||
{
|
||||
if (g_glRaytracingLighting.iesTextureIds[j] == textureId)
|
||||
{
|
||||
slot = j;
|
||||
break;
|
||||
}
|
||||
if (g_glRaytracingLighting.iesTextureIds[j] == 0 && slot == GL_RAYTRACING_MAX_IES_TEXTURES)
|
||||
{
|
||||
slot = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (slot == GL_RAYTRACING_MAX_IES_TEXTURES)
|
||||
{
|
||||
light.iesTextureId = 0;
|
||||
light.iesStrength = 0.0f;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_glRaytracingLighting.iesTextureIds[slot] == 0)
|
||||
{
|
||||
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
UINT width = 0;
|
||||
UINT height = 0;
|
||||
ID3D12Resource* resource = QD3D12_GetTextureResource((GLuint)textureId, &format, &width, &height, g_glRaytracingCmd.cmdList.Get());
|
||||
if (!resource || width == 0 || height == 0)
|
||||
{
|
||||
light.iesTextureId = 0;
|
||||
light.iesStrength = 0.0f;
|
||||
continue;
|
||||
}
|
||||
|
||||
g_glRaytracingLighting.iesTextureIds[slot] = textureId;
|
||||
g_glRaytracingLighting.iesTextures[slot] = resource;
|
||||
g_glRaytracingLighting.iesFormats[slot] = format;
|
||||
}
|
||||
|
||||
light.iesTextureId = slot + 1;
|
||||
}
|
||||
|
||||
const size_t bytes = uploadLights.size() * sizeof(glRaytracingLight_t);
|
||||
if (g_glRaytracingLighting.lightBufferMapped)
|
||||
{
|
||||
memcpy(g_glRaytracingLighting.lightBufferMapped, g_glRaytracingLighting.cpuLights.data(), bytes);
|
||||
memcpy(g_glRaytracingLighting.lightBufferMapped, uploadLights.data(), bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
glRaytracingMapCopy(
|
||||
g_glRaytracingLighting.lightBuffer.resource.Get(),
|
||||
g_glRaytracingLighting.cpuLights.data(),
|
||||
uploadLights.data(),
|
||||
bytes);
|
||||
}
|
||||
|
||||
@@ -6622,6 +6759,21 @@ static void glRaytracingLightingCreatePerPassDescriptors(
|
||||
g_glRaytracingCmd.device->CreateShaderResourceView(specularResource, &specularSrv,
|
||||
glRaytracingOffsetCpu(base, g_glRaytracingLighting.descriptorStride, GLR_DESC_SPECULAR_SRV));
|
||||
|
||||
for (uint32_t i = 0; i < GL_RAYTRACING_MAX_IES_TEXTURES; ++i)
|
||||
{
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC iesSrv = {};
|
||||
iesSrv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
iesSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||
iesSrv.Format = g_glRaytracingLighting.iesTextures[i]
|
||||
? g_glRaytracingLighting.iesFormats[i]
|
||||
: DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
iesSrv.Texture2D.MipLevels = 1;
|
||||
g_glRaytracingCmd.device->CreateShaderResourceView(
|
||||
g_glRaytracingLighting.iesTextures[i],
|
||||
&iesSrv,
|
||||
glRaytracingOffsetCpu(base, g_glRaytracingLighting.descriptorStride, GLR_DESC_IES_TEXTURES_SRV + i));
|
||||
}
|
||||
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC rayOutputUav = {};
|
||||
rayOutputUav.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
|
||||
rayOutputUav.Format = GL_RAYTRACING_DENOISE_FORMAT;
|
||||
|
||||
@@ -373,6 +373,7 @@ void QD3D12_SetCameraInfo(
|
||||
static void QD3D12_CreateUploadRingForWindow(struct QD3D12Window& w);
|
||||
static void QD3D12_DestroyUploadRingForWindow(struct QD3D12Window& w);
|
||||
static void QD3D12_SubmitOpenFrameNoPresentAndWait();
|
||||
static void QD3D12_WaitForGPU();
|
||||
static void QD3D12_EnsureFrameOpen();
|
||||
static void QD3D12_RunUpscalerOrBlit(QD3D12Window& w);
|
||||
static void QD3D12_ExecuteMainCommandListAndWait(QD3D12Window& w);
|
||||
@@ -664,7 +665,7 @@ static void QD3D12_InvalidateTextureMipChain(TextureResource& tex, bool invalida
|
||||
static bool QD3D12_TextureHasNeuralPOMData(const TextureResource& tex);
|
||||
static bool QD3D12_UploadNeuralPOM(TextureResource& tex);
|
||||
static void EnsureTextureResource(TextureResource& tex);
|
||||
static void UploadTexture(TextureResource& tex);
|
||||
static void UploadTexture(TextureResource& tex, ID3D12GraphicsCommandList* commandList = nullptr);
|
||||
static UINT QD3D12_NeuralPOMFallbackSrvIndex();
|
||||
static void QD3D12_CreateNeuralPOMZeroBuffer();
|
||||
|
||||
@@ -1336,17 +1337,6 @@ struct QD3D12Window* AllocD3D12Window() {
|
||||
return new QD3D12Window();
|
||||
}
|
||||
|
||||
void FreeD3D12Window(struct QD3D12Window* wnd) {
|
||||
if (wnd)
|
||||
{
|
||||
QD3D12_DestroyUploadRingForWindow(*wnd);
|
||||
QD3D12_UnregisterWindowDC(wnd->hdc);
|
||||
if (wnd->ownsHdc && wnd->hwnd && wnd->hdc)
|
||||
ReleaseDC(wnd->hwnd, wnd->hdc);
|
||||
}
|
||||
delete wnd;
|
||||
}
|
||||
|
||||
struct ImmediateVertexBuffer
|
||||
{
|
||||
std::vector<GLVertex> storage;
|
||||
@@ -1514,7 +1504,7 @@ struct GLState
|
||||
bool enableRayAIDenoise = false;
|
||||
bool enableDLSSRayReconstruction = false;
|
||||
bool enableFSRRayRegeneration = false;
|
||||
uint32_t frameGenerationMultiplier = 2;
|
||||
uint32_t frameGenerationMultiplier = 0;
|
||||
uint32_t pathTracingSamplesPerPixel = 1;
|
||||
uint32_t pathTracingFallbackSamplesPerPixel = 2;
|
||||
uint32_t pathTracingMaxBounces = 2;
|
||||
@@ -1850,6 +1840,24 @@ static void QD3D12_MatrixMultiplyCM(const float* a, const float* b, float* out)
|
||||
memcpy(out, r, sizeof(r));
|
||||
}
|
||||
|
||||
void FreeD3D12Window(struct QD3D12Window* wnd) {
|
||||
if (wnd)
|
||||
{
|
||||
if ((g_gl.frameOpen && g_gl.frameOwner == wnd) || g_currentWindow == wnd)
|
||||
QD3D12_SubmitOpenFrameNoPresentAndWait();
|
||||
if (g_currentWindow == wnd)
|
||||
g_currentWindow = nullptr;
|
||||
if (g_gl.device && g_gl.queue && g_gl.fence)
|
||||
QD3D12_WaitForGPU();
|
||||
QD3D12_DestroyUploadRingForWindow(*wnd);
|
||||
QD3D12_UnregisterWindowDC(wnd->hdc);
|
||||
if (wnd->ownsHdc && wnd->hwnd && wnd->hdc)
|
||||
ReleaseDC(wnd->hwnd, wnd->hdc);
|
||||
}
|
||||
delete wnd;
|
||||
}
|
||||
|
||||
|
||||
static bool QD3D12_MatrixInvertCM(const float* m, float* out)
|
||||
{
|
||||
if (!QD3D12_MatrixFinite(m) || !out)
|
||||
@@ -2583,6 +2591,32 @@ static TextureResource* QD3D12_FindTextureResource(GLuint id)
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
ID3D12Resource* QD3D12_GetTextureResource(GLuint texture, DXGI_FORMAT* format, UINT* width, UINT* height, ID3D12GraphicsCommandList* commandList)
|
||||
{
|
||||
TextureResource* tex = QD3D12_FindTextureResource(texture);
|
||||
if (!tex)
|
||||
return nullptr;
|
||||
|
||||
EnsureTextureResource(*tex);
|
||||
if (!tex->texture)
|
||||
return nullptr;
|
||||
|
||||
if (!tex->gpuValid && commandList)
|
||||
UploadTexture(*tex, commandList);
|
||||
|
||||
if (!tex->gpuValid)
|
||||
return nullptr;
|
||||
|
||||
if (format)
|
||||
*format = tex->dxgiFormat;
|
||||
if (width)
|
||||
*width = (UINT)tex->width;
|
||||
if (height)
|
||||
*height = (UINT)tex->height;
|
||||
|
||||
return tex->texture.Get();
|
||||
}
|
||||
|
||||
static TextureResource& QD3D12_EnsureTextureName(GLuint id)
|
||||
{
|
||||
auto it = g_gl.textures.find(id);
|
||||
@@ -6842,6 +6876,11 @@ static float QD3D12_QualityRatio(QD3D12UpscalerQuality quality)
|
||||
}
|
||||
}
|
||||
|
||||
static bool QD3D12_IsEmbeddedEditorWindow(const QD3D12Window& w)
|
||||
{
|
||||
return w.hwnd && GetParent(w.hwnd) != nullptr;
|
||||
}
|
||||
|
||||
#if defined(QD3D12_ENABLE_STREAMLINE)
|
||||
struct QD3D12StreamlineState
|
||||
{
|
||||
@@ -7169,6 +7208,7 @@ static bool QD3D12_WantsDLSSRayReconstruction()
|
||||
static bool QD3D12_CanUseDLSSRayReconstructionForLighting(const QD3D12Window& w)
|
||||
{
|
||||
return !w.isPbuffer &&
|
||||
!QD3D12_IsEmbeddedEditorWindow(w) &&
|
||||
g_gl.cameraState.valid &&
|
||||
QD3D12_WantsDLSSRayReconstruction();
|
||||
}
|
||||
@@ -7255,6 +7295,7 @@ static bool QD3D12_WantsDLSSFrameGeneration(const QD3D12Window& w)
|
||||
{
|
||||
return
|
||||
!w.isPbuffer &&
|
||||
!QD3D12_IsEmbeddedEditorWindow(w) &&
|
||||
g_gl.cameraState.valid &&
|
||||
g_qd3d12Sl.deviceBound &&
|
||||
g_qd3d12Sl.dlssGSupported &&
|
||||
@@ -7271,6 +7312,8 @@ static uint32_t QD3D12_GetDLSSFrameGenerationEligibilityMask(const QD3D12Window&
|
||||
uint32_t mask = 0;
|
||||
if (w.isPbuffer)
|
||||
mask |= 1u << 0;
|
||||
if (QD3D12_IsEmbeddedEditorWindow(w))
|
||||
mask |= 1u << 8;
|
||||
if (!g_gl.cameraState.valid)
|
||||
mask |= 1u << 1;
|
||||
if (!g_qd3d12Sl.deviceBound)
|
||||
@@ -7301,9 +7344,10 @@ static void QD3D12_LogDLSSFrameGenerationEligibility(const QD3D12Window& w, uint
|
||||
}
|
||||
|
||||
QD3D12_Log(
|
||||
"DLSS_G inactive: r_frameGen=%u, pbuffer=%d, camera=%d, deviceBound=%d, dlssG=%d, reflex=%d, resources=%d.",
|
||||
"DLSS_G inactive: r_frameGen=%u, pbuffer=%d, embedded=%d, camera=%d, deviceBound=%d, dlssG=%d, reflex=%d, resources=%d.",
|
||||
g_gl.frameGenerationMultiplier,
|
||||
w.isPbuffer ? 1 : 0,
|
||||
QD3D12_IsEmbeddedEditorWindow(w) ? 1 : 0,
|
||||
g_gl.cameraState.valid ? 1 : 0,
|
||||
g_qd3d12Sl.deviceBound ? 1 : 0,
|
||||
(g_qd3d12Sl.dlssGSupported && g_qd3d12Sl.dlssGFeatureLoaded) ? 1 : 0,
|
||||
@@ -11466,11 +11510,15 @@ static void QD3D12_ProcessCompletedTextureMipJobs(UINT maxUploads)
|
||||
}
|
||||
}
|
||||
|
||||
static void UploadTexture(TextureResource& tex)
|
||||
static void UploadTexture(TextureResource& tex, ID3D12GraphicsCommandList* commandList)
|
||||
{
|
||||
if (!tex.texture)
|
||||
return;
|
||||
|
||||
ID3D12GraphicsCommandList* cl = commandList ? commandList : g_gl.cmdList.Get();
|
||||
if (!cl)
|
||||
return;
|
||||
|
||||
if (tex.compressed)
|
||||
{
|
||||
const UINT blockBytes = tex.compressedBlockBytes ? tex.compressedBlockBytes : QD3D12_CompressedTextureBlockBytes(tex.compressedInternalFormat);
|
||||
@@ -11513,7 +11561,7 @@ static void UploadTexture(TextureResource& tex)
|
||||
toCopy.Transition.StateBefore = tex.state;
|
||||
toCopy.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toCopy.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toCopy);
|
||||
cl->ResourceBarrier(1, &toCopy);
|
||||
tex.state = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
}
|
||||
|
||||
@@ -11532,17 +11580,17 @@ static void UploadTexture(TextureResource& tex)
|
||||
dstLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
dstLoc.SubresourceIndex = 0;
|
||||
|
||||
g_gl.cmdList->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
cl->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
|
||||
D3D12_RESOURCE_BARRIER toSrv{};
|
||||
toSrv.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
toSrv.Transition.pResource = tex.texture.Get();
|
||||
toSrv.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toSrv);
|
||||
cl->ResourceBarrier(1, &toSrv);
|
||||
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
tex.gpuValid = true;
|
||||
return;
|
||||
}
|
||||
@@ -11561,7 +11609,7 @@ static void UploadTexture(TextureResource& tex)
|
||||
toCopy.Transition.StateBefore = tex.state;
|
||||
toCopy.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toCopy.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toCopy);
|
||||
cl->ResourceBarrier(1, &toCopy);
|
||||
tex.state = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
}
|
||||
|
||||
@@ -11593,17 +11641,17 @@ static void UploadTexture(TextureResource& tex)
|
||||
dstLoc.pResource = tex.texture.Get();
|
||||
dstLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
dstLoc.SubresourceIndex = 0;
|
||||
g_gl.cmdList->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
cl->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
|
||||
D3D12_RESOURCE_BARRIER toSrv{};
|
||||
toSrv.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
toSrv.Transition.pResource = tex.texture.Get();
|
||||
toSrv.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toSrv);
|
||||
cl->ResourceBarrier(1, &toSrv);
|
||||
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
tex.gpuValid = true;
|
||||
|
||||
EnsureTextureResource(tex);
|
||||
@@ -12894,12 +12942,20 @@ void APIENTRY glFinish(void)
|
||||
if (!g_gl.device || !g_gl.queue || !g_gl.cmdList)
|
||||
return;
|
||||
|
||||
QD3D12Window* owner = g_gl.frameOwner ? g_gl.frameOwner : g_currentWindow;
|
||||
if (!owner)
|
||||
return;
|
||||
|
||||
if (!g_gl.frameOpen && g_gl.queuedBatches.empty())
|
||||
{
|
||||
QD3D12_WaitForGPU();
|
||||
if (!QD3D12_IsEmbeddedEditorWindow(*owner))
|
||||
QD3D12_WaitForGPU();
|
||||
return;
|
||||
}
|
||||
|
||||
QD3D12Window* savedWindow = g_currentWindow;
|
||||
g_currentWindow = owner;
|
||||
|
||||
QD3D12_EnsureFrameOpen();
|
||||
QD3D12_FlushQueuedBatches();
|
||||
|
||||
@@ -12917,16 +12973,17 @@ void APIENTRY glFinish(void)
|
||||
WaitForSingleObject(g_gl.fenceEvent, INFINITE);
|
||||
}
|
||||
|
||||
FrameResources& fr = g_currentWindow->frames[g_currentWindow->frameIndex];
|
||||
FrameResources& fr = owner->frames[owner->frameIndex];
|
||||
fr.fenceValue = signalValue;
|
||||
|
||||
QD3D12_CHECK(fr.cmdAlloc->Reset());
|
||||
QD3D12_CHECK(g_gl.cmdList->Reset(fr.cmdAlloc.Get(), nullptr));
|
||||
|
||||
QD3D12_BindTargetsForCurrentPhase(*g_currentWindow);
|
||||
QD3D12_BindTargetsForCurrentPhase(*owner);
|
||||
|
||||
g_gl.frameOpen = true;
|
||||
g_gl.frameOwner = g_currentWindow;
|
||||
g_gl.frameOwner = owner;
|
||||
g_currentWindow = savedWindow;
|
||||
}
|
||||
|
||||
void APIENTRY glMatrixMode(GLenum mode)
|
||||
@@ -14689,7 +14746,7 @@ void QD3D12_ReleaseWindowSizeResources(QD3D12Window& w)
|
||||
}
|
||||
void QD3D12_Resize()
|
||||
{
|
||||
if (!g_currentWindow)
|
||||
if (!g_currentWindow || !g_currentWindow->swapChain)
|
||||
return;
|
||||
|
||||
RECT rc{};
|
||||
@@ -14718,13 +14775,22 @@ void QD3D12_Resize()
|
||||
|
||||
QD3D12_ReleaseWindowSizeResources(*g_currentWindow);
|
||||
|
||||
QD3D12_CHECK(g_currentWindow->swapChain->ResizeBuffers(
|
||||
HRESULT resizeHr = g_currentWindow->swapChain->ResizeBuffers(
|
||||
QD3D12_FrameCount,
|
||||
width,
|
||||
height,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING
|
||||
));
|
||||
);
|
||||
if (FAILED(resizeHr))
|
||||
{
|
||||
QD3D12_Log("ResizeBuffers failed 0x%08X; recreating swapchain.", (unsigned)resizeHr);
|
||||
g_currentWindow->swapChain.Reset();
|
||||
g_currentWindow->width = width;
|
||||
g_currentWindow->height = height;
|
||||
QD3D12_SelectRenderResolution(*g_currentWindow, width, height);
|
||||
QD3D12_CreateSwapChainForWindow(*g_currentWindow);
|
||||
}
|
||||
|
||||
g_currentWindow->width = width;
|
||||
g_currentWindow->height = height;
|
||||
|
||||
@@ -101,6 +101,7 @@ BOOL WINAPI qd3d12_wglMakeCurrent(HDC hdc, QD3D12_HGLRC hglrc)
|
||||
|
||||
QD3D12FakeContext* ctx = (QD3D12FakeContext*)hglrc;
|
||||
ctx->dc = hdc;
|
||||
const bool wasInitialized = ctx->initialized;
|
||||
|
||||
|
||||
int w = 640, h = 480;
|
||||
@@ -126,16 +127,13 @@ BOOL WINAPI qd3d12_wglMakeCurrent(HDC hdc, QD3D12_HGLRC hglrc)
|
||||
QD3D12_BeginFrame();
|
||||
}
|
||||
|
||||
if (ctx->initialized) {
|
||||
// glFinish();
|
||||
QD3D12_EndFrame();
|
||||
}
|
||||
|
||||
g_currentDC = hdc;
|
||||
g_currentContext = ctx;
|
||||
|
||||
QD3D12_SetCurrentWindow(ctx->window);
|
||||
QD3D12_Resize();
|
||||
if (wasInitialized) {
|
||||
QD3D12_Resize();
|
||||
}
|
||||
|
||||
if (ctx->initialized) {
|
||||
QD3D12_BeginFrame();
|
||||
@@ -162,11 +160,14 @@ BOOL WINAPI qd3d12_wglDeleteContext(QD3D12_HGLRC hglrc)
|
||||
return FALSE;
|
||||
|
||||
QD3D12FakeContext* ctx = (QD3D12FakeContext*)hglrc;
|
||||
const bool embeddedWindow = ctx->hwnd && GetParent(ctx->hwnd) != NULL;
|
||||
|
||||
if (ctx == g_currentContext)
|
||||
{
|
||||
if (ctx->initialized)
|
||||
if (ctx->initialized && !embeddedWindow)
|
||||
QD3D12_ShutdownForQuake();
|
||||
else
|
||||
QD3D12_SetCurrentWindow(NULL);
|
||||
|
||||
g_currentContext = nullptr;
|
||||
g_currentDC = nullptr;
|
||||
@@ -205,4 +206,4 @@ BOOL WINAPI qd3d12_wglSetDeviceGammaRamp3DFX(HDC hdc, LPVOID ramp) {
|
||||
}
|
||||
|
||||
__declspec(dllexport) BOOL WINAPI wglUseFontBitmapsA(HDC, DWORD, DWORD, DWORD) { return FALSE; }
|
||||
__declspec(dllexport) BOOL WINAPI wglUseFontBitmapsW(HDC, DWORD, DWORD, DWORD) { return FALSE; }
|
||||
__declspec(dllexport) BOOL WINAPI wglUseFontBitmapsW(HDC, DWORD, DWORD, DWORD) { return FALSE; }
|
||||
|
||||
@@ -1705,6 +1705,10 @@ typedef struct glRaytracingLight_s
|
||||
// spot: x = near clip, y/z unused
|
||||
// rect : scalar range copy
|
||||
float pointRadiusPad; // non-zero disables specular for this light
|
||||
|
||||
uint32_t iesTextureId; // optional GL texture containing a lat-long IES profile
|
||||
float iesStrength; // 0 disables, 1 uses texture as authored
|
||||
float iesPad[2];
|
||||
} glRaytracingLight_t;
|
||||
|
||||
typedef struct glRaytracingLightingPassDesc_s
|
||||
@@ -1844,6 +1848,7 @@ ID3D12Device* QD3D12_GetDevice(void);
|
||||
ID3D12CommandQueue* QD3D12_GetQueue(void);
|
||||
ID3D12GraphicsCommandList* QD3D12_GetCommandList(void);
|
||||
ID3D12Resource* QD3D12_GetCurrentBackBuffer(void);
|
||||
ID3D12Resource* QD3D12_GetTextureResource(GLuint texture, DXGI_FORMAT* format, UINT* width, UINT* height, ID3D12GraphicsCommandList* commandList);
|
||||
|
||||
static float glRaytracingSqrtf(float x)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user