Merge branch 'master' into vulkan

This commit is contained in:
Triang3l
2020-09-20 15:18:23 +03:00
15 changed files with 105 additions and 76 deletions

View File

@@ -486,6 +486,10 @@ void D3D12ImmediateDrawer::Begin(int render_target_width,
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
current_command_list_->RSSetViewports(1, &viewport);
current_scissor_.left = 0;
current_scissor_.top = 0;
current_scissor_.right = 0;
current_scissor_.bottom = 0;
current_command_list_->SetGraphicsRootSignature(root_signature_);
float viewport_inv_size[2];
@@ -553,6 +557,32 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
auto& provider = context_.GetD3D12Provider();
auto device = provider.GetDevice();
// Set the scissor rectangle if enabled.
D3D12_RECT scissor;
if (draw.scissor) {
scissor.left = draw.scissor_rect[0];
scissor.top = current_render_target_height_ -
(draw.scissor_rect[1] + draw.scissor_rect[3]);
scissor.right = scissor.left + draw.scissor_rect[2];
scissor.bottom = scissor.top + draw.scissor_rect[3];
} else {
scissor.left = 0;
scissor.top = 0;
scissor.right = current_render_target_width_;
scissor.bottom = current_render_target_height_;
}
if (scissor.right <= scissor.left || scissor.bottom <= scissor.top) {
// Nothing is visible (used as the default current_scissor_ value also).
return;
}
if (current_scissor_.left != scissor.left ||
current_scissor_.top != scissor.top ||
current_scissor_.right != scissor.right ||
current_scissor_.bottom != scissor.bottom) {
current_scissor_ = scissor;
current_command_list_->RSSetScissorRects(1, &scissor);
}
// Bind the texture.
auto texture = reinterpret_cast<D3D12ImmediateTexture*>(draw.texture_handle);
ID3D12Resource* texture_resource;
@@ -579,6 +609,7 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
current_command_list_->SetDescriptorHeaps(2, descriptor_heaps);
}
if (bind_texture) {
current_texture_ = texture;
D3D12_SHADER_RESOURCE_VIEW_DESC texture_view_desc;
texture_view_desc.Format = D3D12ImmediateTexture::kFormat;
texture_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
@@ -598,7 +629,6 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
provider.OffsetViewDescriptor(
texture_descriptor_pool_->GetLastRequestHeapGPUStart(),
texture_descriptor_index));
current_texture_ = texture;
}
// Bind the sampler.
@@ -615,11 +645,11 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
sampler_index = SamplerIndex::kNearestClamp;
}
if (current_sampler_index_ != sampler_index) {
current_sampler_index_ = sampler_index;
current_command_list_->SetGraphicsRootDescriptorTable(
UINT(RootParameter::kSampler),
provider.OffsetSamplerDescriptor(sampler_heap_gpu_start_,
uint32_t(sampler_index)));
current_sampler_index_ = sampler_index;
}
// Set whether texture coordinates need to be restricted.
@@ -645,27 +675,11 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
return;
}
if (current_primitive_topology_ != primitive_topology) {
current_primitive_topology_ = primitive_topology;
current_command_list_->IASetPrimitiveTopology(primitive_topology);
current_command_list_->SetPipelineState(pipeline);
current_primitive_topology_ = primitive_topology;
}
// Set the scissor rectangle if enabled.
D3D12_RECT scissor;
if (draw.scissor) {
scissor.left = draw.scissor_rect[0];
scissor.top = current_render_target_height_ -
(draw.scissor_rect[1] + draw.scissor_rect[3]);
scissor.right = scissor.left + draw.scissor_rect[2];
scissor.bottom = scissor.top + draw.scissor_rect[3];
} else {
scissor.left = 0;
scissor.top = 0;
scissor.right = current_render_target_width_;
scissor.bottom = current_render_target_height_;
}
current_command_list_->RSSetScissorRects(1, &scissor);
// Draw.
if (batch_has_index_buffer_) {
current_command_list_->DrawIndexedInstanced(

View File

@@ -95,6 +95,7 @@ class D3D12ImmediateDrawer : public ImmediateDrawer {
int current_render_target_width_, current_render_target_height_;
bool batch_open_ = false;
bool batch_has_index_buffer_;
D3D12_RECT current_scissor_;
D3D_PRIMITIVE_TOPOLOGY current_primitive_topology_;
ImmediateTexture* current_texture_;
SamplerIndex current_sampler_index_;

View File

@@ -1,8 +1,8 @@
// generated from `xb buildhlsl`
// source: immediate.vs.hlsl
const uint8_t immediate_vs[] = {
0x44, 0x58, 0x42, 0x43, 0x6A, 0xC1, 0xC3, 0xE8, 0xA7, 0x09, 0x30, 0xF3,
0x48, 0x84, 0xA3, 0x3C, 0x7D, 0x90, 0xA1, 0x09, 0x01, 0x00, 0x00, 0x00,
0x44, 0x58, 0x42, 0x43, 0xC3, 0x3E, 0x79, 0xCB, 0x09, 0x65, 0x04, 0xF0,
0x71, 0x43, 0x47, 0x45, 0xAC, 0xE1, 0xA9, 0x03, 0x01, 0x00, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x54, 0x01, 0x00, 0x00, 0xC4, 0x01, 0x00, 0x00, 0x34, 0x02, 0x00, 0x00,
0x64, 0x03, 0x00, 0x00, 0x52, 0x44, 0x45, 0x46, 0x18, 0x01, 0x00, 0x00,
@@ -21,8 +21,8 @@ const uint8_t immediate_vs[] = {
0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xCC, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x78, 0x65, 0x5F, 0x76,
0x69, 0x65, 0x77, 0x70, 0x6F, 0x72, 0x74, 0x5F, 0x69, 0x6E, 0x76, 0x5F,
0x73, 0x69, 0x7A, 0x65, 0x00, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x32, 0x00,
0x69, 0x65, 0x77, 0x70, 0x6F, 0x72, 0x74, 0x5F, 0x73, 0x69, 0x7A, 0x65,
0x5F, 0x69, 0x6E, 0x76, 0x00, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x32, 0x00,
0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x00, 0x00,

View File

@@ -7,7 +7,7 @@
// cbuffer $Globals
// {
//
// float2 xe_viewport_inv_size; // Offset: 0 Size: 8
// float2 xe_viewport_size_inv; // Offset: 0 Size: 8
//
// }
//

View File

@@ -14,10 +14,10 @@ struct XeVertexShaderOutput {
XeVertexShaderOutput main(XeVertexShaderInput input) {
XeVertexShaderOutput output;
output.texcoord = input.texcoord;
output.color = input.color;
output.position = float4(
input.position * xe_viewport_size_inv * float2(2.0, -2.0) +
float2(-1.0, 1.0), 0.0, 1.0);
output.texcoord = input.texcoord;
output.color = input.color;
return output;
}