//------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------- AOFX_RETURN_CODE AMD_AOFX_DLL_API AOFX_Release(const AOFX_Desc & desc) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME " \n"); desc.m_pOpaque->release(); return AOFX_RETURN_CODE_SUCCESS; }
HRESULT CreateFullscreenPass(ID3D11PixelShader** ppPS, ID3D11Device* pDevice) { if ( pDevice == NULL || ppPS == NULL ) { AMD_OUTPUT_DEBUG_STRING("Invalid Device or Vertex Shader pointers in function %s\n", AMD_FUNCTION_NAME); return E_INVALIDARG; } return pDevice->CreatePixelShader(PS_FULLSCREEN_Data, sizeof(PS_FULLSCREEN_Data), NULL, ppPS); }
HRESULT CreateFullscreenPass(ID3D11VertexShader** ppVS, ID3D11Device* pDevice) { if ( pDevice == NULL || ppVS == NULL ) { AMD_OUTPUT_DEBUG_STRING("Invalid Device or Vertex Shader pointers in function %s\n", AMD_FUNCTION_NAME); return E_POINTER; } return pDevice->CreateVertexShader(VS_FULLSCREEN_Data, sizeof(VS_FULLSCREEN_Data), NULL, ppVS); }
HRESULT RenderFullscreenAlignedQuads( ID3D11DeviceContext* pDeviceContext, D3D11_VIEWPORT Viewport, ID3D11VertexShader* pVS, ID3D11PixelShader* pPS, D3D11_RECT* pScissor, unsigned int uNumSR, ID3D11Buffer** ppCB, unsigned int uNumCBs, ID3D11SamplerState** ppSamplers, unsigned int uNumSamplers, ID3D11ShaderResourceView** ppSRVs, unsigned int uNumSRVs, ID3D11RenderTargetView** ppRTVs, unsigned int uNumRTVs, ID3D11DepthStencilView* pDSV, ID3D11DepthStencilState* pOutputDSS, unsigned int uStencilRef, ID3D11BlendState * pOutputBS, ID3D11RasterizerState * pOutputRS, int nCount) { float white[] = {1,1,1,1}; ID3D11ShaderResourceView* pNullSRV[8] = { NULL }; ID3D11RenderTargetView* pNullRTV[8] = { NULL }; ID3D11Buffer* pNullBuffer[8] = { NULL }; UINT NullStride[8] = { 0 }; UINT NullOffset[8] = { 0 } ; if ((pDeviceContext == NULL || pVS == NULL || pPS == NULL || (ppRTVs == NULL && pDSV == NULL))) { AMD_OUTPUT_DEBUG_STRING("Invalid pointer argument in function %s\n", AMD_FUNCTION_NAME); return E_POINTER; } pDeviceContext->OMSetDepthStencilState( pOutputDSS, uStencilRef ); pDeviceContext->OMSetRenderTargets( uNumRTVs, (ID3D11RenderTargetView*const*)ppRTVs, pDSV ); pDeviceContext->OMSetBlendState(pOutputBS, white, 0xFFFFFFFF); pDeviceContext->RSSetViewports( 1, &Viewport ); pDeviceContext->RSSetScissorRects(uNumSR, pScissor); pDeviceContext->RSSetState( pOutputRS ); pDeviceContext->PSSetConstantBuffers( 0, uNumCBs, ppCB); pDeviceContext->PSSetShaderResources( 0, uNumSRVs, ppSRVs ); pDeviceContext->PSSetSamplers( 0, uNumSamplers, ppSamplers ); pDeviceContext->IASetInputLayout( NULL ); pDeviceContext->IASetVertexBuffers( 0, AMD_ARRAY_SIZE(pNullBuffer), pNullBuffer, NullStride, NullOffset ); pDeviceContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); pDeviceContext->VSSetShader( pVS, NULL, 0 ); pDeviceContext->PSSetShader(pPS, NULL, 0); pDeviceContext->Draw( 6 * nCount, 0 ); // Unbind RTVs and SRVs back to NULL (otherwise D3D will throw warnings) pDeviceContext->OMSetRenderTargets( AMD_ARRAY_SIZE(pNullRTV), pNullRTV, NULL ); pDeviceContext->PSSetShaderResources( 0, AMD_ARRAY_SIZE(pNullSRV), pNullSRV ); return S_OK; }
//------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------- AOFX_RETURN_CODE AMD_AOFX_DLL_API AOFX_Resize(const AOFX_Desc & desc) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME "\n"); if (NULL == desc.m_pDevice) { return AOFX_RETURN_CODE_INVALID_DEVICE; } if (NULL == desc.m_pDeviceContext) { return AOFX_RETURN_CODE_INVALID_DEVICE_CONTEXT; } AOFX_RETURN_CODE result = desc.m_pOpaque->resize(desc); return result; }
//------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------- AOFX_RETURN_CODE AMD_AOFX_DLL_API AOFX_Initialize(const AOFX_Desc & desc) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME "\n"); AOFX_RETURN_CODE result = AOFX_RETURN_CODE_SUCCESS; if (NULL == desc.m_pDevice) { return AOFX_RETURN_CODE_INVALID_DEVICE; } result = desc.m_pOpaque->cbInitialize(desc); if (result != AOFX_RETURN_CODE_SUCCESS) return result; result = desc.m_pOpaque->createShaders(desc); return result; }
//------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------- AOFX_RETURN_CODE AMD_AOFX_DLL_API AOFX_Render(const AOFX_Desc & desc) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME "\n"); if (NULL == desc.m_pDeviceContext) { return AOFX_RETURN_CODE_INVALID_DEVICE_CONTEXT; } AMD::C_SaveRestore_IA save_ia(desc.m_pDeviceContext); AMD::C_SaveRestore_VS save_vs(desc.m_pDeviceContext); AMD::C_SaveRestore_HS save_hs(desc.m_pDeviceContext); AMD::C_SaveRestore_DS save_ds(desc.m_pDeviceContext); AMD::C_SaveRestore_GS save_gs(desc.m_pDeviceContext); AMD::C_SaveRestore_PS save_ps(desc.m_pDeviceContext); AMD::C_SaveRestore_RS save_rs(desc.m_pDeviceContext); AMD::C_SaveRestore_OM save_om(desc.m_pDeviceContext); AMD::C_SaveRestore_CS save_cs(desc.m_pDeviceContext); AOFX_RETURN_CODE result = desc.m_pOpaque->render(desc); return result; }
//------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------- AOFX_Desc::AOFX_Desc() : m_Implementation(AOFX_IMPLEMENTATION_MASK_KERNEL_CS | AOFX_IMPLEMENTATION_MASK_BLUR_CS | AOFX_IMPLEMENTATION_MASK_UTILITY_CS) , m_pDeviceContext(NULL) , m_pNormalSRV(NULL) , m_pDepthSRV(NULL) , m_pDevice(NULL) , m_pOutputRTV(NULL) , m_pOpaque(NULL) , m_OutputChannelsFlag(0xF) , m_pOutputBS(NULL) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME "\n"); static AOFX_OpaqueDesc opaque(*this); for (AMD::uint i = 0; i < m_MultiResLayerCount; i++) { m_LayerProcess[i] = AOFX_LAYER_PROCESS_DEINTERLEAVE_NONE; m_MultiResLayerScale[i] = 1.0f / powf(2.0f, (float)i); m_PowIntensity[i] = 1.0f; m_BilateralBlurRadius[i] = AOFX_BILATERAL_BLUR_RADIUS_NONE; m_ViewDistanceDiscard[i] = 100.0f; m_ViewDistanceFade[i] = 99.0f; m_NormalScale[i] = 0.1f; m_LinearIntensity[i] = 0.6f; m_AcceptRadius[i] = 0.003f; m_RejectRadius[i] = 0.8f; m_RecipFadeOutDist[i] = 6.0f; m_DepthUpsampleThreshold[i] = 0.05f; m_SampleCount[i] = AOFX_SAMPLE_COUNT_LOW; m_NormalOption[i] = AOFX_NORMAL_OPTION_NONE; m_TapType[i] = AOFX_TAP_TYPE_FIXED; } m_pOpaque = &opaque; }
AMD_AOFX_DLL_API AOFX_RETURN_CODE AOFX_DebugSerialize(AOFX_Desc& desc, const char* params) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME " \n"); HRESULT hr = S_OK; ID3D11Texture2D *pDepthT2D = NULL, *pNormalT2D = NULL; std::string strParams(params); std::wstring wstrParams(strParams.begin(), strParams.end()); if (desc.m_pDepthSRV) { std::wstring depth = wstrParams + L".depth.dds"; desc.m_pDepthSRV->GetResource((ID3D11Resource**)&pDepthT2D); hr = DirectX::SaveDDSTextureToFile(desc.m_pDeviceContext, pDepthT2D, depth.c_str()); AMD_SAFE_RELEASE(pDepthT2D); if (hr != S_OK) { AMD_OUTPUT_DEBUG_STRING("AMD_AO DebugSerialize Error : Can't save Depth Texture\n"); return AOFX_RETURN_CODE_FAIL; } } if (desc.m_pNormalSRV) { std::wstring normal = wstrParams + L".normal.dds"; desc.m_pNormalSRV->GetResource((ID3D11Resource**)&pNormalT2D); hr = DirectX::SaveDDSTextureToFile(desc.m_pDeviceContext, pNormalT2D, normal.c_str()); AMD_SAFE_RELEASE(pNormalT2D); if (hr != S_OK) { AMD_OUTPUT_DEBUG_STRING("AMD_AO DebugSerialize Error : Can't save Normal Texture\n"); return AOFX_RETURN_CODE_FAIL; } } strParams += ".txt"; FILE * file = fopen(strParams.c_str(), "wt"); if (file != NULL) { serialize_uint(file, "desc.m_MultiResLayerCount", (uint *)&desc.m_MultiResLayerCount); for (uint i = 0; i < desc.m_MultiResLayerCount; i++) { serialize_uint(file, "desc.m_LayerProcess", (uint *)&desc.m_LayerProcess[i]); serialize_uint(file, "desc.m_BilateralBlurRadius", (uint *)&desc.m_BilateralBlurRadius[i]); serialize_uint(file, "desc.m_SampleCount", (uint *)&desc.m_SampleCount[i]); serialize_uint(file, "desc.m_NormalOption", (uint *)&desc.m_NormalOption[i]); serialize_uint(file, "desc.m_TapType", (uint *)&desc.m_TapType[i]); serialize_float(file, "desc.m_MultiResLayerScale", (float *)&desc.m_MultiResLayerScale[i]); serialize_float(file, "desc.m_PowIntensity", (float *)&desc.m_PowIntensity[i]); serialize_float(file, "desc.m_RejectRadius", (float *)&desc.m_RejectRadius[i]); serialize_float(file, "desc.m_AcceptRadius", (float *)&desc.m_AcceptRadius[i]); serialize_float(file, "desc.m_RecipFadeOutDist", (float *)&desc.m_RecipFadeOutDist[i]); serialize_float(file, "desc.m_LinearIntensity", (float *)&desc.m_LinearIntensity[i]); serialize_float(file, "desc.m_NormalScale", (float *)&desc.m_NormalScale[i]); serialize_float(file, "desc.m_ViewDistanceDiscard", (float *)&desc.m_ViewDistanceDiscard[i]); serialize_float(file, "desc.m_ViewDistanceFade", (float *)&desc.m_ViewDistanceFade[i]); serialize_float(file, "desc.m_DepthUpsampleThreshold", (float *)&desc.m_DepthUpsampleThreshold[i]); } serialize_uint(file, "desc.m_Implementation", (uint *)&desc.m_Implementation); serialize_float4(file, "desc.m_Camera.m_View.r[0]", (float *)&desc.m_Camera.m_View.r[0]); serialize_float4(file, "desc.m_Camera.m_View.r[1]", (float *)&desc.m_Camera.m_View.r[1]); serialize_float4(file, "desc.m_Camera.m_View.r[2]", (float *)&desc.m_Camera.m_View.r[2]); serialize_float4(file, "desc.m_Camera.m_View.r[3]", (float *)&desc.m_Camera.m_View.r[3]); serialize_float4(file, "desc.m_Camera.m_Projection.r[0]", (float *)&desc.m_Camera.m_Projection.r[0]); serialize_float4(file, "desc.m_Camera.m_Projection.r[1]", (float *)&desc.m_Camera.m_Projection.r[1]); serialize_float4(file, "desc.m_Camera.m_Projection.r[2]", (float *)&desc.m_Camera.m_Projection.r[2]); serialize_float4(file, "desc.m_Camera.m_Projection.r[3]", (float *)&desc.m_Camera.m_Projection.r[3]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[0]", (float *)&desc.m_Camera.m_ViewProjection.r[0]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[1]", (float *)&desc.m_Camera.m_ViewProjection.r[1]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[2]", (float *)&desc.m_Camera.m_ViewProjection.r[2]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[3]", (float *)&desc.m_Camera.m_ViewProjection.r[3]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[0]", (float *)&desc.m_Camera.m_View_Inv.r[0]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[1]", (float *)&desc.m_Camera.m_View_Inv.r[1]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[2]", (float *)&desc.m_Camera.m_View_Inv.r[2]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[3]", (float *)&desc.m_Camera.m_View_Inv.r[3]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[0]", (float *)&desc.m_Camera.m_Projection_Inv.r[0]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[1]", (float *)&desc.m_Camera.m_Projection_Inv.r[1]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[2]", (float *)&desc.m_Camera.m_Projection_Inv.r[2]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[3]", (float *)&desc.m_Camera.m_Projection_Inv.r[3]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[0]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[0]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[1]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[1]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[2]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[2]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[3]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[3]); serialize_float3(file, "desc.m_Camera.m_Position", (float *)&desc.m_Camera.m_Position); serialize_float3(file, "desc.m_Camera.m_Direction", (float *)&desc.m_Camera.m_Direction); serialize_float3(file, "desc.m_Camera.m_Right", (float *)&desc.m_Camera.m_Right); serialize_float3(file, "desc.m_Camera.m_Up", (float *)&desc.m_Camera.m_Up); serialize_float(file, "desc.m_Camera.m_Aspect", (float *)&desc.m_Camera.m_Aspect); serialize_float(file, "desc.m_Camera.m_FarPlane", (float *)&desc.m_Camera.m_FarPlane); serialize_float(file, "desc.m_Camera.m_NearPlane", (float *)&desc.m_Camera.m_NearPlane); serialize_float(file, "desc.m_Camera.m_Fov", (float *)&desc.m_Camera.m_Fov); serialize_float4(file, "desc.m_Camera.m_Color", (float *)&desc.m_Camera.m_Color); serialize_uint2(file, "desc.m_InputSize", (uint*)&desc.m_InputSize); serialize_uint(file, "desc.m_OutputChannelsFlag", (uint *)&desc.m_OutputChannelsFlag); fclose(file); } else { AMD_OUTPUT_DEBUG_STRING("AMD_AO DebugSerialize Error : Can't save AO Parameters\n"); } return AOFX_RETURN_CODE_SUCCESS; }
AMD_AOFX_DLL_API AOFX_RETURN_CODE AOFX_DebugDeserialize(AOFX_Desc& desc, const char* params, ID3D11Texture2D** ppT2D[], ID3D11ShaderResourceView** ppSRV[]) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME " \n"); HRESULT hr = S_OK; std::string strParams(params); std::wstring wstrParams(strParams.begin(), strParams.end()); if (ppT2D != NULL && ppSRV != NULL && ppT2D[0] != NULL && ppSRV[0] != NULL) { std::wstring depth = wstrParams + L".depth.dds"; hr = DirectX::CreateDDSTextureFromFile(desc.m_pDevice, depth.c_str(), (ID3D11Resource**)ppT2D[0], ppSRV[0]); desc.m_pDepthSRV = *ppSRV[0]; } if (ppT2D != NULL && ppSRV != NULL && ppT2D[1] != NULL && ppSRV[1] != NULL) { std::wstring normal = wstrParams + L".normal.dds"; hr = DirectX::CreateDDSTextureFromFile(desc.m_pDevice, normal.c_str(), (ID3D11Resource**)ppT2D[1], ppSRV[1]); desc.m_pNormalSRV = *ppSRV[1]; } strParams += ".txt"; FILE * file = fopen(strParams.c_str(), "rt"); if (file != NULL) { char readStr[1024]; uint multiResLayerCount = 0; deserialize_uint(file, readStr, (uint *)&multiResLayerCount); assert(multiResLayerCount == desc.m_MultiResLayerCount); for (uint i = 0; i < desc.m_MultiResLayerCount; i++) { deserialize_uint(file, readStr, (uint *)&desc.m_LayerProcess[i]); deserialize_uint(file, readStr, (uint *)&desc.m_BilateralBlurRadius[i]); deserialize_uint(file, readStr, (uint *)&desc.m_SampleCount[i]); deserialize_uint(file, readStr, (uint *)&desc.m_NormalOption[i]); deserialize_uint(file, readStr, (uint *)&desc.m_TapType[i]); deserialize_float(file, readStr, (float *)&desc.m_MultiResLayerScale[i]); deserialize_float(file, readStr, (float *)&desc.m_PowIntensity[i]); deserialize_float(file, readStr, (float *)&desc.m_RejectRadius[i]); deserialize_float(file, readStr, (float *)&desc.m_AcceptRadius[i]); deserialize_float(file, readStr, (float *)&desc.m_RecipFadeOutDist[i]); deserialize_float(file, readStr, (float *)&desc.m_LinearIntensity[i]); deserialize_float(file, readStr, (float *)&desc.m_NormalScale[i]); deserialize_float(file, readStr, (float *)&desc.m_ViewDistanceDiscard[i]); deserialize_float(file, readStr, (float *)&desc.m_ViewDistanceFade[i]); deserialize_float(file, readStr, (float *)&desc.m_DepthUpsampleThreshold[i]); } deserialize_uint(file, readStr, (uint *)&desc.m_Implementation); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[3]); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Position); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Direction); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Right); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Up); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_Aspect); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_FarPlane); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_NearPlane); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_Fov); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Color); deserialize_uint2(file, readStr, (uint*)&desc.m_InputSize); deserialize_uint(file, readStr, (uint *)&desc.m_OutputChannelsFlag); fclose(file); } return AOFX_RETURN_CODE_SUCCESS; }