mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-29 17:52:18 +01:00
[d3d11] Experimental support for typed shader buffer views
This commit is contained in:
parent
7f5fa18d0b
commit
e668c65017
@ -1696,9 +1696,9 @@ namespace dxvk {
|
|||||||
if (resView != nullptr) {
|
if (resView != nullptr) {
|
||||||
// Figure out what we have to bind based on the resource type
|
// Figure out what we have to bind based on the resource type
|
||||||
if (resView->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
if (resView->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
||||||
Logger::warn("D3D11: Texel buffers not yet supported");
|
// TODO support raw and structured buffers
|
||||||
m_context->bindResourceTexelBuffer(
|
m_context->bindResourceTexelBuffer(
|
||||||
slotId + i, nullptr);
|
slotId + i, resView->GetDXVKBufferView());
|
||||||
} else {
|
} else {
|
||||||
m_context->bindResourceImage(
|
m_context->bindResourceImage(
|
||||||
slotId + i, resView->GetDXVKImageView());
|
slotId + i, resView->GetDXVKImageView());
|
||||||
|
@ -146,8 +146,42 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
||||||
Logger::err("D3D11: Shader resource views for buffers not yet supported");
|
auto resource = static_cast<D3D11Buffer*>(pResource);
|
||||||
return E_INVALIDARG;
|
|
||||||
|
// TODO implement raw and structured buffers
|
||||||
|
if (pDesc->Format == DXGI_FORMAT_UNKNOWN) {
|
||||||
|
Logger::err("D3D11Device: Raw and structured buffers not yet supported");
|
||||||
|
return E_INVALIDARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Typed buffer views support uncompressed color formats only
|
||||||
|
const VkFormat format = m_dxgiAdapter->LookupFormat(
|
||||||
|
pDesc->Format, DxgiFormatMode::Color).format;
|
||||||
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(format);
|
||||||
|
|
||||||
|
if (formatInfo->flags.test(DxvkFormatFlag::BlockCompressed)) {
|
||||||
|
Logger::err("D3D11Device: Compressed formats for buffer views not supported");
|
||||||
|
return E_INVALIDARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
DxvkBufferViewCreateInfo viewInfo;
|
||||||
|
viewInfo.format = format;
|
||||||
|
viewInfo.rangeOffset = formatInfo->elementSize * pDesc->Buffer.FirstElement;
|
||||||
|
viewInfo.rangeLength = formatInfo->elementSize * pDesc->Buffer.NumElements;
|
||||||
|
|
||||||
|
if (ppSRView == nullptr)
|
||||||
|
return S_FALSE;
|
||||||
|
|
||||||
|
try {
|
||||||
|
*ppSRView = ref(new D3D11ShaderResourceView(
|
||||||
|
this, pResource, desc,
|
||||||
|
m_dxvkDevice->createBufferView(
|
||||||
|
resource->GetBufferSlice().buffer(), viewInfo)));
|
||||||
|
return S_OK;
|
||||||
|
} catch (const DxvkError& e) {
|
||||||
|
Logger::err(e.message());
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Retrieve info about the image
|
// Retrieve info about the image
|
||||||
D3D11TextureInfo textureInfo;
|
D3D11TextureInfo textureInfo;
|
||||||
@ -249,7 +283,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ppSRView == nullptr)
|
if (ppSRView == nullptr)
|
||||||
return S_OK;
|
return S_FALSE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
*ppSRView = ref(new D3D11ShaderResourceView(
|
*ppSRView = ref(new D3D11ShaderResourceView(
|
||||||
@ -353,7 +387,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
// Create the actual image view if requested
|
// Create the actual image view if requested
|
||||||
if (ppRTView == nullptr)
|
if (ppRTView == nullptr)
|
||||||
return S_OK;
|
return S_FALSE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
*ppRTView = ref(new D3D11RenderTargetView(
|
*ppRTView = ref(new D3D11RenderTargetView(
|
||||||
@ -363,7 +397,7 @@ namespace dxvk {
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
} catch (const DxvkError& e) {
|
} catch (const DxvkError& e) {
|
||||||
Logger::err(e.message());
|
Logger::err(e.message());
|
||||||
return DXGI_ERROR_DRIVER_INTERNAL_ERROR;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,7 +481,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
// Create the actual image view if requested
|
// Create the actual image view if requested
|
||||||
if (ppDepthStencilView == nullptr)
|
if (ppDepthStencilView == nullptr)
|
||||||
return S_OK;
|
return S_FALSE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
*ppDepthStencilView = ref(new D3D11DepthStencilView(
|
*ppDepthStencilView = ref(new D3D11DepthStencilView(
|
||||||
@ -457,7 +491,7 @@ namespace dxvk {
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
} catch (const DxvkError& e) {
|
} catch (const DxvkError& e) {
|
||||||
Logger::err(e.message());
|
Logger::err(e.message());
|
||||||
return DXGI_ERROR_DRIVER_INTERNAL_ERROR;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,7 +605,7 @@ namespace dxvk {
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
} catch (const DxvkError& e) {
|
} catch (const DxvkError& e) {
|
||||||
Logger::err(e.message());
|
Logger::err(e.message());
|
||||||
return E_INVALIDARG;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,9 +757,10 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ppBlendState != nullptr)
|
if (ppBlendState != nullptr) {
|
||||||
*ppBlendState = m_bsStateObjects.Create(this, desc);
|
*ppBlendState = m_bsStateObjects.Create(this, desc);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
} return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -753,9 +788,10 @@ namespace dxvk {
|
|||||||
desc.BackFace = stencilOp;
|
desc.BackFace = stencilOp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ppDepthStencilState != nullptr)
|
if (ppDepthStencilState != nullptr) {
|
||||||
*ppDepthStencilState = m_dsStateObjects.Create(this, desc);
|
*ppDepthStencilState = m_dsStateObjects.Create(this, desc);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
} return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -779,9 +815,10 @@ namespace dxvk {
|
|||||||
desc.AntialiasedLineEnable = FALSE;
|
desc.AntialiasedLineEnable = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ppRasterizerState != nullptr)
|
if (ppRasterizerState != nullptr) {
|
||||||
*ppRasterizerState = m_rsStateObjects.Create(this, desc);
|
*ppRasterizerState = m_rsStateObjects.Create(this, desc);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
} return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -827,7 +864,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
// Create sampler object if the application requests it
|
// Create sampler object if the application requests it
|
||||||
if (ppSamplerState == nullptr)
|
if (ppSamplerState == nullptr)
|
||||||
return S_OK;
|
return S_FALSE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
*ppSamplerState = ref(new D3D11SamplerState(this,
|
*ppSamplerState = ref(new D3D11SamplerState(this,
|
||||||
@ -835,7 +872,7 @@ namespace dxvk {
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
} catch (const DxvkError& e) {
|
} catch (const DxvkError& e) {
|
||||||
Logger::err(e.message());
|
Logger::err(e.message());
|
||||||
return S_OK;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1147,7 +1184,7 @@ namespace dxvk {
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
} catch (const DxvkError& e) {
|
} catch (const DxvkError& e) {
|
||||||
Logger::err(e.message());
|
Logger::err(e.message());
|
||||||
return E_INVALIDARG;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,10 @@ struct Vertex {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const std::string g_vertexShaderCode =
|
const std::string g_vertexShaderCode =
|
||||||
|
"Buffer<float4> buf : register(t0);\n"
|
||||||
"struct vs_out {\n"
|
"struct vs_out {\n"
|
||||||
" float4 pos : SV_POSITION;\n"
|
" float4 pos : SV_POSITION;\n"
|
||||||
|
" float4 color : COLOR;\n"
|
||||||
" uint vid : VID;\n"
|
" uint vid : VID;\n"
|
||||||
" uint iid : IID;\n"
|
" uint iid : IID;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
@ -27,6 +29,7 @@ const std::string g_vertexShaderCode =
|
|||||||
" uint iid : SV_INSTANCEID) {\n"
|
" uint iid : SV_INSTANCEID) {\n"
|
||||||
" vs_out result;\n"
|
" vs_out result;\n"
|
||||||
" result.pos = vsIn;\n"
|
" result.pos = vsIn;\n"
|
||||||
|
" result.color = buf[vid];\n"
|
||||||
" result.vid = vid;\n"
|
" result.vid = vid;\n"
|
||||||
" result.iid = iid;\n"
|
" result.iid = iid;\n"
|
||||||
" return result;\n"
|
" return result;\n"
|
||||||
@ -35,12 +38,14 @@ const std::string g_vertexShaderCode =
|
|||||||
const std::string g_pixelShaderCode =
|
const std::string g_pixelShaderCode =
|
||||||
"struct vs_out {\n"
|
"struct vs_out {\n"
|
||||||
" float4 pos : SV_POSITION;\n"
|
" float4 pos : SV_POSITION;\n"
|
||||||
|
" float4 color : COLOR;\n"
|
||||||
" uint vid : VID;\n"
|
" uint vid : VID;\n"
|
||||||
" uint iid : IID;\n"
|
" uint iid : IID;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"cbuffer c_buffer { float4 ccolor[2]; };\n"
|
"cbuffer c_buffer { float4 ccolor[2]; };\n"
|
||||||
"float4 main(vs_out ps_in) : SV_TARGET {\n"
|
"float4 main(vs_out ps_in) : SV_TARGET {\n"
|
||||||
" return 0.5f * (ccolor[min(ps_in.vid, 1u)] + ccolor[min(ps_in.iid, 1u)]);\n"
|
" return ps_in.color;\n"
|
||||||
|
// " return 0.5f * (ccolor[min(ps_in.vid, 1u)] + ccolor[min(ps_in.iid, 1u)]);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
class TriangleApp {
|
class TriangleApp {
|
||||||
@ -157,15 +162,17 @@ public:
|
|||||||
if (FAILED(m_device->CreateBuffer(&indexDesc, &indexDataInfo, &m_indexBuffer)))
|
if (FAILED(m_device->CreateBuffer(&indexDesc, &indexDataInfo, &m_indexBuffer)))
|
||||||
throw DxvkError("Failed to create index buffer");
|
throw DxvkError("Failed to create index buffer");
|
||||||
|
|
||||||
std::array<Vertex, 2> constantData = {{
|
std::array<Vertex, 3> constantData = {{
|
||||||
{ 0.03f, 0.03f, 0.03f, 1.0f },
|
{ 0.03f, 0.03f, 0.03f, 1.0f },
|
||||||
{ 1.00f, 0.00f, 0.00f, 1.0f },
|
{ 1.00f, 0.00f, 0.00f, 1.0f },
|
||||||
|
{ 1.00f, 1.00f, 0.00f, 1.0f },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
D3D11_BUFFER_DESC constantDesc;
|
D3D11_BUFFER_DESC constantDesc;
|
||||||
constantDesc.ByteWidth = sizeof(Vertex) * constantData.size();
|
constantDesc.ByteWidth = sizeof(Vertex) * constantData.size();
|
||||||
constantDesc.Usage = D3D11_USAGE_IMMUTABLE;
|
constantDesc.Usage = D3D11_USAGE_IMMUTABLE;
|
||||||
constantDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
constantDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER
|
||||||
|
| D3D11_BIND_SHADER_RESOURCE;
|
||||||
constantDesc.CPUAccessFlags = 0;
|
constantDesc.CPUAccessFlags = 0;
|
||||||
constantDesc.MiscFlags = 0;
|
constantDesc.MiscFlags = 0;
|
||||||
constantDesc.StructureByteStride = 0;
|
constantDesc.StructureByteStride = 0;
|
||||||
@ -178,6 +185,15 @@ public:
|
|||||||
if (FAILED(m_device->CreateBuffer(&constantDesc, &constantDataInfo, &m_constantBuffer)))
|
if (FAILED(m_device->CreateBuffer(&constantDesc, &constantDataInfo, &m_constantBuffer)))
|
||||||
throw DxvkError("Failed to create constant buffer");
|
throw DxvkError("Failed to create constant buffer");
|
||||||
|
|
||||||
|
D3D11_SHADER_RESOURCE_VIEW_DESC constantViewDesc;
|
||||||
|
constantViewDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||||
|
constantViewDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
|
||||||
|
constantViewDesc.Buffer.FirstElement = 0;
|
||||||
|
constantViewDesc.Buffer.NumElements = 3;
|
||||||
|
|
||||||
|
if (FAILED(m_device->CreateShaderResourceView(m_constantBuffer.ptr(), &constantViewDesc, &m_constantView)))
|
||||||
|
throw DxvkError("Failed to create texel buffer view");
|
||||||
|
|
||||||
Com<ID3DBlob> vertexShaderBlob;
|
Com<ID3DBlob> vertexShaderBlob;
|
||||||
Com<ID3DBlob> pixelShaderBlob;
|
Com<ID3DBlob> pixelShaderBlob;
|
||||||
|
|
||||||
@ -250,6 +266,7 @@ public:
|
|||||||
m_context->ClearRenderTargetView(m_bufferView.ptr(), color);
|
m_context->ClearRenderTargetView(m_bufferView.ptr(), color);
|
||||||
|
|
||||||
m_context->VSSetShader(m_vertexShader.ptr(), nullptr, 0);
|
m_context->VSSetShader(m_vertexShader.ptr(), nullptr, 0);
|
||||||
|
m_context->VSSetShaderResources(0, 1, &m_constantView);
|
||||||
m_context->PSSetShader(m_pixelShader.ptr(), nullptr, 0);
|
m_context->PSSetShader(m_pixelShader.ptr(), nullptr, 0);
|
||||||
m_context->PSSetConstantBuffers(0, 1, &m_constantBuffer);
|
m_context->PSSetConstantBuffers(0, 1, &m_constantBuffer);
|
||||||
|
|
||||||
@ -328,6 +345,7 @@ private:
|
|||||||
Com<ID3D11Texture2D> m_buffer;
|
Com<ID3D11Texture2D> m_buffer;
|
||||||
Com<ID3D11RenderTargetView> m_bufferView;
|
Com<ID3D11RenderTargetView> m_bufferView;
|
||||||
Com<ID3D11Buffer> m_constantBuffer;
|
Com<ID3D11Buffer> m_constantBuffer;
|
||||||
|
Com<ID3D11ShaderResourceView> m_constantView;
|
||||||
Com<ID3D11Buffer> m_indexBuffer;
|
Com<ID3D11Buffer> m_indexBuffer;
|
||||||
Com<ID3D11Buffer> m_vertexBuffer;
|
Com<ID3D11Buffer> m_vertexBuffer;
|
||||||
Com<ID3D11InputLayout> m_vertexFormat;
|
Com<ID3D11InputLayout> m_vertexFormat;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user